mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-05-30 05:24:50 +03:00
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.
This commit is contained in:
parent
2a780afc57
commit
5c46fbc680
@ -113,23 +113,35 @@ static void torture_path_expand_tilde_win(void **state) {
|
|||||||
static void torture_path_expand_tilde_unix(void **state) {
|
static void torture_path_expand_tilde_unix(void **state) {
|
||||||
char h[256];
|
char h[256];
|
||||||
char *d;
|
char *d;
|
||||||
|
char *user;
|
||||||
|
char *home;
|
||||||
|
|
||||||
(void) state;
|
(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");
|
d = ssh_path_expand_tilde("~/.ssh");
|
||||||
|
assert_non_null(d);
|
||||||
assert_string_equal(d, h);
|
assert_string_equal(d, h);
|
||||||
free(d);
|
free(d);
|
||||||
|
|
||||||
d = ssh_path_expand_tilde("/guru/meditation");
|
d = ssh_path_expand_tilde("/guru/meditation");
|
||||||
|
assert_non_null(d);
|
||||||
assert_string_equal(d, "/guru/meditation");
|
assert_string_equal(d, "/guru/meditation");
|
||||||
free(d);
|
free(d);
|
||||||
|
|
||||||
snprintf(h, 256 - 1, "~%s/.ssh", getenv("USER"));
|
snprintf(h, 256 - 1, "~%s/.ssh", user);
|
||||||
d = ssh_path_expand_tilde(h);
|
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);
|
assert_string_equal(d, h);
|
||||||
free(d);
|
free(d);
|
||||||
}
|
}
|
||||||
@ -146,6 +158,7 @@ static void torture_path_expand_escape(void **state) {
|
|||||||
session->opts.username = strdup("root");
|
session->opts.username = strdup("root");
|
||||||
|
|
||||||
e = ssh_path_expand_escape(session, s);
|
e = ssh_path_expand_escape(session, s);
|
||||||
|
assert_non_null(e);
|
||||||
assert_string_equal(e, "guru/meditation/by/root");
|
assert_string_equal(e, "guru/meditation/by/root");
|
||||||
free(e);
|
free(e);
|
||||||
}
|
}
|
||||||
@ -157,6 +170,7 @@ static void torture_path_expand_known_hosts(void **state) {
|
|||||||
session->opts.sshdir = strdup("/home/guru/.ssh");
|
session->opts.sshdir = strdup("/home/guru/.ssh");
|
||||||
|
|
||||||
tmp = ssh_path_expand_escape(session, "%d/known_hosts");
|
tmp = ssh_path_expand_escape(session, "%d/known_hosts");
|
||||||
|
assert_non_null(tmp);
|
||||||
assert_string_equal(tmp, "/home/guru/.ssh/known_hosts");
|
assert_string_equal(tmp, "/home/guru/.ssh/known_hosts");
|
||||||
free(tmp);
|
free(tmp);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user