Skip to content

Commit

Permalink
Updated no_proxy test
Browse files Browse the repository at this point in the history
  • Loading branch information
gregory-shklover committed Oct 22, 2024
1 parent 6c645c7 commit c8fb3e8
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/proxy_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <gtest/gtest.h>

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

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


using namespace cpr;

TEST(ProxyTests, SingleProxyTest) {
Expand Down Expand Up @@ -81,6 +87,7 @@ TEST(ProxyTests, ReferenceProxySessionTest) {
Session session;
session.SetUrl(url);
session.SetProxies(proxies);
session.SetTimeout(std::chrono::seconds(10));
Response response = session.Get();
EXPECT_EQ(url, response.url);
EXPECT_EQ(std::string{"application/json"}, response.header["content-type"]);
Expand All @@ -96,6 +103,7 @@ TEST(ProxyTests, NoProxyTest) {
Session session;
session.SetUrl(url);
session.SetProxies(proxies);
session.SetTimeout(std::chrono::seconds(10));
Response response = session.Get();
EXPECT_EQ(url, response.url);
EXPECT_EQ(std::string{"application/json"}, response.header["content-type"]);
Expand All @@ -104,6 +112,11 @@ TEST(ProxyTests, NoProxyTest) {

// check that access was performed through the proxy
std::string proxy_ip = HTTP_PROXY;
if (proxy_ip[0] == 'h') {
// drop protocol:
proxy_ip = proxy_ip.substr(proxy_ip.find(':') + 3);
}
// drop port:
proxy_ip = proxy_ip.substr(0, proxy_ip.find(':'));

// find "origin": "ip" in response:
Expand Down

0 comments on commit c8fb3e8

Please sign in to comment.