mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-05-31 16:21:13 +03:00
tests: Migrate torture_request_env to cwrap test
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
parent
27834cce2c
commit
4bc6af6c17
@ -2,7 +2,6 @@ project(clienttests C)
|
|||||||
|
|
||||||
find_package(socket_wrapper)
|
find_package(socket_wrapper)
|
||||||
|
|
||||||
add_cmocka_test(torture_request_env torture_request_env.c ${TORTURE_LIBRARY})
|
|
||||||
if (WITH_SFTP)
|
if (WITH_SFTP)
|
||||||
add_cmocka_test(torture_sftp_static torture_sftp_static.c ${TORTURE_LIBRARY})
|
add_cmocka_test(torture_sftp_static torture_sftp_static.c ${TORTURE_LIBRARY})
|
||||||
add_cmocka_test(torture_sftp_dir torture_sftp_dir.c ${TORTURE_LIBRARY})
|
add_cmocka_test(torture_sftp_dir torture_sftp_dir.c ${TORTURE_LIBRARY})
|
||||||
@ -16,7 +15,8 @@ set(LIBSSH_CLIENT_TESTS
|
|||||||
torture_forward
|
torture_forward
|
||||||
torture_knownhosts
|
torture_knownhosts
|
||||||
torture_proxycommand
|
torture_proxycommand
|
||||||
torture_session)
|
torture_session
|
||||||
|
torture_request_env)
|
||||||
|
|
||||||
foreach(_CLI_TEST ${LIBSSH_CLIENT_TESTS})
|
foreach(_CLI_TEST ${LIBSSH_CLIENT_TESTS})
|
||||||
add_cmocka_test(${_CLI_TEST} ${_CLI_TEST}.c ${TORTURE_LIBRARY})
|
add_cmocka_test(${_CLI_TEST} ${_CLI_TEST}.c ${TORTURE_LIBRARY})
|
||||||
|
@ -24,46 +24,54 @@
|
|||||||
#include "torture.h"
|
#include "torture.h"
|
||||||
#include <libssh/libssh.h>
|
#include <libssh/libssh.h>
|
||||||
|
|
||||||
static int setup(void **state)
|
#include <sys/types.h>
|
||||||
|
#include <pwd.h>
|
||||||
|
|
||||||
|
static int sshd_setup(void **state)
|
||||||
{
|
{
|
||||||
ssh_session session;
|
torture_setup_sshd_server(state);
|
||||||
const char *host;
|
|
||||||
const char *user;
|
|
||||||
const char *password;
|
|
||||||
|
|
||||||
host = getenv("TORTURE_HOST");
|
|
||||||
if (host == NULL) {
|
|
||||||
host = "localhost";
|
|
||||||
}
|
|
||||||
|
|
||||||
user = getenv("TORTURE_USER");
|
|
||||||
password = getenv("TORTURE_PASSWORD");
|
|
||||||
|
|
||||||
session = torture_ssh_session(host, NULL, user, password);
|
|
||||||
|
|
||||||
assert_false(session == NULL);
|
|
||||||
*state = session;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int teardown(void **state)
|
static int sshd_teardown(void **state) {
|
||||||
|
torture_teardown_sshd_server(state);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int session_setup(void **state)
|
||||||
{
|
{
|
||||||
ssh_session session = *state;
|
struct torture_state *s = *state;
|
||||||
|
struct passwd *pwd;
|
||||||
|
|
||||||
assert_false(session == NULL);
|
pwd = getpwnam("bob");
|
||||||
|
assert_non_null(pwd);
|
||||||
|
setuid(pwd->pw_uid);
|
||||||
|
|
||||||
if (ssh_is_connected(session)) {
|
s->ssh.session = torture_ssh_session(TORTURE_SSH_SERVER,
|
||||||
ssh_disconnect(session);
|
NULL,
|
||||||
}
|
TORTURE_SSH_USER_ALICE,
|
||||||
ssh_free(session);
|
NULL);
|
||||||
|
assert_non_null(s->ssh.session);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int session_teardown(void **state)
|
||||||
|
{
|
||||||
|
struct torture_state *s = *state;
|
||||||
|
|
||||||
|
ssh_disconnect(s->ssh.session);
|
||||||
|
ssh_free(s->ssh.session);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void torture_request_env(void **state)
|
static void torture_request_env(void **state)
|
||||||
{
|
{
|
||||||
ssh_session session = *state;
|
struct torture_state *s = *state;
|
||||||
|
ssh_session session = s->ssh.session;
|
||||||
ssh_channel c;
|
ssh_channel c;
|
||||||
char buffer[4096] = {0};
|
char buffer[4096] = {0};
|
||||||
int nbytes;
|
int nbytes;
|
||||||
@ -83,8 +91,9 @@ static void torture_request_env(void **state)
|
|||||||
assert_int_equal(rc, SSH_OK);
|
assert_int_equal(rc, SSH_OK);
|
||||||
|
|
||||||
nbytes = ssh_channel_read(c, buffer, sizeof(buffer) - 1, 0);
|
nbytes = ssh_channel_read(c, buffer, sizeof(buffer) - 1, 0);
|
||||||
|
printf("nbytes=%d\n", nbytes);
|
||||||
while (nbytes > 0) {
|
while (nbytes > 0) {
|
||||||
#if 0
|
#if 1
|
||||||
rc = fwrite(buffer, 1, nbytes, stdout);
|
rc = fwrite(buffer, 1, nbytes, stdout);
|
||||||
assert_int_equal(rc, nbytes);
|
assert_int_equal(rc, nbytes);
|
||||||
#endif
|
#endif
|
||||||
@ -105,13 +114,15 @@ int torture_run_tests(void) {
|
|||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
struct CMUnitTest tests[] = {
|
struct CMUnitTest tests[] = {
|
||||||
cmocka_unit_test_setup_teardown(torture_request_env, setup, teardown),
|
cmocka_unit_test_setup_teardown(torture_request_env,
|
||||||
|
session_setup,
|
||||||
|
session_teardown),
|
||||||
};
|
};
|
||||||
|
|
||||||
ssh_init();
|
ssh_init();
|
||||||
|
|
||||||
torture_filter_tests(tests);
|
torture_filter_tests(tests);
|
||||||
rc = cmocka_run_group_tests(tests, NULL, NULL);
|
rc = cmocka_run_group_tests(tests, sshd_setup, sshd_teardown);
|
||||||
|
|
||||||
ssh_finalize();
|
ssh_finalize();
|
||||||
return rc;
|
return rc;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user