diff options
author | Aris Adamantiadis <aris@0xbadc0de.be> | 2015-02-12 11:26:50 +0100 |
---|---|---|
committer | Aris Adamantiadis <aris@0xbadc0de.be> | 2015-02-12 11:38:21 +0100 |
commit | 5c46fbc680d34fa4330f40ae447b90f7ceca3ce3 (patch) | |
tree | 3377a18edd8357bd60796400b1e18e71ca55e559 | |
parent | 2a780afc57200699bbd66a32ea5278b1ae8f3f43 (diff) | |
download | libssh-5c46fbc680d34fa4330f40ae447b90f7ceca3ce3.tar.gz libssh-5c46fbc680d34fa4330f40ae447b90f7ceca3ce3.tar.xz libssh-5c46fbc680d34fa4330f40ae447b90f7ceca3ce3.zip |
tests: torture-misc: check for NULL return codes
Use the LOGNAME environment variable if USER is not set, as it sometimes
happens in cron jobs.
-rw-r--r-- | tests/unittests/torture_misc.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/tests/unittests/torture_misc.c b/tests/unittests/torture_misc.c index ad772450..b3b73efd 100644 --- a/tests/unittests/torture_misc.c +++ b/tests/unittests/torture_misc.c @@ -113,23 +113,35 @@ static void torture_path_expand_tilde_win(void **state) { static void torture_path_expand_tilde_unix(void **state) { char h[256]; char *d; + char *user; + char *home; (void) state; - snprintf(h, 256 - 1, "%s/.ssh", getenv("HOME")); + user = getenv("USER"); + if (user == NULL){ + user = getenv("LOGNAME"); + } + assert_non_null(user); + home = getenv("HOME"); + assert_non_null(home); + snprintf(h, 256 - 1, "%s/.ssh", home); d = ssh_path_expand_tilde("~/.ssh"); + assert_non_null(d); assert_string_equal(d, h); free(d); d = ssh_path_expand_tilde("/guru/meditation"); + assert_non_null(d); assert_string_equal(d, "/guru/meditation"); free(d); - snprintf(h, 256 - 1, "~%s/.ssh", getenv("USER")); + snprintf(h, 256 - 1, "~%s/.ssh", user); d = ssh_path_expand_tilde(h); + assert_non_null(d); - snprintf(h, 256 - 1, "%s/.ssh", getenv("HOME")); + snprintf(h, 256 - 1, "%s/.ssh", home); assert_string_equal(d, h); free(d); } @@ -146,6 +158,7 @@ static void torture_path_expand_escape(void **state) { session->opts.username = strdup("root"); e = ssh_path_expand_escape(session, s); + assert_non_null(e); assert_string_equal(e, "guru/meditation/by/root"); free(e); } @@ -157,6 +170,7 @@ static void torture_path_expand_known_hosts(void **state) { session->opts.sshdir = strdup("/home/guru/.ssh"); tmp = ssh_path_expand_escape(session, "%d/known_hosts"); + assert_non_null(tmp); assert_string_equal(tmp, "/home/guru/.ssh/known_hosts"); free(tmp); } |