aboutsummaryrefslogtreecommitdiff
path: root/tests/unittests
diff options
context:
space:
mode:
authorAlfredo Mazzinghi <am2419@cl.cam.ac.uk>2016-11-12 01:33:37 +0000
committerAndreas Schneider <asn@cryptomilk.org>2017-04-11 10:00:13 +0200
commit9dc650b7fbaef422e2a148322563106f3fbacb7a (patch)
treee413846318ba14a0d8f288b2cafce2128992ed5f /tests/unittests
parent3ec8babfaf2c2b565f837621d0af094a92252241 (diff)
downloadlibssh-9dc650b7fbaef422e2a148322563106f3fbacb7a.tar.gz
libssh-9dc650b7fbaef422e2a148322563106f3fbacb7a.tar.xz
libssh-9dc650b7fbaef422e2a148322563106f3fbacb7a.zip
server: Add option SSH_BIND_OPTIONS_IMPORT_KEY to server
This sets the bind private key directly from an ssh_key struct instead of reading a file. Signed-off-by: Alfredo Mazzinghi <am2419@cl.cam.ac.uk> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'tests/unittests')
-rw-r--r--tests/unittests/torture_options.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/unittests/torture_options.c b/tests/unittests/torture_options.c
index 4ec3f4cb..820e607d 100644
--- a/tests/unittests/torture_options.c
+++ b/tests/unittests/torture_options.c
@@ -199,6 +199,53 @@ static void torture_options_proxycommand(void **state) {
assert_null(session->opts.ProxyCommand);
}
+
+/* sshbind options */
+static int sshbind_setup(void **state)
+{
+ ssh_bind bind = ssh_bind_new();
+ *state = bind;
+ return 0;
+}
+
+static int sshbind_teardown(void **state)
+{
+ ssh_bind_free(*state);
+ return 0;
+}
+
+static void torture_bind_options_import_key(void **state)
+{
+ ssh_bind bind = *state;
+ int rc;
+ ssh_key key = ssh_key_new();
+ const char *base64_key;
+
+ /* set null */
+ rc = ssh_bind_options_set(bind, SSH_BIND_OPTIONS_IMPORT_KEY, NULL);
+ assert_int_equal(rc, -1);
+ /* set invalid key */
+ rc = ssh_bind_options_set(bind, SSH_BIND_OPTIONS_IMPORT_KEY, key);
+ assert_int_equal(rc, -1);
+
+ /* set rsa key */
+ base64_key = torture_get_testkey(SSH_KEYTYPE_RSA, 0, 0);
+ ssh_pki_import_privkey_base64(base64_key, NULL, NULL, NULL, &key);
+ rc = ssh_bind_options_set(bind, SSH_BIND_OPTIONS_IMPORT_KEY, key);
+ assert_int_equal(rc, 0);
+ /* set dsa key */
+ base64_key = torture_get_testkey(SSH_KEYTYPE_DSS, 0, 0);
+ ssh_pki_import_privkey_base64(base64_key, NULL, NULL, NULL, &key);
+ rc = ssh_bind_options_set(bind, SSH_BIND_OPTIONS_IMPORT_KEY, key);
+ assert_int_equal(rc, 0);
+ /* set ecdsa key */
+ base64_key = torture_get_testkey(SSH_KEYTYPE_ECDSA, 512, 0);
+ ssh_pki_import_privkey_base64(base64_key, NULL, NULL, NULL, &key);
+ rc = ssh_bind_options_set(bind, SSH_BIND_OPTIONS_IMPORT_KEY, key);
+ assert_int_equal(rc, 0);
+}
+
+
int torture_run_tests(void) {
int rc;
struct CMUnitTest tests[] = {
@@ -214,9 +261,14 @@ int torture_run_tests(void) {
cmocka_unit_test_setup_teardown(torture_options_proxycommand, setup, teardown),
};
+ struct CMUnitTest sshbind_tests[] = {
+ cmocka_unit_test_setup_teardown(torture_bind_options_import_key, sshbind_setup, sshbind_teardown),
+ };
+
ssh_init();
torture_filter_tests(tests);
rc = cmocka_run_group_tests(tests, NULL, NULL);
+ rc += cmocka_run_group_tests(sshbind_tests, NULL, NULL);
ssh_finalize();
return rc;
}