mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-08-05 20:55:46 +03:00
tests: Use temporary directories in torture_threads_pki_rsa.c
Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
committed by
Andreas Schneider
parent
f38c6fcc6e
commit
ac1377148f
@@ -38,8 +38,14 @@
|
|||||||
|
|
||||||
#define NUM_THREADS 10
|
#define NUM_THREADS 10
|
||||||
|
|
||||||
|
const char template[] = "temp_dir_XXXXXX";
|
||||||
const unsigned char RSA_HASH[] = "12345678901234567890";
|
const unsigned char RSA_HASH[] = "12345678901234567890";
|
||||||
|
|
||||||
|
struct pki_st {
|
||||||
|
char *cwd;
|
||||||
|
char *temp_dir;
|
||||||
|
};
|
||||||
|
|
||||||
static int run_on_threads(void *(*func)(void *))
|
static int run_on_threads(void *(*func)(void *))
|
||||||
{
|
{
|
||||||
pthread_t threads[NUM_THREADS];
|
pthread_t threads[NUM_THREADS];
|
||||||
@@ -67,12 +73,29 @@ static int run_on_threads(void *(*func)(void *))
|
|||||||
|
|
||||||
static int setup_rsa_key(void **state)
|
static int setup_rsa_key(void **state)
|
||||||
{
|
{
|
||||||
(void) state; /* unused */
|
struct pki_st *test_state = NULL;
|
||||||
|
char *cwd = NULL;
|
||||||
|
char *tmp_dir = NULL;
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
unlink(LIBSSH_RSA_TESTKEY);
|
test_state = (struct pki_st *)malloc(sizeof(struct pki_st));
|
||||||
unlink(LIBSSH_RSA_TESTKEY_PASSPHRASE);
|
assert_non_null(test_state);
|
||||||
unlink(LIBSSH_RSA_TESTKEY ".pub");
|
|
||||||
unlink(LIBSSH_RSA_TESTKEY "-cert.pub");
|
cwd = torture_get_current_working_dir();
|
||||||
|
assert_non_null(cwd);
|
||||||
|
|
||||||
|
tmp_dir = torture_make_temp_dir(template);
|
||||||
|
assert_non_null(tmp_dir);
|
||||||
|
|
||||||
|
test_state->cwd = cwd;
|
||||||
|
test_state->temp_dir = tmp_dir;
|
||||||
|
|
||||||
|
*state = test_state;
|
||||||
|
|
||||||
|
rc = torture_change_dir(tmp_dir);
|
||||||
|
assert_int_equal(rc, 0);
|
||||||
|
|
||||||
|
printf("Changed directory to: %s\n", tmp_dir);
|
||||||
|
|
||||||
torture_write_file(LIBSSH_RSA_TESTKEY,
|
torture_write_file(LIBSSH_RSA_TESTKEY,
|
||||||
torture_get_testkey(SSH_KEYTYPE_RSA, 0, 0));
|
torture_get_testkey(SSH_KEYTYPE_RSA, 0, 0));
|
||||||
@@ -80,22 +103,32 @@ static int setup_rsa_key(void **state)
|
|||||||
torture_get_testkey(SSH_KEYTYPE_RSA, 0, 1));
|
torture_get_testkey(SSH_KEYTYPE_RSA, 0, 1));
|
||||||
torture_write_file(LIBSSH_RSA_TESTKEY ".pub",
|
torture_write_file(LIBSSH_RSA_TESTKEY ".pub",
|
||||||
torture_get_testkey_pub(SSH_KEYTYPE_RSA, 0));
|
torture_get_testkey_pub(SSH_KEYTYPE_RSA, 0));
|
||||||
torture_write_file(LIBSSH_RSA_TESTKEY ".pub",
|
|
||||||
torture_get_testkey_pub(SSH_KEYTYPE_RSA, 0));
|
|
||||||
torture_write_file(LIBSSH_RSA_TESTKEY "-cert.pub",
|
torture_write_file(LIBSSH_RSA_TESTKEY "-cert.pub",
|
||||||
torture_get_testkey_pub(SSH_KEYTYPE_RSA_CERT01, 0));
|
torture_get_testkey_pub(SSH_KEYTYPE_RSA_CERT01, 0));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int teardown(void **state)
|
static int teardown(void **state) {
|
||||||
{
|
|
||||||
(void) state; /* unused */
|
|
||||||
|
|
||||||
unlink(LIBSSH_RSA_TESTKEY);
|
struct pki_st *test_state = NULL;
|
||||||
unlink(LIBSSH_RSA_TESTKEY_PASSPHRASE);
|
int rc = 0;
|
||||||
unlink(LIBSSH_RSA_TESTKEY ".pub");
|
|
||||||
unlink(LIBSSH_RSA_TESTKEY "-cert.pub");
|
test_state = *((struct pki_st **)state);
|
||||||
|
|
||||||
|
assert_non_null(test_state);
|
||||||
|
assert_non_null(test_state->cwd);
|
||||||
|
assert_non_null(test_state->temp_dir);
|
||||||
|
|
||||||
|
rc = torture_change_dir(test_state->cwd);
|
||||||
|
assert_int_equal(rc, 0);
|
||||||
|
|
||||||
|
rc = torture_rmdirs(test_state->temp_dir);
|
||||||
|
assert_int_equal(rc, 0);
|
||||||
|
|
||||||
|
SAFE_FREE(test_state->temp_dir);
|
||||||
|
SAFE_FREE(test_state->cwd);
|
||||||
|
SAFE_FREE(test_state);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user