From 2d672111835e5adc4b64185ff295786813c26a12 Mon Sep 17 00:00:00 2001 From: yhirose Date: Thu, 14 May 2020 18:25:18 -0400 Subject: [PATCH] Added more unit tests for the simple interface --- test/test.cc | 78 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 30 deletions(-) diff --git a/test/test.cc b/test/test.cc index 2a0dfbc..c6ee24c 100644 --- a/test/test.cc +++ b/test/test.cc @@ -651,19 +651,6 @@ TEST(YahooRedirectTest, Redirect) { EXPECT_EQ(200, res->status); } -TEST(YahooRedirectTest2, Redirect) { - httplib::Client2 cli("http://yahoo.com"); - - auto res = cli.Get("/"); - ASSERT_TRUE(res != nullptr); - EXPECT_EQ(301, res->status); - - cli.set_follow_location(true); - res = cli.Get("/"); - ASSERT_TRUE(res != nullptr); - EXPECT_EQ(200, res->status); -} - TEST(HttpsToHttpRedirectTest, Redirect) { httplib::SSLClient cli("httpbin.org"); cli.set_follow_location(true); @@ -673,16 +660,6 @@ TEST(HttpsToHttpRedirectTest, Redirect) { EXPECT_EQ(200, res->status); } -TEST(HttpsToHttpRedirectTest2, Redirect) { - auto res = - httplib::Client2("https://httpbin.org") - .set_follow_location(true) - .Get("/redirect-to?url=http%3A%2F%2Fwww.google.com&status_code=302"); - - ASSERT_TRUE(res != nullptr); - EXPECT_EQ(200, res->status); -} - TEST(RedirectToDifferentPort, Redirect) { Server svr8080; Server svr8081; @@ -2887,13 +2864,6 @@ TEST(SSLClientServerTest, TrustDirOptional) { t.join(); } - -/* Cannot test this case as there is no external access to SSL object to check -SSL_get_peer_certificate() == NULL TEST(SSLClientServerTest, -ClientCAPathRequired) { SSLServer svr(SERVER_CERT_FILE, SERVER_PRIVATE_KEY_FILE, -nullptr, CLIENT_CA_CERT_DIR); -} -*/ #endif #ifdef _WIN32 @@ -2902,3 +2872,51 @@ TEST(CleanupTest, WSACleanup) { ASSERT_EQ(0, ret); } #endif + +#ifdef CPPHTTPLIB_OPENSSL_SUPPORT +TEST(InvalidScheme, SimpleInterface) { + httplib::Client2 cli("scheme://yahoo.com"); + ASSERT_FALSE(cli.is_valid()); +} + +TEST(NoScheme, SimpleInterface) { + httplib::Client2 cli("yahoo.com"); + ASSERT_FALSE(cli.is_valid()); +} + +TEST(YahooRedirectTest2, SimpleInterface) { + httplib::Client2 cli("http://yahoo.com"); + + auto res = cli.Get("/"); + ASSERT_TRUE(res != nullptr); + EXPECT_EQ(301, res->status); + + cli.set_follow_location(true); + res = cli.Get("/"); + ASSERT_TRUE(res != nullptr); + EXPECT_EQ(200, res->status); +} + +TEST(YahooRedirectTest3, SimpleInterface) { + httplib::Client2 cli("https://yahoo.com"); + + auto res = cli.Get("/"); + ASSERT_TRUE(res != nullptr); + EXPECT_EQ(301, res->status); + + cli.set_follow_location(true); + res = cli.Get("/"); + ASSERT_TRUE(res != nullptr); + EXPECT_EQ(200, res->status); +} + +TEST(HttpsToHttpRedirectTest2, SimpleInterface) { + auto res = + httplib::Client2("https://httpbin.org") + .set_follow_location(true) + .Get("/redirect-to?url=http%3A%2F%2Fwww.google.com&status_code=302"); + + ASSERT_TRUE(res != nullptr); + EXPECT_EQ(200, res->status); +} +#endif