Skip to content

Commit 953bef6

Browse files
authored
Merge pull request #1166 from Jerry-Terrasse/master
fix: let bad-host-tests pass when there is DNS error redirection
2 parents 0e6bf15 + f1ba230 commit 953bef6

File tree

5 files changed

+11
-5
lines changed

5 files changed

+11
-5
lines changed

test/error_tests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ TEST(ErrorTests, ProxyFailure) {
7676
Response response = cpr::Get(url, cpr::Proxies{{"http", "http://bad_host.libcpr.org"}});
7777
EXPECT_EQ(url, response.url);
7878
EXPECT_EQ(0, response.status_code);
79-
EXPECT_EQ(ErrorCode::COULDNT_RESOLVE_PROXY, response.error.code);
79+
// Sometimes the DNS server returns a fake address instead of an NXDOMAIN response, leading to COULDNT_CONNECT.
80+
EXPECT_TRUE(response.error.code == ErrorCode::COULDNT_RESOLVE_PROXY || response.error.code == ErrorCode::COULDNT_CONNECT);
8081
}
8182

8283
TEST(ErrorTests, BoolFalseTest) {

test/get_tests.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <chrono>
2+
#include <cpr/error.h>
23
#include <gtest/gtest.h>
34

45
#include <memory>
@@ -112,7 +113,8 @@ TEST(BasicTests, BadHostTest) {
112113
EXPECT_EQ(std::string{}, response.text);
113114
EXPECT_EQ(url, response.url);
114115
EXPECT_EQ(0, response.status_code);
115-
EXPECT_EQ(ErrorCode::COULDNT_RESOLVE_HOST, response.error.code);
116+
// Sometimes the DNS server returns a fake address instead of an NXDOMAIN response, leading to COULDNT_CONNECT.
117+
EXPECT_TRUE(response.error.code == ErrorCode::COULDNT_RESOLVE_HOST || response.error.code == ErrorCode::COULDNT_CONNECT);
116118
}
117119

118120
TEST(CookiesTests, BasicCookiesTest) {

test/head_tests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ TEST(HeadTests, BadHostHeadTest) {
4747
EXPECT_EQ(std::string{}, response.text);
4848
EXPECT_EQ(url, response.url);
4949
EXPECT_EQ(0, response.status_code);
50-
EXPECT_EQ(ErrorCode::COULDNT_RESOLVE_HOST, response.error.code);
50+
// Sometimes the DNS server returns a fake address instead of an NXDOMAIN response, leading to COULDNT_CONNECT.
51+
EXPECT_TRUE(response.error.code == ErrorCode::COULDNT_RESOLVE_HOST || response.error.code == ErrorCode::COULDNT_CONNECT);
5152
}
5253

5354
TEST(HeadTests, CookieHeadTest) {

test/post_tests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ TEST(UrlEncodedPostTests, UrlPostBadHostTest) {
119119
EXPECT_EQ(url, response.url);
120120
EXPECT_EQ(std::string{}, response.header["content-type"]);
121121
EXPECT_EQ(0, response.status_code);
122-
EXPECT_EQ(ErrorCode::COULDNT_RESOLVE_HOST, response.error.code);
122+
// Sometimes the DNS server returns a fake address instead of an NXDOMAIN response, leading to COULDNT_CONNECT.
123+
EXPECT_TRUE(response.error.code == ErrorCode::COULDNT_RESOLVE_HOST || response.error.code == ErrorCode::COULDNT_CONNECT);
123124
}
124125

125126
TEST(UrlEncodedPostTests, FormPostSingleTest) {

test/raw_body_tests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ TEST(BodyPostTests, UrlPostBadHostTest) {
110110
EXPECT_EQ(url, response.url);
111111
EXPECT_EQ(std::string{}, response.header["content-type"]);
112112
EXPECT_EQ(0, response.status_code);
113-
EXPECT_EQ(ErrorCode::COULDNT_RESOLVE_HOST, response.error.code);
113+
// Sometimes the DNS server returns a fake address instead of an NXDOMAIN response, leading to COULDNT_CONNECT.
114+
EXPECT_TRUE(response.error.code == ErrorCode::COULDNT_RESOLVE_HOST || response.error.code == ErrorCode::COULDNT_CONNECT);
114115
}
115116

116117
TEST(BodyPostTests, StringMoveBodyTest) {

0 commit comments

Comments
 (0)