mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-10 18:28:10 +09:00
tests: Add NULL checks in pki tests
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
27caaa000b
commit
9c5a1967c3
@@ -207,6 +207,7 @@ static void torture_pki_ecdsa_import_privkey_base64(void **state)
|
||||
|
||||
rc = ssh_pki_import_privkey_base64(key_str, passphrase, NULL, NULL, &key);
|
||||
assert_true(rc == 0);
|
||||
assert_non_null(key);
|
||||
|
||||
rc = ssh_key_is_private(key);
|
||||
assert_true(rc == 1);
|
||||
@@ -230,9 +231,11 @@ static void torture_pki_ecdsa_publickey_from_privatekey(void **state)
|
||||
|
||||
rc = ssh_pki_import_privkey_base64(key_str, passphrase, NULL, NULL, &key);
|
||||
assert_true(rc == 0);
|
||||
assert_non_null(key);
|
||||
|
||||
rc = ssh_pki_export_privkey_to_pubkey(key, &pubkey);
|
||||
assert_true(rc == SSH_OK);
|
||||
assert_non_null(pubkey);
|
||||
|
||||
free(key_str);
|
||||
SSH_KEY_FREE(key);
|
||||
@@ -269,9 +272,11 @@ static void torture_pki_ecdsa_publickey_base64(void **state)
|
||||
|
||||
rc = ssh_pki_import_pubkey_base64(q, type, &key);
|
||||
assert_true(rc == 0);
|
||||
assert_non_null(key);
|
||||
|
||||
rc = ssh_pki_export_pubkey_base64(key, &b64_key);
|
||||
assert_true(rc == 0);
|
||||
assert_non_null(b64_key);
|
||||
|
||||
assert_string_equal(q, b64_key);
|
||||
|
||||
@@ -305,9 +310,11 @@ static void torture_pki_ecdsa_generate_pubkey_from_privkey(void **state)
|
||||
NULL,
|
||||
&privkey);
|
||||
assert_true(rc == 0);
|
||||
assert_non_null(privkey);
|
||||
|
||||
rc = ssh_pki_export_privkey_to_pubkey(privkey, &pubkey);
|
||||
assert_true(rc == SSH_OK);
|
||||
assert_non_null(pubkey);
|
||||
|
||||
rc = ssh_pki_export_pubkey_file(pubkey, LIBSSH_ECDSA_TESTKEY ".pub");
|
||||
assert_true(rc == 0);
|
||||
@@ -336,10 +343,12 @@ static void torture_pki_ecdsa_duplicate_key(void **state)
|
||||
|
||||
rc = ssh_pki_import_pubkey_file(LIBSSH_ECDSA_TESTKEY ".pub", &pubkey);
|
||||
assert_true(rc == 0);
|
||||
assert_non_null(pubkey);
|
||||
|
||||
rc = ssh_pki_export_pubkey_base64(pubkey, &b64_key);
|
||||
assert_true(rc == 0);
|
||||
SSH_KEY_FREE(pubkey);
|
||||
assert_non_null(b64_key);
|
||||
|
||||
rc = ssh_pki_import_privkey_file(LIBSSH_ECDSA_TESTKEY,
|
||||
NULL,
|
||||
@@ -391,6 +400,7 @@ static void torture_pki_ecdsa_duplicate_then_demote(void **state)
|
||||
NULL,
|
||||
&privkey);
|
||||
assert_int_equal(rc, 0);
|
||||
assert_non_null(privkey);
|
||||
|
||||
privkey_dup = ssh_key_dup(privkey);
|
||||
assert_non_null(privkey_dup);
|
||||
@@ -486,6 +496,7 @@ static void torture_pki_ecdsa_write_privkey(void **state)
|
||||
NULL,
|
||||
&origkey);
|
||||
assert_true(rc == 0);
|
||||
assert_non_null(origkey);
|
||||
|
||||
unlink(LIBSSH_ECDSA_TESTKEY);
|
||||
|
||||
@@ -534,6 +545,7 @@ static void torture_pki_ecdsa_write_privkey(void **state)
|
||||
NULL,
|
||||
&privkey);
|
||||
assert_true(rc == SSH_ERROR);
|
||||
assert_null(privkey);
|
||||
|
||||
rc = ssh_pki_import_privkey_file(LIBSSH_ECDSA_TESTKEY_PASSPHRASE,
|
||||
torture_get_testkey_passphrase(),
|
||||
@@ -541,6 +553,7 @@ static void torture_pki_ecdsa_write_privkey(void **state)
|
||||
NULL,
|
||||
&privkey);
|
||||
assert_true(rc == 0);
|
||||
assert_non_null(privkey);
|
||||
|
||||
rc = ssh_key_cmp(origkey, privkey, SSH_KEY_CMP_PRIVATE);
|
||||
assert_true(rc == 0);
|
||||
@@ -560,6 +573,7 @@ static void torture_pki_ecdsa_name(void **state, const char *expected_name)
|
||||
|
||||
rc = ssh_pki_import_privkey_file(LIBSSH_ECDSA_TESTKEY, NULL, NULL, NULL, &key);
|
||||
assert_true(rc == 0);
|
||||
assert_non_null(key);
|
||||
|
||||
etype_char =ssh_pki_key_ecdsa_name(key);
|
||||
assert_true(strcmp(etype_char, expected_name) == 0);
|
||||
|
||||
Reference in New Issue
Block a user