Browse Source

Switch to hghttp2.org/httpbin for redirect test. (#538)

yhirose 5 years ago
parent
commit
b9641048fc
2 changed files with 43 additions and 51 deletions
  1. 16 21
      test/test.cc
  2. 27 30
      test/test_proxy.cc

+ 16 - 21
test/test.cc

@@ -718,9 +718,8 @@ TEST(DigestAuthTest, FromHTTPWatch) {
 }
 }
 #endif
 #endif
 
 
-#if 0
 TEST(AbsoluteRedirectTest, Redirect) {
 TEST(AbsoluteRedirectTest, Redirect) {
-  auto host = "httpbin.org";
+  auto host = "nghttp2.org";
 
 
 #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
 #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
   SSLClient cli(host);
   SSLClient cli(host);
@@ -729,13 +728,13 @@ TEST(AbsoluteRedirectTest, Redirect) {
 #endif
 #endif
 
 
   cli.set_follow_location(true);
   cli.set_follow_location(true);
-  auto res = cli.Get("/absolute-redirect/3");
+  auto res = cli.Get("/httpbin/absolute-redirect/3");
   ASSERT_TRUE(res);
   ASSERT_TRUE(res);
   EXPECT_EQ(200, res->status);
   EXPECT_EQ(200, res->status);
 }
 }
 
 
 TEST(RedirectTest, Redirect) {
 TEST(RedirectTest, Redirect) {
-  auto host = "httpbin.org";
+  auto host = "nghttp2.org";
 
 
 #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
 #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
   SSLClient cli(host);
   SSLClient cli(host);
@@ -744,13 +743,13 @@ TEST(RedirectTest, Redirect) {
 #endif
 #endif
 
 
   cli.set_follow_location(true);
   cli.set_follow_location(true);
-  auto res = cli.Get("/redirect/3");
+  auto res = cli.Get("/httpbin/redirect/3");
   ASSERT_TRUE(res);
   ASSERT_TRUE(res);
   EXPECT_EQ(200, res->status);
   EXPECT_EQ(200, res->status);
 }
 }
 
 
 TEST(RelativeRedirectTest, Redirect) {
 TEST(RelativeRedirectTest, Redirect) {
-  auto host = "httpbin.org";
+  auto host = "nghttp2.org";
 
 
 #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
 #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
   SSLClient cli(host);
   SSLClient cli(host);
@@ -759,13 +758,13 @@ TEST(RelativeRedirectTest, Redirect) {
 #endif
 #endif
 
 
   cli.set_follow_location(true);
   cli.set_follow_location(true);
-  auto res = cli.Get("/relative-redirect/3");
+  auto res = cli.Get("/httpbin/relative-redirect/3");
   ASSERT_TRUE(res);
   ASSERT_TRUE(res);
   EXPECT_EQ(200, res->status);
   EXPECT_EQ(200, res->status);
 }
 }
 
 
 TEST(TooManyRedirectTest, Redirect) {
 TEST(TooManyRedirectTest, Redirect) {
-  auto host = "httpbin.org";
+  auto host = "nghttp2.org";
 
 
 #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
 #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
   SSLClient cli(host);
   SSLClient cli(host);
@@ -774,11 +773,10 @@ TEST(TooManyRedirectTest, Redirect) {
 #endif
 #endif
 
 
   cli.set_follow_location(true);
   cli.set_follow_location(true);
-  auto res = cli.Get("/redirect/21");
+  auto res = cli.Get("/httpbin/redirect/21");
   ASSERT_TRUE(!res);
   ASSERT_TRUE(!res);
   EXPECT_EQ(Error::ExceedRedirectCount, res.error());
   EXPECT_EQ(Error::ExceedRedirectCount, res.error());
 }
 }
-#endif
 
 
 #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
 #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
 TEST(YahooRedirectTest, Redirect) {
 TEST(YahooRedirectTest, Redirect) {
@@ -795,16 +793,14 @@ TEST(YahooRedirectTest, Redirect) {
   EXPECT_EQ("https://yahoo.com/", res->location);
   EXPECT_EQ("https://yahoo.com/", res->location);
 }
 }
 
 
-#if 0
 TEST(HttpsToHttpRedirectTest, Redirect) {
 TEST(HttpsToHttpRedirectTest, Redirect) {
-  SSLClient cli("httpbin.org");
+  SSLClient cli("nghttp2.org");
   cli.set_follow_location(true);
   cli.set_follow_location(true);
-  auto res =
-      cli.Get("/redirect-to?url=http%3A%2F%2Fwww.google.com&status_code=302");
+  auto res = cli.Get(
+      "/httpbin/redirect-to?url=http%3A%2F%2Fwww.google.com&status_code=302");
   ASSERT_TRUE(res);
   ASSERT_TRUE(res);
   EXPECT_EQ(200, res->status);
   EXPECT_EQ(200, res->status);
 }
 }
-#endif
 
 
 TEST(RedirectToDifferentPort, Redirect) {
 TEST(RedirectToDifferentPort, Redirect) {
   Server svr8080;
   Server svr8080;
@@ -3756,15 +3752,14 @@ TEST(DecodeWithChunkedEncoding, BrotliEncoding) {
 }
 }
 #endif
 #endif
 
 
-#if 0
 TEST(HttpsToHttpRedirectTest2, SimpleInterface) {
 TEST(HttpsToHttpRedirectTest2, SimpleInterface) {
-  auto res =
-      Client("https://httpbin.org")
-          .set_follow_location(true)
-          .Get("/redirect-to?url=http%3A%2F%2Fwww.google.com&status_code=302");
+  Client cli("https://nghttp2.org");
+  cli.set_follow_location(true);
+  auto res = cli.Get(
+      "/httpbin/"
+      "redirect-to?url=http%3A%2F%2Fwww.google.com&status_code=302");
 
 
   ASSERT_TRUE(res);
   ASSERT_TRUE(res);
   EXPECT_EQ(200, res->status);
   EXPECT_EQ(200, res->status);
 }
 }
 #endif
 #endif
-#endif

+ 27 - 30
test/test_proxy.cc

@@ -8,29 +8,29 @@ using namespace httplib;
 template <typename T>
 template <typename T>
 void ProxyTest(T& cli, bool basic) {
 void ProxyTest(T& cli, bool basic) {
   cli.set_proxy("localhost", basic ? 3128 : 3129);
   cli.set_proxy("localhost", basic ? 3128 : 3129);
-  auto res = cli.Get("/get");
+  auto res = cli.Get("/httpbin/get");
   ASSERT_TRUE(res != nullptr);
   ASSERT_TRUE(res != nullptr);
   EXPECT_EQ(407, res->status);
   EXPECT_EQ(407, res->status);
 }
 }
 
 
 TEST(ProxyTest, NoSSLBasic) {
 TEST(ProxyTest, NoSSLBasic) {
-  Client cli("httpbin.org");
+  Client cli("nghttp2.org");
   ProxyTest(cli, true);
   ProxyTest(cli, true);
 }
 }
 
 
 #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
 #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
 TEST(ProxyTest, SSLBasic) {
 TEST(ProxyTest, SSLBasic) {
-  SSLClient cli("httpbin.org");
+  SSLClient cli("nghttp2.org");
   ProxyTest(cli, true);
   ProxyTest(cli, true);
 }
 }
 
 
 TEST(ProxyTest, NoSSLDigest) {
 TEST(ProxyTest, NoSSLDigest) {
-  Client cli("httpbin.org");
+  Client cli("nghttp2.org");
   ProxyTest(cli, false);
   ProxyTest(cli, false);
 }
 }
 
 
 TEST(ProxyTest, SSLDigest) {
 TEST(ProxyTest, SSLDigest) {
-  SSLClient cli("httpbin.org");
+  SSLClient cli("nghttp2.org");
   ProxyTest(cli, false);
   ProxyTest(cli, false);
 }
 }
 #endif
 #endif
@@ -54,29 +54,27 @@ void RedirectProxyText(T& cli, const char *path, bool basic) {
   EXPECT_EQ(200, res->status);
   EXPECT_EQ(200, res->status);
 }
 }
 
 
-#if 0
 TEST(RedirectTest, HTTPBinNoSSLBasic) {
 TEST(RedirectTest, HTTPBinNoSSLBasic) {
-  Client cli("httpbin.org");
-  RedirectProxyText(cli, "/redirect/2", true);
+  Client cli("nghttp2.org");
+  RedirectProxyText(cli, "/httpbin/redirect/2", true);
 }
 }
 
 
 #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
 #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
 TEST(RedirectTest, HTTPBinNoSSLDigest) {
 TEST(RedirectTest, HTTPBinNoSSLDigest) {
-  Client cli("httpbin.org");
-  RedirectProxyText(cli, "/redirect/2", false);
+  Client cli("nghttp2.org");
+  RedirectProxyText(cli, "/httpbin/redirect/2", false);
 }
 }
 
 
 TEST(RedirectTest, HTTPBinSSLBasic) {
 TEST(RedirectTest, HTTPBinSSLBasic) {
-  SSLClient cli("httpbin.org");
-  RedirectProxyText(cli, "/redirect/2", true);
+  SSLClient cli("nghttp2.org");
+  RedirectProxyText(cli, "/httpbin/redirect/2", true);
 }
 }
 
 
 TEST(RedirectTest, HTTPBinSSLDigest) {
 TEST(RedirectTest, HTTPBinSSLDigest) {
-  SSLClient cli("httpbin.org");
-  RedirectProxyText(cli, "/redirect/2", false);
+  SSLClient cli("nghttp2.org");
+  RedirectProxyText(cli, "/httpbin/redirect/2", false);
 }
 }
 #endif
 #endif
-#endif
 
 
 #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
 #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
 TEST(RedirectTest, YouTubeNoSSLBasic) {
 TEST(RedirectTest, YouTubeNoSSLBasic) {
@@ -218,7 +216,8 @@ TEST(DigestAuthTest, NoSSL) {
 
 
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 
 
-void KeepAliveTest(Client& cli, bool basic) {
+template <typename T>
+void KeepAliveTest(T& cli, 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");
@@ -234,20 +233,20 @@ void KeepAliveTest(Client& cli, bool basic) {
 #endif
 #endif
 
 
   {
   {
-    auto res = cli.Get("/get");
+    auto res = cli.Get("/httpbin/get");
     EXPECT_EQ(200, res->status);
     EXPECT_EQ(200, res->status);
   }
   }
   {
   {
-    auto res = cli.Get("/redirect/2");
+    auto res = cli.Get("/httpbin/redirect/2");
     EXPECT_EQ(200, res->status);
     EXPECT_EQ(200, res->status);
   }
   }
 
 
   {
   {
     std::vector<std::string> paths = {
     std::vector<std::string> paths = {
-        "/digest-auth/auth/hello/world/MD5",
-        "/digest-auth/auth/hello/world/SHA-256",
-        "/digest-auth/auth/hello/world/SHA-512",
-        "/digest-auth/auth-int/hello/world/MD5",
+        "/httpbin/digest-auth/auth/hello/world/MD5",
+        "/httpbin/digest-auth/auth/hello/world/SHA-256",
+        "/httpbin/digest-auth/auth/hello/world/SHA-512",
+        "/httpbin/digest-auth/auth-int/hello/world/MD5",
     };
     };
 
 
     for (auto path: paths) {
     for (auto path: paths) {
@@ -258,34 +257,32 @@ void KeepAliveTest(Client& cli, bool basic) {
   }
   }
 
 
   {
   {
-    int count = 100;
+    int count = 10;
     while (count--) {
     while (count--) {
-      auto res = cli.Get("/get");
+      auto res = cli.Get("/httpbin/get");
       EXPECT_EQ(200, res->status);
       EXPECT_EQ(200, res->status);
     }
     }
   }
   }
 }
 }
 
 
-#if 0
 #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
 #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
 TEST(KeepAliveTest, NoSSLWithBasic) {
 TEST(KeepAliveTest, NoSSLWithBasic) {
-  Client cli("httpbin.org");
+  Client cli("nghttp2.org");
   KeepAliveTest(cli, true);
   KeepAliveTest(cli, true);
 }
 }
 
 
 TEST(KeepAliveTest, SSLWithBasic) {
 TEST(KeepAliveTest, SSLWithBasic) {
-  SSLClient cli("httpbin.org");
+  SSLClient cli("nghttp2.org");
   KeepAliveTest(cli, true);
   KeepAliveTest(cli, true);
 }
 }
 
 
 TEST(KeepAliveTest, NoSSLWithDigest) {
 TEST(KeepAliveTest, NoSSLWithDigest) {
-  Client cli("httpbin.org");
+  Client cli("nghttp2.org");
   KeepAliveTest(cli, false);
   KeepAliveTest(cli, false);
 }
 }
 
 
 TEST(KeepAliveTest, SSLWithDigest) {
 TEST(KeepAliveTest, SSLWithDigest) {
-  SSLClient cli("httpbin.org");
+  SSLClient cli("nghttp2.org");
   KeepAliveTest(cli, false);
   KeepAliveTest(cli, false);
 }
 }
 #endif
 #endif
-#endif