From db8facbb6b1a4107e22fe8064ee7e9aa4f8e96ad Mon Sep 17 00:00:00 2001 From: Dengke Tang Date: Mon, 20 Sep 2021 15:53:14 -0700 Subject: [PATCH 01/10] fix a bug I forgot --- source/proxy_connection.c | 9 ++++++++- tests/CMakeLists.txt | 1 + tests/test_connection.c | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/source/proxy_connection.c b/source/proxy_connection.c index 1ab165ca9..22ff452c3 100644 --- a/source/proxy_connection.c +++ b/source/proxy_connection.c @@ -1190,7 +1190,7 @@ static int s_connect_proxy_via_env_variable(const struct aws_http_client_connect proxy_options.connection_type = options->proxy_ev_settings->connection_type; if (proxy_options.connection_type == AWS_HPCT_HTTP_LEGACY) { if (options->tls_options) { - /* Use Tunneling when main connection use TLS. */ + /* Use tunneling when main connection use TLS. */ proxy_options.connection_type = AWS_HPCT_HTTP_TUNNEL; } else { /* Use forwarding proxy when main connection use clear text. */ @@ -1212,6 +1212,9 @@ static int s_connect_proxy_via_env_variable(const struct aws_http_client_connect }; proxy_options.proxy_strategy = aws_http_proxy_strategy_new_basic_auth(options->allocator, &config); } + } else { + success = true; + goto done; } struct aws_http_client_connection_options copied_options = *options; copied_options.proxy_options = &proxy_options; @@ -1223,6 +1226,10 @@ static int s_connect_proxy_via_env_variable(const struct aws_http_client_connect aws_tls_connection_options_clean_up(&default_tls_connection_options); aws_http_proxy_strategy_release(proxy_options.proxy_strategy); aws_uri_clean_up(&proxy_uri); + if (success && !found) { + /* Successfully, but no envrionment variable found. Connect without proxy */ + return aws_http_client_connect_internal(options, NULL); + } return success ? AWS_OP_SUCCESS : AWS_OP_ERR; } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 67fa14de5..a0e646d7a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -442,6 +442,7 @@ add_test_case(h2_client_get_remote_settings) add_test_case(server_new_destroy) add_test_case(connection_setup_shutdown) add_test_case(connection_setup_shutdown_tls) +add_test_case(connection_setup_shutdown_proxy_setting_on_ev_not_found) add_test_case(connection_h2_prior_knowledge) add_test_case(connection_h2_prior_knowledge_not_work_with_tls) add_test_case(connection_customized_alpn) diff --git a/tests/test_connection.c b/tests/test_connection.c index 42b8cbf7d..a7d78d5cb 100644 --- a/tests/test_connection.c +++ b/tests/test_connection.c @@ -471,6 +471,43 @@ static int s_test_connection_setup_shutdown_tls(struct aws_allocator *allocator, } AWS_TEST_CASE(connection_setup_shutdown_tls, s_test_connection_setup_shutdown_tls); +static int s_test_connection_setup_shutdown_proxy_setting_on_ev_not_found(struct aws_allocator *allocator, void *ctx) { + (void)ctx; + struct tester_options options = { + .alloc = allocator, + .no_connection = true, + }; + struct tester tester; + ASSERT_SUCCESS(s_tester_init(&tester, &options)); + struct aws_http_client_connection_options client_options = AWS_HTTP_CLIENT_CONNECTION_OPTIONS_INIT; + struct proxy_env_var_settings proxy_ev_settings; + AWS_ZERO_STRUCT(proxy_ev_settings); + proxy_ev_settings.env_var_type = AWS_HPEV_ENABLE; + client_options.proxy_ev_settings = &proxy_ev_settings; + + s_client_connection_options_init_tester(&client_options, &tester); + tester.client_options = client_options; + + tester.server_connection_num = 0; + tester.client_connection_num = 0; + ASSERT_SUCCESS(aws_http_client_connect(&tester.client_options)); + + /* Wait for server & client connections to finish setup */ + tester.wait_client_connection_num = 1; + tester.wait_server_connection_num = 1; + ASSERT_SUCCESS(s_tester_wait(&tester, s_tester_connection_setup_pred)); + + release_all_client_connections(&tester); + release_all_server_connections(&tester); + ASSERT_SUCCESS(s_tester_wait(&tester, s_tester_connection_shutdown_pred)); + + ASSERT_SUCCESS(s_tester_clean_up(&tester)); + return AWS_OP_SUCCESS; +} +AWS_TEST_CASE( + connection_setup_shutdown_proxy_setting_on_ev_not_found, + s_test_connection_setup_shutdown_proxy_setting_on_ev_not_found); + static int s_test_connection_h2_prior_knowledge(struct aws_allocator *allocator, void *ctx) { (void)ctx; struct tester_options options = { From be991adeed198e84de6590b98533ba76ef2ff5f2 Mon Sep 17 00:00:00 2001 From: Dengke Tang Date: Wed, 22 Sep 2021 10:13:01 -0700 Subject: [PATCH 02/10] byo_crypto for http --- .github/workflows/ci.yml | 9 +++++++++ CMakeLists.txt | 2 +- source/proxy_connection.c | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3bef0aba7..0b61da7a7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -79,6 +79,15 @@ jobs: aws s3 cp s3://aws-crt-test-stuff/ci/${{ env.BUILDER_VERSION }}/linux-container-ci.sh ./linux-container-ci.sh && chmod a+x ./linux-container-ci.sh ./linux-container-ci.sh ${{ env.BUILDER_VERSION }} aws-crt-${{ env.LINUX_BASE_IMAGE }} build -p ${{ env.PACKAGE_NAME }} --cmake-extra=-DBUILD_SHARED_LIBS=ON + byo-crypto: + runs-on: ubuntu-latest + steps: + # We can't use the `uses: docker://image` version yet, GitHub lacks authentication for actions -> packages + - name: Build ${{ env.PACKAGE_NAME }} + run: | + aws s3 cp s3://aws-crt-test-stuff/ci/${{ env.BUILDER_VERSION }}/linux-container-ci.sh ./linux-container-ci.sh && chmod a+x ./linux-container-ci.sh + ./linux-container-ci.sh ${{ env.BUILDER_VERSION }} aws-crt-${{ env.LINUX_BASE_IMAGE }} build -p ${{ env.PACKAGE_NAME }} --cmake-extra=-DBYO_CRYPTO=ON downstream + windows: runs-on: windows-latest steps: diff --git a/CMakeLists.txt b/CMakeLists.txt index 862e0d55a..2d5a455e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,7 +96,7 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" COMPONENT Development) include(CTest) -if (BUILD_TESTING) +if (NOT BYO_CRYPTO AND BUILD_TESTING) add_subdirectory(tests) if (NOT CMAKE_CROSSCOMPILING ) diff --git a/source/proxy_connection.c b/source/proxy_connection.c index 22ff452c3..6a25e82d1 100644 --- a/source/proxy_connection.c +++ b/source/proxy_connection.c @@ -1139,6 +1139,13 @@ static int s_setup_proxy_tls_env_variable( if (options->proxy_ev_settings->tls_options) { proxy_options->tls_options = options->proxy_ev_settings->tls_options; } else { +#ifdef BYO_CRYPTO + AWS_LOGF_ERROR( + AWS_LS_HTTP_CONNECTION, + "Failed making default TLS context because of BYO_CRYPTO, set up the tls_options for proxy_env_settings to " + "make it work."); + return AWS_OP_ERR; +#endif struct aws_tls_ctx *tls_ctx = NULL; struct aws_tls_ctx_options tls_ctx_options; AWS_ZERO_STRUCT(tls_ctx_options); From 5c66c7e50a6d344907ef45ad3897069ceea87ccd Mon Sep 17 00:00:00 2001 From: Dengke Tang Date: Wed, 22 Sep 2021 10:19:38 -0700 Subject: [PATCH 03/10] else? --- source/proxy_connection.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/proxy_connection.c b/source/proxy_connection.c index 6a25e82d1..e3d52b3f3 100644 --- a/source/proxy_connection.c +++ b/source/proxy_connection.c @@ -1145,7 +1145,7 @@ static int s_setup_proxy_tls_env_variable( "Failed making default TLS context because of BYO_CRYPTO, set up the tls_options for proxy_env_settings to " "make it work."); return AWS_OP_ERR; -#endif +#else struct aws_tls_ctx *tls_ctx = NULL; struct aws_tls_ctx_options tls_ctx_options; AWS_ZERO_STRUCT(tls_ctx_options); @@ -1174,6 +1174,7 @@ static int s_setup_proxy_tls_env_variable( return AWS_OP_ERR; } proxy_options->tls_options = default_tls_connection_options; +#endif } return AWS_OP_SUCCESS; } From bf115468be64bd27580827d5f69cfb51adb8dbf8 Mon Sep 17 00:00:00 2001 From: Dengke Tang Date: Wed, 22 Sep 2021 10:23:22 -0700 Subject: [PATCH 04/10] unused param --- source/proxy_connection.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/proxy_connection.c b/source/proxy_connection.c index e3d52b3f3..db0e226fb 100644 --- a/source/proxy_connection.c +++ b/source/proxy_connection.c @@ -1136,6 +1136,8 @@ static int s_setup_proxy_tls_env_variable( struct aws_tls_connection_options *default_tls_connection_options, struct aws_http_proxy_options *proxy_options, struct aws_uri *proxy_uri) { + (void)default_tls_connection_options; + (void)proxy_uri; if (options->proxy_ev_settings->tls_options) { proxy_options->tls_options = options->proxy_ev_settings->tls_options; } else { From bb87183e4699fe15098f50278995bd52b95e079c Mon Sep 17 00:00:00 2001 From: Dengke Tang Date: Wed, 22 Sep 2021 10:26:50 -0700 Subject: [PATCH 05/10] another not used --- source/proxy_connection.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/proxy_connection.c b/source/proxy_connection.c index db0e226fb..86a976432 100644 --- a/source/proxy_connection.c +++ b/source/proxy_connection.c @@ -34,7 +34,9 @@ AWS_STATIC_STRING_FROM_LITERAL(s_http_proxy_env_var_low, "http_proxy"); AWS_STATIC_STRING_FROM_LITERAL(s_https_proxy_env_var, "HTTPS_PROXY"); AWS_STATIC_STRING_FROM_LITERAL(s_https_proxy_env_var_low, "https_proxy"); +#ifndef BYO_CRYPTO AWS_STATIC_STRING_FROM_LITERAL(s_proxy_no_verify_peer_env_var, "AWS_PROXY_NO_VERIFY_PEER"); +#endif static struct aws_http_proxy_system_vtable s_default_vtable = { .setup_client_tls = &aws_channel_setup_client_tls, From 49d24c17bc3e39a0199fa4463be0aff1827615fd Mon Sep 17 00:00:00 2001 From: Dengke Tang Date: Wed, 22 Sep 2021 10:36:47 -0700 Subject: [PATCH 06/10] I don't know... Test --- CMakeLists.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d5a455e3..1f8168865 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,9 +96,10 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" COMPONENT Development) include(CTest) -if (NOT BYO_CRYPTO AND BUILD_TESTING) - add_subdirectory(tests) - +if (BUILD_TESTING) + if(NOT BYO_CRYPTO) + add_subdirectory(tests) + endif() if (NOT CMAKE_CROSSCOMPILING ) add_subdirectory(bin/elasticurl) endif() From 3f43fe1a468a34dcd99894c7a6b6bbbd63e79581 Mon Sep 17 00:00:00 2001 From: Dengke Tang Date: Wed, 22 Sep 2021 10:37:00 -0700 Subject: [PATCH 07/10] format --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f8168865..cc36ad1d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,7 +99,7 @@ include(CTest) if (BUILD_TESTING) if(NOT BYO_CRYPTO) add_subdirectory(tests) - endif() + endif() if (NOT CMAKE_CROSSCOMPILING ) add_subdirectory(bin/elasticurl) endif() From 2a15c21f2d32a10ee589c87cbd66e4718dfe9ff9 Mon Sep 17 00:00:00 2001 From: Dengke Tang Date: Wed, 22 Sep 2021 10:44:32 -0700 Subject: [PATCH 08/10] turn it back --- CMakeLists.txt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cc36ad1d1..2471669d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,11 +96,9 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" COMPONENT Development) include(CTest) -if (BUILD_TESTING) - if(NOT BYO_CRYPTO) - add_subdirectory(tests) - endif() - if (NOT CMAKE_CROSSCOMPILING ) +if (NOT BYO_CRYPTO AND BUILD_TESTING) + add_subdirectory(tests) + if (NOT CMAKE_CROSSCOMPILING) add_subdirectory(bin/elasticurl) endif() endif() From 29019f2f8f24bcd7e4aa121f7c830265e0b24b41 Mon Sep 17 00:00:00 2001 From: Dengke Tang Date: Wed, 22 Sep 2021 10:59:09 -0700 Subject: [PATCH 09/10] disable integration test when BYO_CRYPTO --- .github/workflows/ci.yml | 1 + integration-testing/http_client_test.py | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0b61da7a7..0f0396ec7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -86,6 +86,7 @@ jobs: - name: Build ${{ env.PACKAGE_NAME }} run: | aws s3 cp s3://aws-crt-test-stuff/ci/${{ env.BUILDER_VERSION }}/linux-container-ci.sh ./linux-container-ci.sh && chmod a+x ./linux-container-ci.sh + export BYO_CRYPTO=ON ./linux-container-ci.sh ${{ env.BUILDER_VERSION }} aws-crt-${{ env.LINUX_BASE_IMAGE }} build -p ${{ env.PACKAGE_NAME }} --cmake-extra=-DBYO_CRYPTO=ON downstream windows: diff --git a/integration-testing/http_client_test.py b/integration-testing/http_client_test.py index 33d22eed6..38469d66f 100644 --- a/integration-testing/http_client_test.py +++ b/integration-testing/http_client_test.py @@ -5,9 +5,14 @@ import sys import urllib.request import unittest +import os TIMEOUT = 100 +if os.getenv("BYO_CRYPTO") is not None: + print('BYO_CRYPTO, not running integration test') + sys.exit(0) + # Accepting multiple args so we can pass something like: python elasticurl.py elasticurl_cmd_prefix = sys.argv[1:] if not elasticurl_cmd_prefix: From f5d5bcf40d73f1a541ef4ccd301569ba16bf5b0a Mon Sep 17 00:00:00 2001 From: Dengke Tang Date: Wed, 22 Sep 2021 11:15:29 -0700 Subject: [PATCH 10/10] check the bin exist --- .github/workflows/ci.yml | 1 - integration-testing/http_client_test.py | 13 ++++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0f0396ec7..0b61da7a7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -86,7 +86,6 @@ jobs: - name: Build ${{ env.PACKAGE_NAME }} run: | aws s3 cp s3://aws-crt-test-stuff/ci/${{ env.BUILDER_VERSION }}/linux-container-ci.sh ./linux-container-ci.sh && chmod a+x ./linux-container-ci.sh - export BYO_CRYPTO=ON ./linux-container-ci.sh ${{ env.BUILDER_VERSION }} aws-crt-${{ env.LINUX_BASE_IMAGE }} build -p ${{ env.PACKAGE_NAME }} --cmake-extra=-DBYO_CRYPTO=ON downstream windows: diff --git a/integration-testing/http_client_test.py b/integration-testing/http_client_test.py index 38469d66f..5ba8f45bd 100644 --- a/integration-testing/http_client_test.py +++ b/integration-testing/http_client_test.py @@ -5,20 +5,23 @@ import sys import urllib.request import unittest -import os +import os.path TIMEOUT = 100 -if os.getenv("BYO_CRYPTO") is not None: - print('BYO_CRYPTO, not running integration test') - sys.exit(0) - # Accepting multiple args so we can pass something like: python elasticurl.py elasticurl_cmd_prefix = sys.argv[1:] if not elasticurl_cmd_prefix: print('You must pass the elasticurl cmd prefix') sys.exit(-1) +program_to_run = elasticurl_cmd_prefix[0] + +if 'bin' in program_to_run: + if not os.path.exists(program_to_run): + print('the program_to_run is not found, skip integration test') + sys.exit(0) + # Remove args from sys.argv so that unittest doesn't also try to parse them. sys.argv = sys.argv[:1]