update 3rd party httpbin server for inhouse instance (#1935)

* update 3rd party httpbin server for inhouse instance
This commit is contained in:
Victor Vazquez 2021-03-31 16:35:03 -07:00 committed by GitHub
parent ddd7a093f4
commit bae16450c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 112 additions and 44 deletions

View File

@ -114,3 +114,22 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
License notice for postmanlabs httpbin
-------------------------------------------------------------------
ISC License
Copyright (c) 2017 Kenneth Reitz.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

View File

@ -72,6 +72,16 @@
}
},
"DevelopmentDependency": true
},
{
"Component": {
"Type": "git",
"git": {
"RepositoryUrl": "https://github.com/postmanlabs/httpbin",
"CommitHash": "f8ec666b4d1b654e4ff6aedd356f510dcac09f83"
}
},
"DevelopmentDependency": true
}
]
}

View File

@ -36,8 +36,8 @@ namespace Azure { namespace Core { namespace Test {
// Use the same request for all connections.
Azure::Core::Http::Request req(
Azure::Core::Http::HttpMethod::Get, Azure::Core::Url("http://httpbin.org/get"));
std::string const expectedConnectionKey = "httpbin.org0011";
Azure::Core::Http::HttpMethod::Get, Azure::Core::Url(AzureSdkHttpbinServer::Get()));
std::string const expectedConnectionKey = AzureSdkHttpbinServer::Host() + "0011";
{
// Creating a new connection with default options
@ -85,15 +85,13 @@ namespace Azure { namespace Core { namespace Test {
EXPECT_EQ(values->second.begin()->get()->GetConnectionKey(), expectedConnectionKey);
// Now test that using a different connection config won't re-use the same connection
std::string const CAinfo = "someFakePath";
std::string const secondExpectedKey = "httpbin.org" + CAinfo + "011";
std::string const secondExpectedKey = AzureSdkHttpbinServer::Host() + "0010";
{
// Creating a new connection with default options
// Creating a new connection with options
Azure::Core::Http::CurlTransportOptions options;
options.CAInfo = CAinfo;
options.SSLVerifyPeer = false;
auto connection
= Azure::Core::Http::CurlConnectionPool::ExtractOrCreateCurlConnection(req, options);
EXPECT_EQ(connection->GetConnectionKey(), secondExpectedKey);
// One connection still in the pool after getting a new connection and with first expected
// key
@ -116,20 +114,18 @@ namespace Azure { namespace Core { namespace Test {
EXPECT_EQ(Azure::Core::Http::CurlConnectionPool::ConnectionPoolIndex.size(), 2);
values = Azure::Core::Http::CurlConnectionPool::ConnectionPoolIndex.begin();
EXPECT_EQ(values->second.size(), 1);
EXPECT_EQ(values->second.begin()->get()->GetConnectionKey(), expectedConnectionKey);
EXPECT_EQ(values->second.begin()->get()->GetConnectionKey(), secondExpectedKey);
values++;
EXPECT_EQ(values->second.size(), 1);
EXPECT_EQ(values->second.begin()->get()->GetConnectionKey(), secondExpectedKey);
EXPECT_EQ(values->second.begin()->get()->GetConnectionKey(), expectedConnectionKey);
// Test re-using same custom config
{
// Creating a new connection with default options
Azure::Core::Http::CurlTransportOptions options;
options.CAInfo = CAinfo;
auto connection
= Azure::Core::Http::CurlConnectionPool::ExtractOrCreateCurlConnection(req, options);
EXPECT_EQ(connection->GetConnectionKey(), secondExpectedKey);
EXPECT_EQ(connection->GetConnectionKey(), expectedConnectionKey);
// One connection still in the pool after getting a new connection and with first expected
// key
EXPECT_EQ(Azure::Core::Http::CurlConnectionPool::ConnectionPoolIndex.size(), 1);
@ -138,7 +134,7 @@ namespace Azure { namespace Core { namespace Test {
->second.begin()
->get()
->GetConnectionKey(),
expectedConnectionKey);
secondExpectedKey);
auto session = std::make_unique<Azure::Core::Http::CurlSession>(
req, std::move(connection), options.HttpKeepAlive);
@ -150,10 +146,10 @@ namespace Azure { namespace Core { namespace Test {
EXPECT_EQ(Azure::Core::Http::CurlConnectionPool::ConnectionPoolIndex.size(), 2);
values = Azure::Core::Http::CurlConnectionPool::ConnectionPoolIndex.begin();
EXPECT_EQ(values->second.size(), 1);
EXPECT_EQ(values->second.begin()->get()->GetConnectionKey(), expectedConnectionKey);
EXPECT_EQ(values->second.begin()->get()->GetConnectionKey(), secondExpectedKey);
values++;
EXPECT_EQ(values->second.size(), 1);
EXPECT_EQ(values->second.begin()->get()->GetConnectionKey(), secondExpectedKey);
EXPECT_EQ(values->second.begin()->get()->GetConnectionKey(), expectedConnectionKey);
#ifdef RUN_LONG_UNIT_TESTS
{
@ -183,7 +179,7 @@ namespace Azure { namespace Core { namespace Test {
TEST(CurlConnectionPool, resiliencyOnConnectionClosed)
{
Azure::Core::Http::Request req(
Azure::Core::Http::HttpMethod::Get, Azure::Core::Url("http://httpbin.org/get"));
Azure::Core::Http::HttpMethod::Get, Azure::Core::Url(AzureSdkHttpbinServer::Get()));
Azure::Core::Http::CurlTransportOptions options;
auto connection

View File

@ -17,6 +17,8 @@
#include <http/curl/curl_connection_private.hpp>
#include <http/curl/curl_session_private.hpp>
#include "transport_adapter_base.hpp"
#include <string>
#include <vector>
@ -41,7 +43,7 @@ namespace Azure { namespace Core { namespace Test {
policies.emplace_back(std::move(transportPolicy));
Azure::Core::Http::_internal::HttpPipeline pipeline(policies);
Azure::Core::Url url("http://httpbin.org/get");
Azure::Core::Url url(AzureSdkHttpbinServer::Get());
Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Get, url);
std::unique_ptr<Azure::Core::Http::RawResponse> response;
@ -72,7 +74,7 @@ namespace Azure { namespace Core { namespace Test {
policies.emplace_back(std::move(transportPolicy));
Azure::Core::Http::_internal::HttpPipeline pipeline(policies);
Azure::Core::Url url("https://httpbin.org/get");
Azure::Core::Url url(AzureSdkHttpbinServer::Get());
Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Get, url);
std::unique_ptr<Azure::Core::Http::RawResponse> response;
@ -106,7 +108,7 @@ namespace Azure { namespace Core { namespace Test {
policies.emplace_back(std::move(transportPolicy));
Azure::Core::Http::_internal::HttpPipeline pipeline(policies);
Azure::Core::Url url("https://httpbin.org/get");
Azure::Core::Url url(AzureSdkHttpbinServer::Get());
Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Get, url);
std::unique_ptr<Azure::Core::Http::RawResponse> response;
@ -132,7 +134,7 @@ namespace Azure { namespace Core { namespace Test {
policies.emplace_back(std::move(transportPolicy));
Azure::Core::Http::_internal::HttpPipeline pipeline(policies);
Azure::Core::Url url("https://httpbin.org/get");
Azure::Core::Url url(AzureSdkHttpbinServer::Get());
Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Get, url);
std::unique_ptr<Azure::Core::Http::RawResponse> response;
@ -158,7 +160,7 @@ namespace Azure { namespace Core { namespace Test {
policies.emplace_back(std::move(transportPolicy));
Azure::Core::Http::_internal::HttpPipeline pipeline(policies);
Azure::Core::Url url("https://httpbin.org/get");
Azure::Core::Url url(AzureSdkHttpbinServer::Get());
Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Get, url);
std::unique_ptr<Azure::Core::Http::RawResponse> response;
@ -190,7 +192,7 @@ namespace Azure { namespace Core { namespace Test {
Azure::Core::Http::_internal::HttpPipeline pipeline(policies);
// Use https
Azure::Core::Url url("https://httpbin.org/get");
Azure::Core::Url url(AzureSdkHttpbinServer::Get());
Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Get, url);
std::unique_ptr<Azure::Core::Http::RawResponse> response;
@ -222,7 +224,7 @@ namespace Azure { namespace Core { namespace Test {
Azure::Core::Http::_internal::HttpPipeline pipeline(policies);
// Use https
Azure::Core::Url url("https://httpbin.org/get");
Azure::Core::Url url(AzureSdkHttpbinServer::Get());
Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Get, url);
std::unique_ptr<Azure::Core::Http::RawResponse> response;
@ -259,7 +261,7 @@ namespace Azure { namespace Core { namespace Test {
policies.emplace_back(std::move(transportPolicy));
Azure::Core::Http::_internal::HttpPipeline pipeline(policies);
Azure::Core::Url url("http://httpbin.org/get");
Azure::Core::Url url(AzureSdkHttpbinServer::Get());
Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Get, url);
std::unique_ptr<Azure::Core::Http::RawResponse> response;

View File

@ -4,20 +4,31 @@
#include <gtest/gtest.h>
#if defined(BUILD_CURL_HTTP_TRANSPORT_ADAPTER)
#include <azure/core/platform.hpp>
#include <curl/curl.h>
#include <signal.h>
#endif
int main(int argc, char** argv)
{
#if defined(BUILD_CURL_HTTP_TRANSPORT_ADAPTER)
curl_global_init(CURL_GLOBAL_ALL);
#if defined(AZ_PLATFORM_POSIX)
// OpenSSL signals SIGPIPE when trying to clean an HTTPS closed connection.
// End users need to decide if SIGPIPE should be ignored or not.
signal(SIGPIPE, SIG_IGN);
#endif
#endif
testing::InitGoogleTest(&argc, argv);
auto r = RUN_ALL_TESTS();
#if defined(BUILD_CURL_HTTP_TRANSPORT_ADAPTER)
#if defined(AZ_PLATFORM_POSIX)
// Cleaning ssl connections on Windows is broken until
// https://github.com/Azure/azure-sdk-for-cpp/pull/1500 is merged.
curl_global_cleanup();
#endif
#endif
return r;
}

View File

@ -30,7 +30,7 @@ namespace Azure { namespace Core { namespace Test {
TEST_P(TransportAdapter, get)
{
Azure::Core::Url host("http://httpbin.org/get");
Azure::Core::Url host(AzureSdkHttpbinServer::Get());
auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Get, host);
auto response = m_pipeline->Send(request, Azure::Core::Context::GetApplicationContext());
@ -61,7 +61,7 @@ namespace Azure { namespace Core { namespace Test {
TEST_P(TransportAdapter, getLoop)
{
Azure::Core::Url host("http://httpbin.org/get");
Azure::Core::Url host(AzureSdkHttpbinServer::Get());
auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Get, host);
@ -77,7 +77,7 @@ namespace Azure { namespace Core { namespace Test {
TEST_P(TransportAdapter, head)
{
Azure::Core::Url host("http://httpbin.org/get");
Azure::Core::Url host(AzureSdkHttpbinServer::Get());
auto expectedResponseBodySize = 0;
auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Head, host);
@ -92,7 +92,7 @@ namespace Azure { namespace Core { namespace Test {
TEST_P(TransportAdapter, put)
{
Azure::Core::Url host("http://httpbin.org/put");
Azure::Core::Url host(AzureSdkHttpbinServer::Put());
// PUT 1K
auto requestBodyVector = std::vector<uint8_t>(1024, 'x');
@ -108,7 +108,7 @@ namespace Azure { namespace Core { namespace Test {
TEST_P(TransportAdapter, deleteRequest)
{
Azure::Core::Url host("http://httpbin.org/delete");
Azure::Core::Url host(AzureSdkHttpbinServer::Delete());
// Delete with 1k payload
auto requestBodyVector = std::vector<uint8_t>(1024, 'x');
@ -124,7 +124,7 @@ namespace Azure { namespace Core { namespace Test {
TEST_P(TransportAdapter, patch)
{
Azure::Core::Url host("http://httpbin.org/patch");
Azure::Core::Url host(AzureSdkHttpbinServer::Patch());
// Patch with 1kb payload
auto requestBodyVector = std::vector<uint8_t>(1024, 'x');
@ -158,7 +158,7 @@ namespace Azure { namespace Core { namespace Test {
TEST_P(TransportAdapter, putErrorResponse)
{
Azure::Core::Url host("http://httpbin.org/get");
Azure::Core::Url host(AzureSdkHttpbinServer::Get());
// Try to make a PUT to a GET url. This will return an error code from server.
// This test makes sure that the connection is not re-used (because it gets closed by server)
@ -179,7 +179,7 @@ namespace Azure { namespace Core { namespace Test {
TEST_P(TransportAdapter, getWithStream)
{
Azure::Core::Url host("http://httpbin.org/get");
Azure::Core::Url host(AzureSdkHttpbinServer::Get());
auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Get, host, true);
auto response = m_pipeline->Send(request, Azure::Core::Context::GetApplicationContext());
@ -198,7 +198,7 @@ namespace Azure { namespace Core { namespace Test {
TEST_P(TransportAdapter, getLoopWithStream)
{
Azure::Core::Url host("http://httpbin.org/get");
Azure::Core::Url host(AzureSdkHttpbinServer::Get());
auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Get, host, true);
@ -214,7 +214,7 @@ namespace Azure { namespace Core { namespace Test {
TEST_P(TransportAdapter, headWithStream)
{
Azure::Core::Url host("http://httpbin.org/get");
Azure::Core::Url host(AzureSdkHttpbinServer::Get());
auto expectedResponseBodySize = 0;
auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Head, host, true);
@ -229,7 +229,7 @@ namespace Azure { namespace Core { namespace Test {
TEST_P(TransportAdapter, putWithStream)
{
Azure::Core::Url host("http://httpbin.org/put");
Azure::Core::Url host(AzureSdkHttpbinServer::Put());
// PUT 1k
auto requestBodyVector = std::vector<uint8_t>(1024, 'x');
@ -245,7 +245,7 @@ namespace Azure { namespace Core { namespace Test {
TEST_P(TransportAdapter, deleteRequestWithStream)
{
Azure::Core::Url host("http://httpbin.org/delete");
Azure::Core::Url host(AzureSdkHttpbinServer::Delete());
// Delete with 1k payload
auto requestBodyVector = std::vector<uint8_t>(1024, 'x');
@ -261,7 +261,7 @@ namespace Azure { namespace Core { namespace Test {
TEST_P(TransportAdapter, patchWithStream)
{
Azure::Core::Url host("http://httpbin.org/patch");
Azure::Core::Url host(AzureSdkHttpbinServer::Patch());
// Patch with 1kb payload
auto requestBodyVector = std::vector<uint8_t>(1024, 'x');
@ -295,7 +295,7 @@ namespace Azure { namespace Core { namespace Test {
TEST_P(TransportAdapter, createResponseT)
{
Azure::Core::Url host("http://httpbin.org/get");
Azure::Core::Url host(AzureSdkHttpbinServer::Get());
std::string expectedType("This is the Response Type");
auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Get, host, false);
@ -321,7 +321,7 @@ namespace Azure { namespace Core { namespace Test {
TEST_P(TransportAdapter, customSizePut)
{
Azure::Core::Url host("http://httpbin.org/put");
Azure::Core::Url host(AzureSdkHttpbinServer::Put());
// PUT 1MB
auto requestBodyVector = std::vector<uint8_t>(1024 * 1024, 'x');
@ -341,7 +341,7 @@ namespace Azure { namespace Core { namespace Test {
TEST_P(TransportAdapter, putWithStreamOnFail)
{
// point to bad address pah to generate server MethodNotAllowed error
Azure::Core::Url host("http://httpbin.org/get");
Azure::Core::Url host(AzureSdkHttpbinServer::Get());
// PUT 1k
auto requestBodyVector = std::vector<uint8_t>(1024, 'x');
@ -358,7 +358,7 @@ namespace Azure { namespace Core { namespace Test {
TEST_P(TransportAdapter, cancelTransferUpload)
{
Azure::Core::Url host("http://httpbin.org/put");
Azure::Core::Url host(AzureSdkHttpbinServer::Put());
Azure::Core::Context cancelThis;
auto threadRoutine = [&]() {
@ -435,7 +435,7 @@ namespace Azure { namespace Core { namespace Test {
TEST_P(TransportAdapter, SizePutFromFile)
{
Azure::Core::Url host("http://httpbin.org/put");
Azure::Core::Url host(AzureSdkHttpbinServer::Put());
std::string testDataPath(AZURE_TEST_DATA_PATH);
#if defined(AZ_PLATFORM_POSIX)
@ -462,7 +462,7 @@ namespace Azure { namespace Core { namespace Test {
TEST_P(TransportAdapter, SizePutFromFileDefault)
{
Azure::Core::Url host("http://httpbin.org/put");
Azure::Core::Url host(AzureSdkHttpbinServer::Put());
std::string testDataPath(AZURE_TEST_DATA_PATH);
#if defined(AZ_PLATFORM_POSIX)
@ -488,7 +488,7 @@ namespace Azure { namespace Core { namespace Test {
TEST_P(TransportAdapter, SizePutFromFileBiggerPage)
{
Azure::Core::Url host("http://httpbin.org/put");
Azure::Core::Url host(AzureSdkHttpbinServer::Put());
std::string testDataPath(AZURE_TEST_DATA_PATH);
#if defined(AZ_PLATFORM_POSIX)

View File

@ -19,6 +19,36 @@
namespace Azure { namespace Core { namespace Test {
namespace _detail {
constexpr static const char AzureSdkHttpbinServerSchema[] = "https://";
constexpr static const char AzureSdkHttpbinServer[] = "azuresdkforcpp.azurewebsites.net";
} // namespace _detail
struct AzureSdkHttpbinServer
{
inline static std::string Get()
{
return std::string(_detail::AzureSdkHttpbinServerSchema)
+ std::string(_detail::AzureSdkHttpbinServer) + "/get";
}
inline static std::string Put()
{
return std::string(_detail::AzureSdkHttpbinServerSchema)
+ std::string(_detail::AzureSdkHttpbinServer) + "/put";
}
inline static std::string Delete()
{
return std::string(_detail::AzureSdkHttpbinServerSchema)
+ std::string(_detail::AzureSdkHttpbinServer) + "/delete";
}
inline static std::string Patch()
{
return std::string(_detail::AzureSdkHttpbinServerSchema)
+ std::string(_detail::AzureSdkHttpbinServer) + "/patch";
}
inline static std::string Host() { return std::string(_detail::AzureSdkHttpbinServer); }
};
struct TransportAdaptersTestParameter
{
std::string Suffix;