From f3a19d8c963a0510ca67a5292436ac5c40c8e788 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Thu, 12 Apr 2018 17:03:06 +0200 Subject: torture_path_expand_tilde_unix: use getpwuid() if no env variables This allows operating under environments where the username variables are not present. Signed-off-by: Nikos Mavrogiannopoulos Reviewed-by: Andreas Schneider --- tests/unittests/torture_misc.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/unittests/torture_misc.c b/tests/unittests/torture_misc.c index de84c4a3..37fa4aed 100644 --- a/tests/unittests/torture_misc.c +++ b/tests/unittests/torture_misc.c @@ -1,5 +1,8 @@ #include "config.h" +#ifdef HAVE_UNISTD_H +#include +#endif #include #ifndef _WIN32 @@ -129,7 +132,14 @@ static void torture_path_expand_tilde_unix(void **state) { if (user == NULL){ user = getenv("LOGNAME"); } - assert_non_null(user); + /* in certain CIs there no such variables */ + if (!user){ + struct passwd *pw = getpwuid(getuid()); + if (pw){ + user = pw->pw_name; + } + } + home = getenv("HOME"); assert_non_null(home); snprintf(h, 256 - 1, "%s/.ssh", home); -- cgit v1.2.3