Files
@ f2a6ba12fc29
Branch filter:
Location: libtransport.git/3rdparty/cpprestsdk/tests/functional/http/client/proxy_tests.cpp
f2a6ba12fc29
4.2 KiB
text/x-c++hdr
Slack frontend stub
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | /***
* ==++==
*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ==--==
* =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
*
* proxy_tests.cpp
*
* Tests cases for using proxies with http_clients.
*
* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
****/
#include "stdafx.h"
using namespace web::http;
using namespace web::http::client;
using namespace tests::functional::http::utilities;
namespace tests { namespace functional { namespace http { namespace client {
SUITE(proxy_tests)
{
#ifndef __cplusplus_winrt
// IXHR2 does not allow the proxy settings to be changed
TEST_FIXTURE(uri_address, auto_discovery_proxy)
{
test_http_server::scoped_server scoped(m_uri);
scoped.server()->next_request().then([&](test_request *p_request)
{
http_asserts::assert_test_request_equals(p_request, methods::PUT, U("/"), U("text/plain"), U("this is a test"));
p_request->reply(200);
});
http_client_config config;
config.set_proxy(web_proxy::use_auto_discovery);
VERIFY_IS_FALSE(config.proxy().is_disabled());
VERIFY_IS_FALSE(config.proxy().is_specified());
http_client client(m_uri, config);
http_asserts::assert_response_equals(client.request(methods::PUT, U("/"), U("this is a test")).get(), status_codes::OK);
}
TEST_FIXTURE(uri_address, disabled_proxy)
{
test_http_server::scoped_server scoped(m_uri);
scoped.server()->next_request().then([&](test_request *p_request)
{
http_asserts::assert_test_request_equals(p_request, methods::PUT, U("/"), U("text/plain"), U("sample data"));
p_request->reply(status_codes::OK);
});
http_client_config config;
config.set_proxy(web_proxy(web_proxy::disabled));
VERIFY_IS_TRUE(config.proxy().is_disabled());
VERIFY_IS_FALSE(config.proxy().is_auto_discovery());
VERIFY_IS_FALSE(config.proxy().is_specified());
VERIFY_IS_FALSE(config.proxy().is_default());
http_client client(m_uri, config);
http_asserts::assert_response_equals(client.request(methods::PUT, U("/"), U("sample data")).get(), status_codes::OK);
}
#endif // __cplusplus_winrt
#ifdef __cplusplus_winrt
TEST_FIXTURE(uri_address, no_proxy_options_on_winrt)
{
http_client_config config;
config.set_proxy(web_proxy::use_auto_discovery);
http_client client(m_uri, config);
VERIFY_THROWS(client.request(methods::GET, U("/")).get(), http_exception);
}
#endif
#ifndef __cplusplus_winrt
// Can't specify a proxy with WinRT implementation.
TEST_FIXTURE(uri_address, proxy_with_credentials, "Ignore:Linux", "NYI", "Ignore:Apple", "NYI", "Ignore:Android", "NYI")
{
uri u(U("http://netproxy.redmond.corp.microsoft.com"));
web_proxy proxy(u);
VERIFY_IS_TRUE(proxy.is_specified());
VERIFY_ARE_EQUAL(u, proxy.address());
credentials cred(U("artur"), U("fred")); // relax, this is not my real password
proxy.set_credentials(cred);
http_client_config config;
config.set_proxy(proxy);
// Access to this server will succeed because the first request will not be challenged and hence
// my bogus credentials will not be supplied.
http_client client(U("http://www.microsoft.com"), config);
try
{
http_response response = client.request(methods::GET).get();
VERIFY_ARE_EQUAL(status_codes::OK, response.status_code());
response.content_ready().wait();
}
catch (web::http::http_exception const& e)
{
if (e.error_code().value() == 12007) {
// The above "netproxy.redmond.corp.microsoft.com" is an internal site not generally accessible.
// This will cause a failure to resolve the URL.
// This is ok.
return;
}
throw;
}
}
#endif
} // SUITE(proxy_tests)
}}}}
|