Skip to content

Commit c8fb3e8

Browse files
Updated no_proxy test
1 parent 6c645c7 commit c8fb3e8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

test/proxy_tests.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <gtest/gtest.h>
22

3+
#include <chrono>
34
#include <stdlib.h>
45
#include <string>
56
#include <sstream>
@@ -9,9 +10,14 @@
910
// TODO: This uses public servers for proxies and endpoints. This should be replaced with a source
1011
// code implementation inside server.cpp
1112

13+
// NOTES:
14+
// * For no-proxy testing need to run the tests with direct connection to the internet
15+
// * List of free proxies for testing can be found at https://proxy-list.org/english/index.php
16+
// Example: #define HTTP_PROXY "http://162.223.90.130:80"
1217
#define HTTP_PROXY "51.159.4.98:80"
1318
#define HTTPS_PROXY "51.104.53.182:8000"
1419

20+
1521
using namespace cpr;
1622

1723
TEST(ProxyTests, SingleProxyTest) {
@@ -81,6 +87,7 @@ TEST(ProxyTests, ReferenceProxySessionTest) {
8187
Session session;
8288
session.SetUrl(url);
8389
session.SetProxies(proxies);
90+
session.SetTimeout(std::chrono::seconds(10));
8491
Response response = session.Get();
8592
EXPECT_EQ(url, response.url);
8693
EXPECT_EQ(std::string{"application/json"}, response.header["content-type"]);
@@ -96,6 +103,7 @@ TEST(ProxyTests, NoProxyTest) {
96103
Session session;
97104
session.SetUrl(url);
98105
session.SetProxies(proxies);
106+
session.SetTimeout(std::chrono::seconds(10));
99107
Response response = session.Get();
100108
EXPECT_EQ(url, response.url);
101109
EXPECT_EQ(std::string{"application/json"}, response.header["content-type"]);
@@ -104,6 +112,11 @@ TEST(ProxyTests, NoProxyTest) {
104112

105113
// check that access was performed through the proxy
106114
std::string proxy_ip = HTTP_PROXY;
115+
if (proxy_ip[0] == 'h') {
116+
// drop protocol:
117+
proxy_ip = proxy_ip.substr(proxy_ip.find(':') + 3);
118+
}
119+
// drop port:
107120
proxy_ip = proxy_ip.substr(0, proxy_ip.find(':'));
108121

109122
// find "origin": "ip" in response:

0 commit comments

Comments
 (0)