|
@@ -36,7 +36,7 @@ TEST(ProxyTest, SSLDigest) {
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-void RedirectTestHTTPBin(Client& cli, const char *path, bool basic) {
|
|
|
|
|
|
|
+void RedirectProxyText(Client& cli, const char *path, bool basic) {
|
|
|
cli.set_proxy("localhost", basic ? 3128 : 3129);
|
|
cli.set_proxy("localhost", basic ? 3128 : 3129);
|
|
|
if (basic) {
|
|
if (basic) {
|
|
|
cli.set_proxy_basic_auth("hello", "world");
|
|
cli.set_proxy_basic_auth("hello", "world");
|
|
@@ -52,45 +52,45 @@ void RedirectTestHTTPBin(Client& cli, const char *path, bool basic) {
|
|
|
|
|
|
|
|
TEST(RedirectTest, HTTPBinNoSSLBasic) {
|
|
TEST(RedirectTest, HTTPBinNoSSLBasic) {
|
|
|
Client cli("httpbin.org");
|
|
Client cli("httpbin.org");
|
|
|
- RedirectTestHTTPBin(cli, "/redirect/2", true);
|
|
|
|
|
|
|
+ RedirectProxyText(cli, "/redirect/2", true);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
TEST(RedirectTest, HTTPBinNoSSLDigest) {
|
|
TEST(RedirectTest, HTTPBinNoSSLDigest) {
|
|
|
Client cli("httpbin.org");
|
|
Client cli("httpbin.org");
|
|
|
- RedirectTestHTTPBin(cli, "/redirect/2", false);
|
|
|
|
|
|
|
+ RedirectProxyText(cli, "/redirect/2", false);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
|
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
|
|
TEST(RedirectTest, HTTPBinSSLBasic) {
|
|
TEST(RedirectTest, HTTPBinSSLBasic) {
|
|
|
SSLClient cli("httpbin.org");
|
|
SSLClient cli("httpbin.org");
|
|
|
- RedirectTestHTTPBin(cli, "/redirect/2", true);
|
|
|
|
|
|
|
+ RedirectProxyText(cli, "/redirect/2", true);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
TEST(RedirectTest, HTTPBinSSLDigest) {
|
|
TEST(RedirectTest, HTTPBinSSLDigest) {
|
|
|
SSLClient cli("httpbin.org");
|
|
SSLClient cli("httpbin.org");
|
|
|
- RedirectTestHTTPBin(cli, "/redirect/2", false);
|
|
|
|
|
|
|
+ RedirectProxyText(cli, "/redirect/2", false);
|
|
|
}
|
|
}
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
|
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
|
|
TEST(RedirectTest, YouTubeNoSSLBasic) {
|
|
TEST(RedirectTest, YouTubeNoSSLBasic) {
|
|
|
Client cli("youtube.com");
|
|
Client cli("youtube.com");
|
|
|
- RedirectTestHTTPBin(cli, "/", true);
|
|
|
|
|
|
|
+ RedirectProxyText(cli, "/", true);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
TEST(RedirectTest, YouTubeNoSSLDigest) {
|
|
TEST(RedirectTest, YouTubeNoSSLDigest) {
|
|
|
Client cli("youtube.com");
|
|
Client cli("youtube.com");
|
|
|
- RedirectTestHTTPBin(cli, "/", false);
|
|
|
|
|
|
|
+ RedirectProxyText(cli, "/", false);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
TEST(RedirectTest, YouTubeSSLBasic) {
|
|
TEST(RedirectTest, YouTubeSSLBasic) {
|
|
|
SSLClient cli("youtube.com");
|
|
SSLClient cli("youtube.com");
|
|
|
- RedirectTestHTTPBin(cli, "/", true);
|
|
|
|
|
|
|
+ RedirectProxyText(cli, "/", true);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
TEST(RedirectTest, YouTubeSSLDigest) {
|
|
TEST(RedirectTest, YouTubeSSLDigest) {
|
|
|
SSLClient cli("youtube.com");
|
|
SSLClient cli("youtube.com");
|
|
|
- RedirectTestHTTPBin(cli, "/", false);
|
|
|
|
|
|
|
+ RedirectProxyText(cli, "/", false);
|
|
|
}
|
|
}
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
@@ -111,8 +111,7 @@ void BaseAuthTestFromHTTPWatch(Client& cli) {
|
|
|
cli.Get("/basic-auth/hello/world",
|
|
cli.Get("/basic-auth/hello/world",
|
|
|
{make_basic_authentication_header("hello", "world")});
|
|
{make_basic_authentication_header("hello", "world")});
|
|
|
ASSERT_TRUE(res != nullptr);
|
|
ASSERT_TRUE(res != nullptr);
|
|
|
- EXPECT_EQ(res->body,
|
|
|
|
|
- "{\n \"authenticated\": true, \n \"user\": \"hello\"\n}\n");
|
|
|
|
|
|
|
+ EXPECT_EQ("{\n \"authenticated\": true, \n \"user\": \"hello\"\n}\n", res->body);
|
|
|
EXPECT_EQ(200, res->status);
|
|
EXPECT_EQ(200, res->status);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -120,8 +119,7 @@ void BaseAuthTestFromHTTPWatch(Client& cli) {
|
|
|
cli.set_basic_auth("hello", "world");
|
|
cli.set_basic_auth("hello", "world");
|
|
|
auto res = cli.Get("/basic-auth/hello/world");
|
|
auto res = cli.Get("/basic-auth/hello/world");
|
|
|
ASSERT_TRUE(res != nullptr);
|
|
ASSERT_TRUE(res != nullptr);
|
|
|
- EXPECT_EQ(res->body,
|
|
|
|
|
- "{\n \"authenticated\": true, \n \"user\": \"hello\"\n}\n");
|
|
|
|
|
|
|
+ EXPECT_EQ("{\n \"authenticated\": true, \n \"user\": \"hello\"\n}\n", res->body);
|
|
|
EXPECT_EQ(200, res->status);
|
|
EXPECT_EQ(200, res->status);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -150,6 +148,7 @@ TEST(BaseAuthTest, SSL) {
|
|
|
SSLClient cli("httpbin.org");
|
|
SSLClient cli("httpbin.org");
|
|
|
BaseAuthTestFromHTTPWatch(cli);
|
|
BaseAuthTestFromHTTPWatch(cli);
|
|
|
}
|
|
}
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
@@ -169,7 +168,6 @@ void DigestAuthTestFromHTTPWatch(Client& cli) {
|
|
|
"/digest-auth/auth/hello/world/MD5",
|
|
"/digest-auth/auth/hello/world/MD5",
|
|
|
"/digest-auth/auth/hello/world/SHA-256",
|
|
"/digest-auth/auth/hello/world/SHA-256",
|
|
|
"/digest-auth/auth/hello/world/SHA-512",
|
|
"/digest-auth/auth/hello/world/SHA-512",
|
|
|
- "/digest-auth/auth-init/hello/world/MD5",
|
|
|
|
|
"/digest-auth/auth-int/hello/world/MD5",
|
|
"/digest-auth/auth-int/hello/world/MD5",
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -177,8 +175,7 @@ void DigestAuthTestFromHTTPWatch(Client& cli) {
|
|
|
for (auto path : paths) {
|
|
for (auto path : paths) {
|
|
|
auto res = cli.Get(path.c_str());
|
|
auto res = cli.Get(path.c_str());
|
|
|
ASSERT_TRUE(res != nullptr);
|
|
ASSERT_TRUE(res != nullptr);
|
|
|
- EXPECT_EQ(res->body,
|
|
|
|
|
- "{\n \"authenticated\": true, \n \"user\": \"hello\"\n}\n");
|
|
|
|
|
|
|
+ EXPECT_EQ("{\n \"authenticated\": true, \n \"user\": \"hello\"\n}\n", res->body);
|
|
|
EXPECT_EQ(200, res->status);
|
|
EXPECT_EQ(200, res->status);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -197,7 +194,6 @@ void DigestAuthTestFromHTTPWatch(Client& cli) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-#endif
|
|
|
|
|
|
|
|
|
|
TEST(DigestAuthTest, SSL) {
|
|
TEST(DigestAuthTest, SSL) {
|
|
|
SSLClient cli("httpbin.org");
|
|
SSLClient cli("httpbin.org");
|
|
@@ -209,3 +205,83 @@ TEST(DigestAuthTest, NoSSL) {
|
|
|
DigestAuthTestFromHTTPWatch(cli);
|
|
DigestAuthTestFromHTTPWatch(cli);
|
|
|
}
|
|
}
|
|
|
#endif
|
|
#endif
|
|
|
|
|
+
|
|
|
|
|
+// ----------------------------------------------------------------------------
|
|
|
|
|
+
|
|
|
|
|
+#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
|
|
|
|
+TEST(KeepAliveText, NoSSLWithDigest) {
|
|
|
|
|
+ Client cli("httpbin.org");
|
|
|
|
|
+ cli.set_keep_alive_max_count(4);
|
|
|
|
|
+ cli.set_follow_location(true);
|
|
|
|
|
+ cli.set_digest_auth("hello", "world");
|
|
|
|
|
+ cli.set_proxy("localhost", 3129);
|
|
|
|
|
+ cli.set_proxy_digest_auth("hello", "world");
|
|
|
|
|
+
|
|
|
|
|
+ std::vector<Request> requests;
|
|
|
|
|
+
|
|
|
|
|
+ Get(requests, "/get");
|
|
|
|
|
+ Get(requests, "/redirect/2");
|
|
|
|
|
+ Get(requests, "/digest-auth/auth/hello/world/MD5");
|
|
|
|
|
+
|
|
|
|
|
+ std::vector<Response> responses;
|
|
|
|
|
+ auto ret = cli.send(requests, responses);
|
|
|
|
|
+ ASSERT_TRUE(ret == true);
|
|
|
|
|
+ ASSERT_TRUE(requests.size() == responses.size());
|
|
|
|
|
+
|
|
|
|
|
+ auto i = 0;
|
|
|
|
|
+
|
|
|
|
|
+ {
|
|
|
|
|
+ auto &res = responses[i++];
|
|
|
|
|
+ EXPECT_EQ(200, res.status);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ {
|
|
|
|
|
+ auto &res = responses[i++];
|
|
|
|
|
+ EXPECT_EQ(200, res.status);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ {
|
|
|
|
|
+ auto &res = responses[i++];
|
|
|
|
|
+ EXPECT_EQ("{\n \"authenticated\": true, \n \"user\": \"hello\"\n}\n", res.body);
|
|
|
|
|
+ EXPECT_EQ(200, res.status);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+TEST(KeepAliveText, SSLWithDigest) {
|
|
|
|
|
+ SSLClient cli("httpbin.org");
|
|
|
|
|
+ cli.set_keep_alive_max_count(4);
|
|
|
|
|
+ cli.set_follow_location(true);
|
|
|
|
|
+ cli.set_digest_auth("hello", "world");
|
|
|
|
|
+ cli.set_proxy("localhost", 3129);
|
|
|
|
|
+ cli.set_proxy_digest_auth("hello", "world");
|
|
|
|
|
+
|
|
|
|
|
+ std::vector<Request> requests;
|
|
|
|
|
+
|
|
|
|
|
+ Get(requests, "/get");
|
|
|
|
|
+ Get(requests, "/redirect/2");
|
|
|
|
|
+ Get(requests, "/digest-auth/auth/hello/world/MD5");
|
|
|
|
|
+
|
|
|
|
|
+ std::vector<Response> responses;
|
|
|
|
|
+ auto ret = cli.send(requests, responses);
|
|
|
|
|
+ ASSERT_TRUE(ret == true);
|
|
|
|
|
+ ASSERT_TRUE(requests.size() == responses.size());
|
|
|
|
|
+
|
|
|
|
|
+ auto i = 0;
|
|
|
|
|
+
|
|
|
|
|
+ {
|
|
|
|
|
+ auto &res = responses[i++];
|
|
|
|
|
+ EXPECT_EQ(200, res.status);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ {
|
|
|
|
|
+ auto &res = responses[i++];
|
|
|
|
|
+ EXPECT_EQ(200, res.status);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ {
|
|
|
|
|
+ auto &res = responses[i++];
|
|
|
|
|
+ EXPECT_EQ("{\n \"authenticated\": true, \n \"user\": \"hello\"\n}\n", res.body);
|
|
|
|
|
+ EXPECT_EQ(200, res.status);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+#endif
|