From 62531d3df84f05407ebccf4d74b31ac4e72d44a4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 17 Aug 2024 01:58:01 +0200 Subject: [PATCH] Fix tests for response body after authentication It turns out different httpbin clones produce slightly different responses, so accept any of them. --- tests/net/webrequest.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/net/webrequest.cpp b/tests/net/webrequest.cpp index 2741c11484..a429266700 100644 --- a/tests/net/webrequest.cpp +++ b/tests/net/webrequest.cpp @@ -253,6 +253,12 @@ public: // default buffer size works correctly. constexpr int DOWNLOAD_BYTES = 99999; +// Substring used to check that we got the expected response after +// authenticating successfully. It is so weird because httpbin and go-httpbin +// use different strings for this: one uses "authenticated" while the other +// ones uses "authorized", so we use a substring common to both of them. +constexpr char AUTHORIZED_SUBSTRING[] = R"(ed": true)"; + TEST_CASE_METHOD(RequestFixture, "WebRequest::Get::Bytes", "[net][webrequest][get]") { @@ -480,7 +486,7 @@ TEST_CASE_METHOD(RequestFixture, const auto& response = request.GetResponse(); CHECK( response.GetStatus() == 200 ); CHECK_THAT( response.AsString().utf8_string(), - Catch::Contains(R"("authorized": true)") ); + Catch::Contains(AUTHORIZED_SUBSTRING) ); } SECTION("Bad password") @@ -511,7 +517,7 @@ TEST_CASE_METHOD(RequestFixture, const auto& response = request.GetResponse(); CHECK( response.GetStatus() == 200 ); CHECK_THAT( response.AsString().utf8_string(), - Catch::Contains(R"("authorized": true)") ); + Catch::Contains(AUTHORIZED_SUBSTRING) ); } SECTION("Bad password") @@ -537,7 +543,7 @@ TEST_CASE_METHOD(RequestFixture, const auto& response = request.GetResponse(); CHECK( response.GetStatus() == 200 ); CHECK_THAT( response.AsString().utf8_string(), - Catch::Contains(R"("authorized": true)") ); + Catch::Contains(AUTHORIZED_SUBSTRING) ); } TEST_CASE_METHOD(RequestFixture, @@ -554,7 +560,7 @@ TEST_CASE_METHOD(RequestFixture, const auto& response = request.GetResponse(); CHECK( response.GetStatus() == 200 ); CHECK_THAT( response.AsString().utf8_string(), - Catch::Contains(R"("authorized": true)") ); + Catch::Contains(AUTHORIZED_SUBSTRING) ); } TEST_CASE_METHOD(RequestFixture, @@ -885,7 +891,7 @@ TEST_CASE_METHOD(SyncRequestFixture, CHECK( state == wxWebRequest::State_Completed ); CHECK_THAT( response.AsString().utf8_string(), - Catch::Contains(R"("authorized": true)") ); + Catch::Contains(AUTHORIZED_SUBSTRING) ); } SECTION("Bad password") @@ -919,7 +925,7 @@ TEST_CASE_METHOD(SyncRequestFixture, CHECK( state == wxWebRequest::State_Completed ); CHECK_THAT( response.AsString().utf8_string(), - Catch::Contains(R"("authorized": true)") ); + Catch::Contains(AUTHORIZED_SUBSTRING) ); } SECTION("Bad password")