aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnderson Toshiyuki Sasaki <ansasaki@redhat.com>2018-11-19 13:45:36 +0100
committerAndreas Schneider <asn@cryptomilk.org>2018-11-28 15:51:06 +0100
commit77be4ce9056e86f13b06fe15f410d663f5e7b771 (patch)
treeeb81c0ba2800e0d10d6ad234e608e588bbd57b43
parent78b1f0ead38f8086ebc5210823f470bfcaff742f (diff)
downloadlibssh-77be4ce9056e86f13b06fe15f410d663f5e7b771.tar.gz
libssh-77be4ce9056e86f13b06fe15f410d663f5e7b771.tar.xz
libssh-77be4ce9056e86f13b06fe15f410d663f5e7b771.zip
tests: use torture_create_temp_file() in torture_knownhosts_parsing
Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--tests/torture.c1
-rw-r--r--tests/unittests/torture_knownhosts_parsing.c33
-rw-r--r--tests/unittests/torture_temp_file.c2
3 files changed, 15 insertions, 21 deletions
diff --git a/tests/torture.c b/tests/torture.c
index fbf2463f..f7ed775e 100644
--- a/tests/torture.c
+++ b/tests/torture.c
@@ -1058,6 +1058,7 @@ char *torture_create_temp_file(const char *template)
goto free_prefix;
}
+ /* Remark: this function creates the file */
rc = GetTempFileNameA(tmp_dir_path, TEXT(prefix), 0, tmp_file_name);
if (rc == 0) {
goto free_prefix;
diff --git a/tests/unittests/torture_knownhosts_parsing.c b/tests/unittests/torture_knownhosts_parsing.c
index cb3cea8c..fa8eb048 100644
--- a/tests/unittests/torture_knownhosts_parsing.c
+++ b/tests/unittests/torture_knownhosts_parsing.c
@@ -31,37 +31,29 @@ static int setup_knownhosts_file(void **state)
char *tmp_file = NULL;
size_t nwritten;
FILE *fp = NULL;
- mode_t mask;
- int fd;
+ int rc = 0;
- tmp_file = strdup(TMP_FILE_NAME);
+ tmp_file = torture_create_temp_file(TMP_FILE_NAME);
assert_non_null(tmp_file);
+
*state = tmp_file;
- mask = umask(S_IRWXO | S_IRWXG);
- fd = mkstemp(tmp_file);
- umask(mask);
- assert_return_code(fd, errno);
-
- fp = fdopen(fd, "w");
- if (fp == NULL) {
- close(fd);
- return -1;
- }
+ fp = fopen(tmp_file, "w");
+ assert_non_null(fp);
nwritten = fwrite(LOCALHOST_PATTERN_ED25519,
sizeof(char),
strlen(LOCALHOST_PATTERN_ED25519),
fp);
if (nwritten != strlen(LOCALHOST_PATTERN_ED25519)) {
- fclose(fp);
- return -1;
+ rc = -1;
+ goto close_fp;
}
nwritten = fwrite("\n", sizeof(char), 1, fp);
if (nwritten != 1) {
- fclose(fp);
- return -1;
+ rc = -1;
+ goto close_fp;
}
nwritten = fwrite(LOCALHOST_RSA_LINE,
@@ -69,13 +61,14 @@ static int setup_knownhosts_file(void **state)
strlen(LOCALHOST_RSA_LINE),
fp);
if (nwritten != strlen(LOCALHOST_RSA_LINE)) {
- fclose(fp);
- return -1;
+ rc = -1;
+ goto close_fp;
}
+close_fp:
fclose(fp);
- return 0;
+ return rc;
}
static int teardown_knownhosts_file(void **state)
diff --git a/tests/unittests/torture_temp_file.c b/tests/unittests/torture_temp_file.c
index 8f97bc9d..793d6c12 100644
--- a/tests/unittests/torture_temp_file.c
+++ b/tests/unittests/torture_temp_file.c
@@ -3,7 +3,7 @@
#include "torture.h"
#define LIBSSH_STATIC
-const char template[] = "/tmp/temp_file_XXXXXX";
+const char template[] = "temp_file_XXXXXX";
static int setup(void **state)
{