Skip to content

Commit

Permalink
Fix broken ssh allocation test
Browse files Browse the repository at this point in the history
  • Loading branch information
worr committed Sep 8, 2016
1 parent c2b190c commit 9e4d862
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion library/src/ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ gint wsh_ssh_host(wsh_ssh_session_t* session, GError** err) {
WSH_SSH_ERROR = g_quark_from_static_string("wsh_ssh_error");
gint ret = 0;
session->session = ssh_new();
if (session == NULL) return -1;
if (session->session == NULL) return -1;

#ifdef DEBUG
if (ssh_set_pcap_file(session->session, pfile)) {
Expand Down
7 changes: 7 additions & 0 deletions library/test/mock/libssh/libssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ gint ssh_scp_push_file_ret;
gint ssh_scp_push_directory_ret;
gint ssh_scp_write_ret;
gint ssh_channel_poll_timeout_ret;
gint ssh_new_ret = 1;

void* ssh_channel_read_set;
guint8 ssh_channel_read_size[4] = { 0x00, 0x00, 0x00, 0x11, };
Expand Down Expand Up @@ -120,7 +121,13 @@ const char* ssh_get_error() {
return NULL;
}

void set_ssh_new_res(gint ret) {
ssh_new_ret = ret;
}

ssh_session ssh_new() {
if (! ssh_new_ret)
return NULL;
return g_malloc0(sizeof(ssh_session));
}

Expand Down
1 change: 1 addition & 0 deletions library/test/mock/libssh/libssh.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ void set_ssh_channel_poll_timeout_ret(gint ret);
gint ssh_channel_poll_timeout();
gint ssh_get_fd();
gint ssh_threads_get_pthread();
void set_ssh_new_res(gint ret);

void set_ssh_threads_set_callbacks_ret(gint ret);

Expand Down
16 changes: 16 additions & 0 deletions library/test/test_ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,20 @@ static void ssh_args(void) {
g_assert(! wsh_ssh_check_args(no_args, &err));
}

static void ssh_alloc_fail(void) {
set_ssh_new_res(0);

wsh_ssh_session_t* session = g_slice_new0(wsh_ssh_session_t);
session->hostname = remote;
session->username = username;
session->password = password;
session->port = port;
GError* err = NULL;
gint ret = wsh_ssh_host(session, &err);

g_assert(ret == -1);
}

int main(int argc, char** argv) {
g_test_init(&argc, &argv, NULL);

Expand Down Expand Up @@ -716,6 +730,8 @@ int main(int argc, char** argv) {

g_test_add_func("/Library/SSH/CheckArgs", ssh_args);

g_test_add_func("/Library/SSH/SSHAllocFailure", ssh_alloc_fail);

return g_test_run();
}

0 comments on commit 9e4d862

Please sign in to comment.