2017-10-28 15:31:37 +03:00
|
|
|
#include "config.h"
|
|
|
|
|
2017-08-24 16:09:08 +03:00
|
|
|
#define LIBSSH_STATIC
|
|
|
|
|
|
|
|
#include "torture.h"
|
|
|
|
#include "libssh/options.h"
|
2017-10-23 16:06:12 +03:00
|
|
|
#include "libssh/session.h"
|
2017-08-24 16:09:08 +03:00
|
|
|
|
2017-11-20 16:46:41 +03:00
|
|
|
extern LIBSSH_THREAD int ssh_log_level;
|
|
|
|
|
2017-08-24 16:09:08 +03:00
|
|
|
#define LIBSSH_TESTCONFIG1 "libssh_testconfig1.tmp"
|
|
|
|
#define LIBSSH_TESTCONFIG2 "libssh_testconfig2.tmp"
|
|
|
|
#define LIBSSH_TESTCONFIG3 "libssh_testconfig3.tmp"
|
2017-09-10 06:11:47 +03:00
|
|
|
#define LIBSSH_TESTCONFIG4 "libssh_testconfig4.tmp"
|
2017-10-25 15:20:52 +03:00
|
|
|
#define LIBSSH_TESTCONFIG5 "libssh_testconfig5.tmp"
|
|
|
|
#define LIBSSH_TESTCONFIG6 "libssh_testconfig6.tmp"
|
2017-11-13 15:58:32 +03:00
|
|
|
#define LIBSSH_TESTCONFIG7 "libssh_testconfig7.tmp"
|
2017-11-16 18:51:58 +03:00
|
|
|
#define LIBSSH_TESTCONFIG8 "libssh_testconfig8.tmp"
|
2018-08-16 11:32:11 +03:00
|
|
|
#define LIBSSH_TESTCONFIG9 "libssh_testconfig9.tmp"
|
2018-09-04 20:09:08 +03:00
|
|
|
#define LIBSSH_TESTCONFIG10 "libssh_testconfig10.tmp"
|
2017-10-25 15:20:52 +03:00
|
|
|
#define LIBSSH_TESTCONFIGGLOB "libssh_testc*[36].tmp"
|
2017-08-24 16:09:08 +03:00
|
|
|
|
|
|
|
#define USERNAME "testuser"
|
|
|
|
#define PROXYCMD "ssh -q -W %h:%p gateway.example.com"
|
|
|
|
#define ID_FILE "/etc/xxx"
|
2018-09-20 11:39:13 +03:00
|
|
|
#define KEXALGORITHMS "ecdh-sha2-nistp521,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha1"
|
2017-11-13 14:03:52 +03:00
|
|
|
#define HOSTKEYALGORITHMS "ssh-ed25519,ecdsa-sha2-nistp521,ssh-rsa"
|
2018-08-07 12:31:01 +03:00
|
|
|
#define PUBKEYACCEPTEDTYPES "rsa-sha2-512,ssh-rsa,ecdsa-sha2-nistp521"
|
2017-10-23 17:33:28 +03:00
|
|
|
#define MACS "hmac-sha1,hmac-sha2-256"
|
2017-11-13 15:58:32 +03:00
|
|
|
#define USER_KNOWN_HOSTS "%d/my_known_hosts"
|
|
|
|
#define GLOBAL_KNOWN_HOSTS "/etc/ssh/my_ssh_known_hosts"
|
2017-11-16 19:21:23 +03:00
|
|
|
#define BIND_ADDRESS "::1"
|
2017-08-24 16:09:08 +03:00
|
|
|
|
|
|
|
static int setup_config_files(void **state)
|
|
|
|
{
|
|
|
|
ssh_session session;
|
2018-09-04 16:29:01 +03:00
|
|
|
int verbosity;
|
2017-08-24 16:09:08 +03:00
|
|
|
|
|
|
|
unlink(LIBSSH_TESTCONFIG1);
|
|
|
|
unlink(LIBSSH_TESTCONFIG2);
|
|
|
|
unlink(LIBSSH_TESTCONFIG3);
|
2017-09-10 06:11:47 +03:00
|
|
|
unlink(LIBSSH_TESTCONFIG4);
|
2017-10-25 15:20:52 +03:00
|
|
|
unlink(LIBSSH_TESTCONFIG5);
|
|
|
|
unlink(LIBSSH_TESTCONFIG6);
|
2017-11-13 15:58:32 +03:00
|
|
|
unlink(LIBSSH_TESTCONFIG7);
|
2017-11-16 18:51:58 +03:00
|
|
|
unlink(LIBSSH_TESTCONFIG8);
|
2018-09-04 14:50:51 +03:00
|
|
|
unlink(LIBSSH_TESTCONFIG9);
|
2017-08-24 16:09:08 +03:00
|
|
|
|
|
|
|
torture_write_file(LIBSSH_TESTCONFIG1,
|
|
|
|
"User "USERNAME"\nInclude "LIBSSH_TESTCONFIG2"\n\n");
|
|
|
|
torture_write_file(LIBSSH_TESTCONFIG2,
|
|
|
|
"Include "LIBSSH_TESTCONFIG3"\n"
|
|
|
|
"ProxyCommand "PROXYCMD"\n\n");
|
|
|
|
torture_write_file(LIBSSH_TESTCONFIG3,
|
2017-10-23 16:06:12 +03:00
|
|
|
"\n\nIdentityFile "ID_FILE"\n"
|
2017-10-23 17:33:28 +03:00
|
|
|
"\n\nKexAlgorithms "KEXALGORITHMS"\n"
|
2017-11-13 14:03:52 +03:00
|
|
|
"\n\nHostKeyAlgorithms "HOSTKEYALGORITHMS"\n"
|
2018-08-07 12:31:01 +03:00
|
|
|
"\n\nPubkeyAcceptedTypes "PUBKEYACCEPTEDTYPES"\n"
|
2017-10-23 17:33:28 +03:00
|
|
|
"\n\nMACs "MACS"\n");
|
2017-08-24 16:09:08 +03:00
|
|
|
|
2017-09-10 06:11:47 +03:00
|
|
|
/* Multiple Port settings -> parsing returns early. */
|
|
|
|
torture_write_file(LIBSSH_TESTCONFIG4,
|
|
|
|
"Port 123\nPort 456\n");
|
|
|
|
|
2017-10-25 15:20:52 +03:00
|
|
|
/* Testing glob include */
|
|
|
|
torture_write_file(LIBSSH_TESTCONFIG5,
|
|
|
|
"User "USERNAME"\nInclude "LIBSSH_TESTCONFIGGLOB"\n\n");
|
|
|
|
|
|
|
|
torture_write_file(LIBSSH_TESTCONFIG6,
|
|
|
|
"ProxyCommand "PROXYCMD"\n\n");
|
|
|
|
|
2017-11-16 19:21:23 +03:00
|
|
|
/* new options */
|
2017-11-13 15:58:32 +03:00
|
|
|
torture_write_file(LIBSSH_TESTCONFIG7,
|
2017-11-16 19:21:23 +03:00
|
|
|
"\tBindAddress "BIND_ADDRESS"\n"
|
|
|
|
"\tConnectTimeout 30\n"
|
2017-11-20 16:46:41 +03:00
|
|
|
"\tLogLevel DEBUG3\n"
|
2017-11-13 15:58:32 +03:00
|
|
|
"\tGlobalKnownHostsFile "GLOBAL_KNOWN_HOSTS"\n"
|
2018-12-03 20:44:01 +03:00
|
|
|
"\tCompression yes\n"
|
|
|
|
"\tStrictHostkeyChecking no\n"
|
|
|
|
"\tGSSAPIDelegateCredentials yes\n"
|
|
|
|
"\tGSSAPIServerIdentity example.com\n"
|
|
|
|
"\tGSSAPIClientIdentity home.sweet\n"
|
2017-11-13 15:58:32 +03:00
|
|
|
"\tUserKnownHostsFile "USER_KNOWN_HOSTS"\n");
|
|
|
|
|
2017-11-16 18:51:58 +03:00
|
|
|
/* authentication methods */
|
|
|
|
torture_write_file(LIBSSH_TESTCONFIG8,
|
|
|
|
"Host gss\n"
|
|
|
|
"\tGSSAPIAuthentication yes\n"
|
|
|
|
"Host kbd\n"
|
|
|
|
"\tKbdInteractiveAuthentication yes\n"
|
|
|
|
"Host pass\n"
|
|
|
|
"\tPasswordAuthentication yes\n"
|
|
|
|
"Host pubkey\n"
|
|
|
|
"\tPubkeyAuthentication yes\n"
|
|
|
|
"Host nogss\n"
|
|
|
|
"\tGSSAPIAuthentication no\n"
|
|
|
|
"Host nokbd\n"
|
|
|
|
"\tKbdInteractiveAuthentication no\n"
|
|
|
|
"Host nopass\n"
|
|
|
|
"\tPasswordAuthentication no\n"
|
|
|
|
"Host nopubkey\n"
|
|
|
|
"\tPubkeyAuthentication no\n");
|
|
|
|
|
2018-08-16 11:32:11 +03:00
|
|
|
/* unsupported options and corner cases */
|
|
|
|
torture_write_file(LIBSSH_TESTCONFIG9,
|
|
|
|
"\n" /* empty line */
|
|
|
|
"# comment line\n"
|
|
|
|
" # comment line not starting with hash\n"
|
|
|
|
"UnknownConfigurationOption yes\n"
|
|
|
|
"GSSAPIKexAlgorithms yes\n"
|
|
|
|
"ControlMaster auto\n" /* SOC_NA */
|
|
|
|
"VisualHostkey yes\n" /* SOC_UNSUPPORTED */
|
|
|
|
"");
|
|
|
|
|
2018-09-04 20:09:08 +03:00
|
|
|
/* Match keyword */
|
|
|
|
torture_write_file(LIBSSH_TESTCONFIG10,
|
|
|
|
"Match host example\n"
|
|
|
|
"\tHostName example.com\n"
|
|
|
|
"Match host example1,example2\n"
|
|
|
|
"\tHostName exampleN\n"
|
|
|
|
"Match user guest\n"
|
|
|
|
"\tHostName guest.com\n"
|
|
|
|
"Match user tester host testhost\n"
|
|
|
|
"\tHostName testhost.com\n"
|
|
|
|
"Match !user tester host testhost\n"
|
|
|
|
"\tHostName nonuser-testhost.com\n"
|
|
|
|
"Match all\n"
|
|
|
|
"\tHostName all-matched.com\n"
|
|
|
|
"");
|
|
|
|
|
2017-08-24 16:09:08 +03:00
|
|
|
session = ssh_new();
|
2018-09-04 16:29:01 +03:00
|
|
|
|
|
|
|
verbosity = torture_libssh_verbosity();
|
|
|
|
ssh_options_set(session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
|
|
|
|
|
2017-08-24 16:09:08 +03:00
|
|
|
*state = session;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int teardown(void **state)
|
|
|
|
{
|
|
|
|
unlink(LIBSSH_TESTCONFIG1);
|
|
|
|
unlink(LIBSSH_TESTCONFIG2);
|
|
|
|
unlink(LIBSSH_TESTCONFIG3);
|
2017-09-10 06:11:47 +03:00
|
|
|
unlink(LIBSSH_TESTCONFIG4);
|
2017-10-25 15:20:52 +03:00
|
|
|
unlink(LIBSSH_TESTCONFIG5);
|
|
|
|
unlink(LIBSSH_TESTCONFIG6);
|
2017-11-13 15:58:32 +03:00
|
|
|
unlink(LIBSSH_TESTCONFIG7);
|
2017-11-16 18:51:58 +03:00
|
|
|
unlink(LIBSSH_TESTCONFIG8);
|
2018-08-16 11:32:11 +03:00
|
|
|
unlink(LIBSSH_TESTCONFIG9);
|
2018-09-04 20:09:08 +03:00
|
|
|
unlink(LIBSSH_TESTCONFIG10);
|
2017-08-24 16:09:08 +03:00
|
|
|
|
|
|
|
ssh_free(*state);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2017-09-10 06:11:47 +03:00
|
|
|
* @brief tests ssh_config_parse_file with Include directives
|
2017-08-24 16:09:08 +03:00
|
|
|
*/
|
|
|
|
static void torture_config_from_file(void **state) {
|
|
|
|
ssh_session session = *state;
|
|
|
|
int ret;
|
|
|
|
char *v;
|
|
|
|
|
|
|
|
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG1);
|
|
|
|
assert_true(ret == 0);
|
|
|
|
|
|
|
|
/* Test the variable presence */
|
|
|
|
|
|
|
|
ret = ssh_options_get(session, SSH_OPTIONS_PROXYCOMMAND, &v);
|
|
|
|
assert_true(ret == 0);
|
2018-09-13 14:26:18 +03:00
|
|
|
assert_non_null(v);
|
2017-08-24 16:09:08 +03:00
|
|
|
|
|
|
|
assert_string_equal(v, PROXYCMD);
|
2018-09-24 19:24:53 +03:00
|
|
|
SSH_STRING_FREE_CHAR(v);
|
2017-08-24 16:09:08 +03:00
|
|
|
|
|
|
|
ret = ssh_options_get(session, SSH_OPTIONS_IDENTITY, &v);
|
|
|
|
assert_true(ret == 0);
|
2018-09-13 14:26:18 +03:00
|
|
|
assert_non_null(v);
|
2017-08-24 16:09:08 +03:00
|
|
|
|
|
|
|
assert_string_equal(v, ID_FILE);
|
2018-09-24 19:24:53 +03:00
|
|
|
SSH_STRING_FREE_CHAR(v);
|
2017-08-24 16:09:08 +03:00
|
|
|
|
|
|
|
ret = ssh_options_get(session, SSH_OPTIONS_USER, &v);
|
|
|
|
assert_true(ret == 0);
|
2018-09-13 14:26:18 +03:00
|
|
|
assert_non_null(v);
|
2017-08-24 16:09:08 +03:00
|
|
|
|
|
|
|
assert_string_equal(v, USERNAME);
|
2018-09-24 19:24:53 +03:00
|
|
|
SSH_STRING_FREE_CHAR(v);
|
2017-08-24 16:09:08 +03:00
|
|
|
|
2017-10-23 16:06:12 +03:00
|
|
|
assert_string_equal(session->opts.wanted_methods[SSH_KEX], KEXALGORITHMS);
|
2017-10-23 17:33:28 +03:00
|
|
|
|
2017-11-13 14:03:52 +03:00
|
|
|
assert_string_equal(session->opts.wanted_methods[SSH_HOSTKEYS], HOSTKEYALGORITHMS);
|
|
|
|
|
2018-08-07 12:31:01 +03:00
|
|
|
assert_string_equal(session->opts.pubkey_accepted_types, PUBKEYACCEPTEDTYPES);
|
|
|
|
|
2017-10-23 17:33:28 +03:00
|
|
|
assert_string_equal(session->opts.wanted_methods[SSH_MAC_C_S], MACS);
|
|
|
|
assert_string_equal(session->opts.wanted_methods[SSH_MAC_S_C], MACS);
|
2017-08-24 16:09:08 +03:00
|
|
|
}
|
|
|
|
|
2017-09-10 06:11:47 +03:00
|
|
|
/**
|
|
|
|
* @brief tests ssh_config_parse_file with multiple Port settings.
|
|
|
|
*/
|
|
|
|
static void torture_config_double_ports(void **state) {
|
|
|
|
ssh_session session = *state;
|
|
|
|
int ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG4);
|
|
|
|
assert_true(ret == 0);
|
|
|
|
}
|
|
|
|
|
2017-10-25 15:20:52 +03:00
|
|
|
static void torture_config_glob(void **state) {
|
|
|
|
ssh_session session = *state;
|
|
|
|
int ret;
|
2017-12-11 17:37:02 +03:00
|
|
|
#ifdef HAVE_GLOB
|
2017-10-25 15:20:52 +03:00
|
|
|
char *v;
|
2017-12-11 17:37:02 +03:00
|
|
|
#endif
|
2017-10-25 15:20:52 +03:00
|
|
|
|
|
|
|
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG5);
|
2017-12-11 17:37:02 +03:00
|
|
|
assert_true(ret == 0); /* non-existing files should not error */
|
2017-10-25 15:20:52 +03:00
|
|
|
|
|
|
|
/* Test the variable presence */
|
|
|
|
|
2017-12-11 17:37:02 +03:00
|
|
|
#ifdef HAVE_GLOB
|
2017-10-25 15:20:52 +03:00
|
|
|
ret = ssh_options_get(session, SSH_OPTIONS_PROXYCOMMAND, &v);
|
|
|
|
assert_true(ret == 0);
|
2018-08-06 10:43:51 +03:00
|
|
|
assert_non_null(v);
|
2017-10-25 15:20:52 +03:00
|
|
|
|
|
|
|
assert_string_equal(v, PROXYCMD);
|
2018-09-24 19:24:53 +03:00
|
|
|
SSH_STRING_FREE_CHAR(v);
|
2017-10-25 15:20:52 +03:00
|
|
|
|
|
|
|
ret = ssh_options_get(session, SSH_OPTIONS_IDENTITY, &v);
|
|
|
|
assert_true(ret == 0);
|
2018-08-06 10:43:51 +03:00
|
|
|
assert_non_null(v);
|
2017-10-25 15:20:52 +03:00
|
|
|
|
|
|
|
assert_string_equal(v, ID_FILE);
|
2018-09-24 19:24:53 +03:00
|
|
|
SSH_STRING_FREE_CHAR(v);
|
2017-12-11 17:37:02 +03:00
|
|
|
#endif /* HAVE_GLOB */
|
2017-10-25 15:20:52 +03:00
|
|
|
}
|
|
|
|
|
2017-11-13 15:58:32 +03:00
|
|
|
/**
|
2017-11-16 19:21:23 +03:00
|
|
|
* @brief Verify the new options are passed from configuration
|
2017-11-13 15:58:32 +03:00
|
|
|
*/
|
2017-11-16 19:21:23 +03:00
|
|
|
static void torture_config_new(void **state)
|
|
|
|
{
|
2017-11-13 15:58:32 +03:00
|
|
|
ssh_session session = *state;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG7);
|
|
|
|
assert_true(ret == 0);
|
|
|
|
|
|
|
|
assert_string_equal(session->opts.knownhosts, USER_KNOWN_HOSTS);
|
|
|
|
assert_string_equal(session->opts.global_knownhosts, GLOBAL_KNOWN_HOSTS);
|
2017-11-16 19:21:23 +03:00
|
|
|
assert_int_equal(session->opts.timeout, 30);
|
|
|
|
assert_string_equal(session->opts.bindaddr, BIND_ADDRESS);
|
2018-12-03 20:44:01 +03:00
|
|
|
assert_string_equal(session->opts.wanted_methods[SSH_COMP_C_S],
|
|
|
|
"zlib@openssh.com,zlib");
|
|
|
|
assert_string_equal(session->opts.wanted_methods[SSH_COMP_S_C],
|
|
|
|
"zlib@openssh.com,zlib");
|
|
|
|
assert_int_equal(session->opts.StrictHostKeyChecking, 0);
|
|
|
|
assert_int_equal(session->opts.gss_delegate_creds, 1);
|
|
|
|
assert_string_equal(session->opts.gss_server_identity, "example.com");
|
|
|
|
assert_string_equal(session->opts.gss_client_identity, "home.sweet");
|
2017-11-20 16:46:41 +03:00
|
|
|
|
2018-06-30 14:53:39 +03:00
|
|
|
assert_int_equal(ssh_get_log_level(), SSH_LOG_TRACE);
|
2017-11-20 16:46:41 +03:00
|
|
|
assert_int_equal(session->common.log_verbosity, SSH_LOG_TRACE);
|
2017-11-13 15:58:32 +03:00
|
|
|
}
|
|
|
|
|
2017-11-16 18:51:58 +03:00
|
|
|
/**
|
|
|
|
* @brief Verify the authentication methods from configuration are effective
|
|
|
|
*/
|
|
|
|
static void torture_config_auth_methods(void **state) {
|
|
|
|
ssh_session session = *state;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
/* gradually disable all the methods based on different hosts */
|
|
|
|
ssh_options_set(session, SSH_OPTIONS_HOST, "nogss");
|
|
|
|
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG8);
|
|
|
|
assert_true(ret == 0);
|
|
|
|
assert_false(session->opts.flags & SSH_OPT_FLAG_GSSAPI_AUTH);
|
|
|
|
assert_true(session->opts.flags & SSH_OPT_FLAG_KBDINT_AUTH);
|
|
|
|
|
|
|
|
ssh_options_set(session, SSH_OPTIONS_HOST, "nokbd");
|
|
|
|
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG8);
|
|
|
|
assert_true(ret == 0);
|
|
|
|
assert_false(session->opts.flags & SSH_OPT_FLAG_KBDINT_AUTH);
|
|
|
|
|
|
|
|
ssh_options_set(session, SSH_OPTIONS_HOST, "nopass");
|
|
|
|
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG8);
|
|
|
|
assert_true(ret == 0);
|
|
|
|
assert_false(session->opts.flags & SSH_OPT_FLAG_PASSWORD_AUTH);
|
|
|
|
|
|
|
|
ssh_options_set(session, SSH_OPTIONS_HOST, "nopubkey");
|
|
|
|
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG8);
|
|
|
|
assert_true(ret == 0);
|
|
|
|
assert_false(session->opts.flags & SSH_OPT_FLAG_PUBKEY_AUTH);
|
|
|
|
|
|
|
|
/* no method should be left enabled */
|
2018-10-30 14:51:31 +03:00
|
|
|
assert_int_equal(session->opts.flags, 0);
|
2017-11-16 18:51:58 +03:00
|
|
|
|
|
|
|
/* gradually enable them again */
|
2018-10-30 14:52:32 +03:00
|
|
|
SAFE_FREE(session->opts.options_seen);
|
2017-11-16 18:51:58 +03:00
|
|
|
ssh_options_set(session, SSH_OPTIONS_HOST, "gss");
|
|
|
|
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG8);
|
|
|
|
assert_true(ret == 0);
|
|
|
|
assert_true(session->opts.flags & SSH_OPT_FLAG_GSSAPI_AUTH);
|
|
|
|
assert_false(session->opts.flags & SSH_OPT_FLAG_KBDINT_AUTH);
|
|
|
|
|
|
|
|
ssh_options_set(session, SSH_OPTIONS_HOST, "kbd");
|
|
|
|
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG8);
|
|
|
|
assert_true(ret == 0);
|
|
|
|
assert_true(session->opts.flags & SSH_OPT_FLAG_KBDINT_AUTH);
|
|
|
|
|
|
|
|
ssh_options_set(session, SSH_OPTIONS_HOST, "pass");
|
|
|
|
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG8);
|
|
|
|
assert_true(ret == 0);
|
|
|
|
assert_true(session->opts.flags & SSH_OPT_FLAG_PASSWORD_AUTH);
|
|
|
|
|
|
|
|
ssh_options_set(session, SSH_OPTIONS_HOST, "pubkey");
|
|
|
|
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG8);
|
|
|
|
assert_true(ret == 0);
|
|
|
|
assert_true(session->opts.flags & SSH_OPT_FLAG_PUBKEY_AUTH);
|
|
|
|
}
|
|
|
|
|
2018-08-16 11:32:11 +03:00
|
|
|
/**
|
|
|
|
* @brief Verify the configuration parser does not choke on unknown
|
|
|
|
* or unsupported configuration options
|
|
|
|
*/
|
|
|
|
static void torture_config_unknown(void **state) {
|
|
|
|
ssh_session session = *state;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
/* test corner cases */
|
|
|
|
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG9);
|
|
|
|
assert_true(ret == 0);
|
|
|
|
ret = ssh_config_parse_file(session, "/etc/ssh/ssh_config");
|
|
|
|
assert_true(ret == 0);
|
|
|
|
}
|
|
|
|
|
2018-09-04 20:09:08 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Verify the configuration parser accepts Match keyword with
|
|
|
|
* full OpenSSH syntax.
|
|
|
|
*/
|
|
|
|
static void torture_config_match(void **state)
|
|
|
|
{
|
|
|
|
ssh_session session = *state;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
/* Without any settings we should get all-matched.com hostname */
|
|
|
|
ssh_options_set(session, SSH_OPTIONS_HOST, "unmatched");
|
|
|
|
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG10);
|
|
|
|
assert_true(ret == 0);
|
|
|
|
assert_string_equal(session->opts.host, "all-matched.com");
|
|
|
|
|
|
|
|
/* Hostname example does simple hostname matching */
|
2018-10-30 14:52:32 +03:00
|
|
|
SAFE_FREE(session->opts.options_seen);
|
2018-09-04 20:09:08 +03:00
|
|
|
ssh_options_set(session, SSH_OPTIONS_HOST, "example");
|
|
|
|
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG10);
|
|
|
|
assert_true(ret == 0);
|
|
|
|
assert_string_equal(session->opts.host, "example.com");
|
|
|
|
|
|
|
|
/* We can match also both hosts from a comma separated list */
|
2018-10-30 14:52:32 +03:00
|
|
|
SAFE_FREE(session->opts.options_seen);
|
2018-09-04 20:09:08 +03:00
|
|
|
ssh_options_set(session, SSH_OPTIONS_HOST, "example1");
|
|
|
|
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG10);
|
|
|
|
assert_true(ret == 0);
|
|
|
|
assert_string_equal(session->opts.host, "exampleN");
|
|
|
|
|
2018-10-30 14:52:32 +03:00
|
|
|
SAFE_FREE(session->opts.options_seen);
|
2018-09-04 20:09:08 +03:00
|
|
|
ssh_options_set(session, SSH_OPTIONS_HOST, "example2");
|
|
|
|
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG10);
|
|
|
|
assert_true(ret == 0);
|
|
|
|
assert_string_equal(session->opts.host, "exampleN");
|
|
|
|
|
|
|
|
/* We can match by user */
|
2018-10-30 14:52:32 +03:00
|
|
|
SAFE_FREE(session->opts.options_seen);
|
2018-09-04 20:09:08 +03:00
|
|
|
ssh_options_set(session, SSH_OPTIONS_USER, "guest");
|
|
|
|
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG10);
|
|
|
|
assert_true(ret == 0);
|
|
|
|
assert_string_equal(session->opts.host, "guest.com");
|
|
|
|
|
|
|
|
/* We can combine two options on a single line to match both of them */
|
2018-10-30 14:52:32 +03:00
|
|
|
SAFE_FREE(session->opts.options_seen);
|
2018-09-04 20:09:08 +03:00
|
|
|
ssh_options_set(session, SSH_OPTIONS_USER, "tester");
|
|
|
|
ssh_options_set(session, SSH_OPTIONS_HOST, "testhost");
|
|
|
|
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG10);
|
|
|
|
assert_true(ret == 0);
|
|
|
|
assert_string_equal(session->opts.host, "testhost.com");
|
|
|
|
|
|
|
|
/* We can also negate conditions */
|
2018-10-30 14:52:32 +03:00
|
|
|
SAFE_FREE(session->opts.options_seen);
|
2018-09-04 20:09:08 +03:00
|
|
|
ssh_options_set(session, SSH_OPTIONS_USER, "not-tester");
|
|
|
|
ssh_options_set(session, SSH_OPTIONS_HOST, "testhost");
|
|
|
|
ret = ssh_config_parse_file(session, LIBSSH_TESTCONFIG10);
|
|
|
|
assert_true(ret == 0);
|
|
|
|
assert_string_equal(session->opts.host, "nonuser-testhost.com");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-08-24 16:09:08 +03:00
|
|
|
int torture_run_tests(void) {
|
|
|
|
int rc;
|
|
|
|
struct CMUnitTest tests[] = {
|
|
|
|
cmocka_unit_test_setup_teardown(torture_config_from_file,
|
|
|
|
setup_config_files,
|
|
|
|
teardown),
|
2017-09-10 06:11:47 +03:00
|
|
|
cmocka_unit_test_setup_teardown(torture_config_double_ports,
|
|
|
|
setup_config_files,
|
|
|
|
teardown),
|
2017-10-25 15:20:52 +03:00
|
|
|
cmocka_unit_test_setup_teardown(torture_config_glob,
|
|
|
|
setup_config_files,
|
|
|
|
teardown),
|
2017-11-16 19:21:23 +03:00
|
|
|
cmocka_unit_test_setup_teardown(torture_config_new,
|
2017-11-13 15:58:32 +03:00
|
|
|
setup_config_files,
|
|
|
|
teardown),
|
2017-11-16 18:51:58 +03:00
|
|
|
cmocka_unit_test_setup_teardown(torture_config_auth_methods,
|
|
|
|
setup_config_files,
|
|
|
|
teardown),
|
2018-08-16 11:32:11 +03:00
|
|
|
cmocka_unit_test_setup_teardown(torture_config_unknown,
|
|
|
|
setup_config_files,
|
|
|
|
teardown),
|
2018-09-04 20:09:08 +03:00
|
|
|
cmocka_unit_test_setup_teardown(torture_config_match,
|
|
|
|
setup_config_files,
|
|
|
|
teardown),
|
2017-08-24 16:09:08 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ssh_init();
|
|
|
|
torture_filter_tests(tests);
|
|
|
|
rc = cmocka_run_group_tests(tests, NULL, NULL);
|
|
|
|
ssh_finalize();
|
|
|
|
return rc;
|
|
|
|
}
|