Skip to content

Commit

Permalink
Added unit tests for TLS negotiation failure and download of a medium… (
Browse files Browse the repository at this point in the history
#37)

* Added unit tests for TLS negotiation failure and download of a medium-size file

* Use RelWithDebInfo so test failures have meaningful callstacks

* pinned versions of aws-c-common and aws-c-io for CI
  • Loading branch information
Justin Boswell authored May 2, 2019
1 parent 095acca commit 3e4eb7c
Show file tree
Hide file tree
Showing 6 changed files with 356 additions and 7 deletions.
17 changes: 14 additions & 3 deletions codebuild/common-posix.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
#!/bin/bash

set -e
set -x

echo "Using CC=$CC CXX=$CXX"

BUILD_PATH=/tmp/builds
mkdir -p $BUILD_PATH
INSTALL_PATH=$BUILD_PATH/install
mkdir -p $INSTALL_PATH
CMAKE_ARGS="-DCMAKE_PREFIX_PATH=$INSTALL_PATH -DCMAKE_INSTALL_PREFIX=$INSTALL_PATH -DENABLE_SANITIZERS=ON $@"
CMAKE_ARGS="-DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_PREFIX_PATH=$INSTALL_PATH -DCMAKE_INSTALL_PREFIX=$INSTALL_PATH -DENABLE_SANITIZERS=ON $@"

# pushd $BUILD_PATH
# curl -LO https://sourceware.org/pub/valgrind/valgrind-3.15.0.tar.bz2
# tar xvjf valgrind-*.tar.bz2
# cd valgrind-3.15.0
# ./configure
# make -j && sudo make install
# sudo apt-get install -y libc6-dbg
# popd

# install_library <git_repo> [<commit>]
function install_library {
Expand All @@ -31,14 +41,15 @@ if [ "$TRAVIS_OS_NAME" != "osx" ]; then
sudo apt-get install libssl-dev -y
install_library s2n 7c9069618e68214802ac7fbf45705d5f8b53135f
fi
install_library aws-c-common
install_library aws-c-io
install_library aws-c-common v0.3.7
install_library aws-c-io v0.3.5

mkdir -p build
pushd build
cmake $CMAKE_ARGS ../
cmake --build . --target install

#valgrind --leak-check=full --track-origins=yes --show-leak-kinds=all `pwd`/tests/aws-c-http-tests tls_negotiation_timeout
LSAN_OPTIONS=verbosity=1:log_threads=1 ctest --output-on-failure
popd
python3 integration-testing/http_client_test.py $INSTALL_PATH/bin/elasticurl
Expand Down
5 changes: 5 additions & 0 deletions source/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,11 @@ static void s_client_bootstrap_on_channel_setup(
goto error;
}

if (!channel) {
AWS_LOGF_ERROR(AWS_LS_HTTP_CONNECTION, "static: Client connection did not produce a channel");
goto error;
}

AWS_LOGF_TRACE(AWS_LS_HTTP_CONNECTION, "static: Socket connected, creating client connection object.");

struct aws_http_connection *connection = s_connection_new(channel, false, options->is_using_tls, options);
Expand Down
12 changes: 9 additions & 3 deletions source/connection_h1.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ struct aws_http_stream *s_new_client_request_stream(const struct aws_http_reques

wrote_all &= aws_byte_buf_write_u8(&stream->outgoing_head_buf, '\r');
wrote_all &= aws_byte_buf_write_u8(&stream->outgoing_head_buf, '\n');

(void)wrote_all;
assert(wrote_all);

/* Insert new stream into pending list, and schedule outgoing_stream_task if it's not already running. */
Expand Down Expand Up @@ -543,6 +543,11 @@ static void s_update_window_task(struct aws_channel_task *channel_task, void *ar
AWS_FATAL_ASSERT(!err);

size_t window_update_size = connection->synced_data.window_update_size;
AWS_LOGF_TRACE(
AWS_LS_HTTP_CONNECTION,
"id=%p: Zeroing window update size, was %zu",
(void *)&connection->base,
window_update_size);
connection->synced_data.window_update_size = 0;

err = aws_mutex_unlock(&connection->synced_data.lock);
Expand Down Expand Up @@ -573,8 +578,9 @@ static void s_stream_update_window(struct aws_http_stream *stream, size_t increm
int err = aws_mutex_lock(&connection->synced_data.lock);
AWS_FATAL_ASSERT(!err);

bool should_schedule_task = connection->synced_data.window_update_size == 0;

/* if this is not volatile, gcc-4x will load window_update_size's address into a register
* and then read it as should_schedule_task down below, which will invert its meaning */
volatile bool should_schedule_task = (connection->synced_data.window_update_size == 0);
connection->synced_data.window_update_size =
aws_add_size_saturating(connection->synced_data.window_update_size, increment_size);

Expand Down
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ add_test_case(h1_client_close_from_incoming_body_callback_stops_decoder)
add_test_case(h1_client_close_from_stream_complete_callback_stops_decoder)
add_test_case(h1_client_close_from_off_thread_makes_not_open)
add_test_case(h1_client_close_from_on_thread_makes_not_open)
add_test_case(tls_negotiation_timeout)
add_test_case(tls_download_medium_file)
add_test_case(websocket_decoder_sanity_check)
add_test_case(websocket_decoder_simplest_frame)
add_test_case(websocket_decoder_rsv)
Expand Down
6 changes: 5 additions & 1 deletion tests/test_h1_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,9 @@ static int s_window_update(struct aws_allocator *allocator, bool on_thread) {
"Call Momo";
ASSERT_SUCCESS(s_send_response_str(&tester, response_str));

/* drain the task queue, in case there's an update window task in there from the headers */
testing_channel_execute_queued_tasks(&tester.testing_channel);

/* check result */
if (!on_thread) {
testing_channel_set_is_on_users_thread(&tester.testing_channel, false);
Expand All @@ -1161,9 +1164,10 @@ static int s_window_update(struct aws_allocator *allocator, bool on_thread) {
testing_channel_set_is_on_users_thread(&tester.testing_channel, true);
testing_channel_execute_queued_tasks(&tester.testing_channel);
}
testing_channel_execute_queued_tasks(&tester.testing_channel);

size_t window_update = testing_channel_last_window_update(&tester.testing_channel);
ASSERT_TRUE(window_update == 9);
ASSERT_INT_EQUALS(9, window_update);

/* clean up */
ASSERT_SUCCESS(s_response_tester_clean_up(&response));
Expand Down
Loading

0 comments on commit 3e4eb7c

Please sign in to comment.