From 8410f43d8b7be357177fc58481446476d2748e9c Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 4 Sep 2018 22:13:52 +0200 Subject: [PATCH] tests: Add a test for ssh_pki_export_privkey_base64() Signed-off-by: Andreas Schneider --- tests/unittests/torture_pki_ed25519.c | 56 ++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/tests/unittests/torture_pki_ed25519.c b/tests/unittests/torture_pki_ed25519.c index 9f696c20..39012168 100644 --- a/tests/unittests/torture_pki_ed25519.c +++ b/tests/unittests/torture_pki_ed25519.c @@ -110,6 +110,56 @@ static void torture_pki_ed25519_import_privkey_base64(void **state) } +static void torture_pki_ed25519_import_export_privkey_base64(void **state) +{ + char *b64_key = NULL; + ssh_key key = NULL; + const char *passphrase = torture_get_testkey_passphrase(); + enum ssh_keytypes_e type; + int rc; + + (void) state; /* unused */ + + rc = ssh_pki_import_privkey_base64(torture_get_openssh_testkey(SSH_KEYTYPE_ED25519, + 0, + false), + passphrase, + NULL, + NULL, + &key); + assert_return_code(rc, errno); + + type = ssh_key_type(key); + assert_true(type == SSH_KEYTYPE_ED25519); + + rc = ssh_key_is_private(key); + assert_true(rc == 1); + + rc = ssh_pki_export_privkey_base64(key, + passphrase, + NULL, + NULL, + &b64_key); + assert_return_code(rc, errno); + ssh_key_free(key); + + rc = ssh_pki_import_privkey_base64(b64_key, + passphrase, + NULL, + NULL, + &key); + assert_return_code(rc, errno); + + type = ssh_key_type(key); + assert_true(type == SSH_KEYTYPE_ED25519); + + rc = ssh_key_is_private(key); + assert_true(rc == 1); + + SSH_STRING_FREE_CHAR(b64_key); + ssh_key_free(key); +} + static void torture_pki_ed25519_publickey_from_privatekey(void **state) { int rc; @@ -565,7 +615,7 @@ static void torture_pki_ed25519_pubkey_dup(void **state) int torture_run_tests(void) { int rc; - const struct CMUnitTest tests[] = { + struct CMUnitTest tests[] = { cmocka_unit_test_setup_teardown(torture_pki_ed25519_import_pubkey_file, setup_ed25519_key, teardown), @@ -575,6 +625,9 @@ int torture_run_tests(void) { cmocka_unit_test_setup_teardown(torture_pki_ed25519_import_privkey_base64, setup_ed25519_key, teardown), + cmocka_unit_test_setup_teardown(torture_pki_ed25519_import_export_privkey_base64, + setup_ed25519_key, + teardown), cmocka_unit_test_setup_teardown(torture_pki_ed25519_publickey_from_privatekey, setup_ed25519_key, teardown), @@ -597,6 +650,7 @@ int torture_run_tests(void) { }; ssh_init(); + torture_filter_tests(tests); rc = cmocka_run_group_tests(tests, NULL, NULL); ssh_finalize(); return rc;