mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-11 10:40:27 +09:00
tests: Move getpwuid_r to a setup function.
This commit is contained in:
@@ -4,12 +4,32 @@
|
|||||||
#include "options.c"
|
#include "options.c"
|
||||||
|
|
||||||
ssh_session session;
|
ssh_session session;
|
||||||
|
#ifndef _WIN32
|
||||||
|
struct passwd pwd;
|
||||||
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
static void setup(void) {
|
static void setup(void) {
|
||||||
session = ssh_new();
|
session = ssh_new();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void setup_passwd(void) {
|
||||||
|
int rc;
|
||||||
|
#ifndef _WIN32
|
||||||
|
#ifndef NSS_BUFLEN_PASSWD
|
||||||
|
#define NSS_BUFLEN_PASSWD 4096
|
||||||
|
#endif /* NSS_BUFLEN_PASSWD */
|
||||||
|
struct passwd *pwdbuf;
|
||||||
|
char buf[NSS_BUFLEN_PASSWD];
|
||||||
|
|
||||||
|
/* get local username */
|
||||||
|
rc = getpwuid_r(getuid(), &pwd, buf, NSS_BUFLEN_PASSWD, &pwdbuf);
|
||||||
|
ck_assert(rc == 0);
|
||||||
|
#endif /* _WIN32 */
|
||||||
|
session = ssh_new();
|
||||||
|
}
|
||||||
|
|
||||||
static void teardown(void) {
|
static void teardown(void) {
|
||||||
|
ZERO_STRUCT(pwd);
|
||||||
ssh_free(session);
|
ssh_free(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,14 +89,6 @@ END_TEST
|
|||||||
START_TEST (torture_options_set_user)
|
START_TEST (torture_options_set_user)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
#ifndef _WIN32
|
|
||||||
#ifndef NSS_BUFLEN_PASSWD
|
|
||||||
#define NSS_BUFLEN_PASSWD 4096
|
|
||||||
#endif
|
|
||||||
struct passwd pwd;
|
|
||||||
struct passwd *pwdbuf;
|
|
||||||
char buf[NSS_BUFLEN_PASSWD];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
rc = ssh_options_set(session, SSH_OPTIONS_USER, "guru");
|
rc = ssh_options_set(session, SSH_OPTIONS_USER, "guru");
|
||||||
ck_assert(rc == 0);
|
ck_assert(rc == 0);
|
||||||
@@ -87,10 +99,6 @@ START_TEST (torture_options_set_user)
|
|||||||
ck_assert(rc == 0);
|
ck_assert(rc == 0);
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
/* get local username */
|
|
||||||
rc = getpwuid_r(getuid(), &pwd, buf, NSS_BUFLEN_PASSWD, &pwdbuf);
|
|
||||||
ck_assert(rc == 0);
|
|
||||||
|
|
||||||
ck_assert_str_eq(session->username, pwd.pw_name);
|
ck_assert_str_eq(session->username, pwd.pw_name);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -129,7 +137,7 @@ Suite *torture_make_suite(void) {
|
|||||||
torture_create_case_fixture(s, "torture_options_set_fd",
|
torture_create_case_fixture(s, "torture_options_set_fd",
|
||||||
torture_options_set_fd, setup, teardown);
|
torture_options_set_fd, setup, teardown);
|
||||||
torture_create_case_fixture(s, "torture_options_set_user",
|
torture_create_case_fixture(s, "torture_options_set_user",
|
||||||
torture_options_set_user, setup, teardown);
|
torture_options_set_user, setup_passwd, teardown);
|
||||||
torture_create_case_fixture(s, "torture_options_set_identity",
|
torture_create_case_fixture(s, "torture_options_set_identity",
|
||||||
torture_options_set_identity, setup, teardown);
|
torture_options_set_identity, setup, teardown);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user