2010-03-02 15:47:14 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <pwd.h>
|
2010-03-03 01:48:45 +03:00
|
|
|
|
|
|
|
#define LIBSSH_STATIC
|
2010-03-02 15:47:14 +03:00
|
|
|
#include <libssh/priv.h>
|
|
|
|
|
|
|
|
#include "torture.h"
|
|
|
|
#include "misc.c"
|
2010-05-09 00:13:35 +04:00
|
|
|
#define DIR "/usr/local/bin/truc/much/.."
|
2010-03-02 15:47:14 +03:00
|
|
|
|
2010-05-11 03:12:08 +04:00
|
|
|
ssh_session session;
|
|
|
|
|
|
|
|
static void setup(void) {
|
|
|
|
session = ssh_new();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void teardown(void) {
|
|
|
|
ssh_free(session);
|
|
|
|
}
|
|
|
|
|
2010-03-02 15:47:14 +03:00
|
|
|
START_TEST (torture_get_user_home_dir)
|
|
|
|
{
|
|
|
|
struct passwd *pwd;
|
|
|
|
char *user;
|
|
|
|
|
|
|
|
pwd = getpwuid(getuid());
|
|
|
|
|
|
|
|
user = ssh_get_user_home_dir();
|
|
|
|
ck_assert_str_eq(user, pwd->pw_dir);
|
2010-03-13 18:59:26 +03:00
|
|
|
|
|
|
|
SAFE_FREE(user);
|
2010-03-02 15:47:14 +03:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2010-05-09 00:13:35 +04:00
|
|
|
START_TEST (torture_basename)
|
|
|
|
{
|
|
|
|
char *path;
|
|
|
|
path=ssh_basename(DIR "/test");
|
|
|
|
ck_assert(path != NULL);
|
|
|
|
ck_assert_str_eq(path, "test");
|
|
|
|
SAFE_FREE(path);
|
|
|
|
path=ssh_basename(DIR "/test/");
|
|
|
|
ck_assert(path != NULL);
|
|
|
|
ck_assert_str_eq(path, "test");
|
|
|
|
SAFE_FREE(path);
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST (torture_dirname)
|
|
|
|
{
|
|
|
|
char *path;
|
|
|
|
path=ssh_dirname(DIR "/test");
|
|
|
|
ck_assert(path != NULL);
|
|
|
|
ck_assert_str_eq(path, DIR );
|
|
|
|
SAFE_FREE(path);
|
|
|
|
path=ssh_dirname(DIR "/test/");
|
|
|
|
ck_assert(path != NULL);
|
|
|
|
ck_assert_str_eq(path, DIR);
|
|
|
|
SAFE_FREE(path);
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2010-05-09 00:22:06 +04:00
|
|
|
START_TEST (torture_ntohll)
|
|
|
|
{
|
2010-05-09 00:23:05 +04:00
|
|
|
uint32_t sample = 1;
|
2010-05-09 00:22:06 +04:00
|
|
|
unsigned char *ptr=(unsigned char *) &sample;
|
2010-05-09 00:23:05 +04:00
|
|
|
uint64_t value = 0x0123456789abcdef;
|
|
|
|
uint64_t check;
|
2010-05-09 00:22:06 +04:00
|
|
|
if(ptr[0]==1){
|
|
|
|
/* we're in little endian */
|
|
|
|
check = 0xefcdab8967452301;
|
|
|
|
} else {
|
|
|
|
/* big endian */
|
|
|
|
check = value;
|
|
|
|
}
|
|
|
|
value=ntohll(value);
|
|
|
|
ck_assert(value == check);
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2010-05-11 00:47:21 +04:00
|
|
|
START_TEST (torture_path_expand_tilde)
|
|
|
|
{
|
|
|
|
char h[256];
|
|
|
|
char *d;
|
|
|
|
|
|
|
|
snprintf(h, 256 - 1, "%s/.ssh", getenv("HOME"));
|
|
|
|
|
|
|
|
d = ssh_path_expand_tilde("~/.ssh");
|
|
|
|
ck_assert_str_eq(d, h);
|
|
|
|
free(d);
|
|
|
|
|
|
|
|
d = ssh_path_expand_tilde("/guru/meditation");
|
|
|
|
ck_assert_str_eq(d, "/guru/meditation");
|
|
|
|
free(d);
|
|
|
|
|
|
|
|
snprintf(h, 256 - 1, "~%s/.ssh", getenv("USER"));
|
|
|
|
d = ssh_path_expand_tilde(h);
|
|
|
|
|
|
|
|
snprintf(h, 256 - 1, "%s/.ssh", getenv("HOME"));
|
|
|
|
ck_assert_str_eq(d, h);
|
|
|
|
free(d);
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2010-05-11 03:12:08 +04:00
|
|
|
START_TEST (torture_path_expand_escape)
|
|
|
|
{
|
|
|
|
const char *s = "%d/%h/by/%r";
|
|
|
|
char *e;
|
|
|
|
|
|
|
|
ssh_options_set(session, SSH_OPTIONS_SSH_DIR, "guru");
|
|
|
|
ssh_options_set(session, SSH_OPTIONS_HOST, "meditation");
|
|
|
|
ssh_options_set(session, SSH_OPTIONS_USER, "root");
|
|
|
|
|
|
|
|
e = ssh_path_expand_escape(session, s);
|
|
|
|
ck_assert_str_eq(e, "guru/meditation/by/root");
|
|
|
|
free(e);
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2010-05-19 00:25:06 +04:00
|
|
|
Suite *torture_make_suite(void) {
|
2010-03-02 15:47:14 +03:00
|
|
|
Suite *s = suite_create("libssh_misc");
|
|
|
|
|
|
|
|
torture_create_case(s, "torture_get_user_home_dir", torture_get_user_home_dir);
|
2010-05-09 00:13:35 +04:00
|
|
|
torture_create_case(s, "torture_basename", torture_basename);
|
|
|
|
torture_create_case(s, "torture_dirname", torture_dirname);
|
2010-05-09 00:22:06 +04:00
|
|
|
torture_create_case(s, "torture_ntohll", torture_ntohll);
|
2010-05-11 00:47:21 +04:00
|
|
|
torture_create_case(s, "torture_path_expand_tilde", torture_path_expand_tilde);
|
2010-05-11 03:12:08 +04:00
|
|
|
torture_create_case_fixture(s, "torture_path_expand_escape",
|
|
|
|
torture_path_expand_escape, setup, teardown);
|
2010-03-02 15:47:14 +03:00
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|