diff --git a/tests/client/torture_session.c b/tests/client/torture_session.c index d83ec9b6..2fa2ae33 100644 --- a/tests/client/torture_session.c +++ b/tests/client/torture_session.c @@ -218,6 +218,46 @@ static void torture_max_sessions(void **state) #undef MAX_CHANNELS } +static void torture_channel_delayed_close(void **state) +{ + struct torture_state *s = *state; + ssh_session session = s->ssh.session; + ssh_channel channel; + + char request[256]; + char buff[256] = {0}; + + int rc; + int fd; + + snprintf(request, 256, + "dd if=/dev/urandom of=/tmp/file bs=64000 count=2; hexdump -C /tmp/file"); + + channel = ssh_channel_new(session); + assert_non_null(channel); + + rc = ssh_channel_open_session(channel); + assert_ssh_return_code(session, rc); + + fd = ssh_get_fd(session); + assert_true(fd > 2); + + /* Make the request, read parts with close */ + rc = ssh_channel_request_exec(channel, request); + assert_ssh_return_code(session, rc); + + do { + rc = ssh_channel_read(channel, buff, 256, 0); + } while(rc > 0); + assert_ssh_return_code(session, rc); + + rc = ssh_channel_poll_timeout(channel, 500, 0); + assert_int_equal(rc, SSH_EOF); + + ssh_channel_free(channel); + +} + int torture_run_tests(void) { int rc; struct CMUnitTest tests[] = { @@ -233,6 +273,9 @@ int torture_run_tests(void) { cmocka_unit_test_setup_teardown(torture_max_sessions, session_setup, session_teardown), + cmocka_unit_test_setup_teardown(torture_channel_delayed_close, + session_setup, + session_teardown), }; ssh_init();