get_tests.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 
3 #include <string>
4 
5 #include <cpr/cpr.h>
6 
7 #include "server.h"
8 
9 using namespace cpr;
10 
11 static Server* server = new Server();
12 auto base = server->GetBaseUrl();
13 
14 TEST(BasicTests, HelloWorldTest) {
15  auto url = Url{base + "/hello.html"};
16  auto response = cpr::Get(url);
17  auto expected_text = std::string{"Hello world!"};
18  EXPECT_EQ(expected_text, response.text);
19  EXPECT_EQ(url, response.url);
20  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
21  EXPECT_EQ(200, response.status_code);
22  EXPECT_EQ(ErrorCode::OK, response.error.code);
23 }
24 
25 TEST(BasicTests, TimeoutTest) {
26  auto url = Url{base + "/hello.html"};
27  auto response = cpr::Get(url, Timeout{0L});
28  auto expected_text = std::string{"Hello world!"};
29  EXPECT_EQ(expected_text, response.text);
30  EXPECT_EQ(url, response.url);
31  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
32  EXPECT_EQ(200, response.status_code);
33  EXPECT_EQ(ErrorCode::OK, response.error.code);
34 }
35 
36 TEST(BasicTests, BasicJsonTest) {
37  auto url = Url{base + "/basic.json"};
38  auto response = cpr::Get(url);
39  auto expected_text = std::string{"[\n"
40  " {\n"
41  " \"first_key\": \"first_value\",\n"
42  " \"second_key\": \"second_value\"\n"
43  " }\n"
44  "]"};
45  EXPECT_EQ(expected_text, response.text);
46  EXPECT_EQ(url, response.url);
47  EXPECT_EQ(std::string{"application/octet-stream"}, response.header["content-type"]);
48  EXPECT_EQ(200, response.status_code);
49  EXPECT_EQ(ErrorCode::OK, response.error.code);
50 }
51 
52 TEST(BasicTests, ResourceNotFoundTest) {
53  auto url = Url{base + "/error.html"};
54  auto response = cpr::Get(url);
55  auto expected_text = std::string{"404 Not Found\n"};
56  EXPECT_EQ(expected_text, response.text);
57  EXPECT_EQ(url, response.url);
58  EXPECT_EQ(std::string{"text/plain"}, response.header["content-type"]);
59  EXPECT_EQ(404, response.status_code);
60  EXPECT_EQ(ErrorCode::OK, response.error.code);
61 }
62 
63 TEST(BasicTests, BadHostTest) {
64  auto url = Url{"http://bad_host/"};
65  auto response = cpr::Get(url);
66  EXPECT_EQ(std::string{}, response.text);
67  EXPECT_EQ(url, response.url);
68  EXPECT_EQ(0, response.status_code);
69  EXPECT_EQ(ErrorCode::HOST_RESOLUTION_FAILURE, response.error.code);
70 }
71 
72 TEST(BasicTests, RequestBodyTest) {
73  auto url = Url{base + "/body_get.html"};
74  auto body = Body{"message=abc123"};
75  auto response = cpr::Get(url, body);
76  auto expected_text = std::string{"abc123"};
77  EXPECT_EQ(expected_text, response.text);
78  EXPECT_EQ(url, response.url);
79  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
80  EXPECT_EQ(200, response.status_code);
81  EXPECT_EQ(ErrorCode::OK, response.error.code);
82 }
83 
84 TEST(CookiesTests, SingleCookieTest) {
85  auto url = Url{base + "/basic_cookies.html"};
86  auto cookies = Cookies{{"hello", "world"}, {"my", "another; fake=cookie;"}};
87  auto response = cpr::Get(url, cookies);
88  auto expected_text = std::string{"Hello world!"};
89  EXPECT_EQ(expected_text, response.text);
90  EXPECT_EQ(url, response.url);
91  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
92  EXPECT_EQ(200, response.status_code);
93  EXPECT_EQ(ErrorCode::OK, response.error.code);
94  cookies = response.cookies;
95  EXPECT_EQ(cookies["cookie"], response.cookies["cookie"]);
96  EXPECT_EQ(cookies["icecream"], response.cookies["icecream"]);
97  EXPECT_EQ(cookies["expires"], response.cookies["expires"]);
98 }
99 
100 TEST(CookiesTests, CheckBasicCookieTest) {
101  // server validates whether the cookies are indeed present
102  auto url = Url{base + "/check_cookies.html"};
103  auto cookies = Cookies{{"cookie", "chocolate"}, {"icecream", "vanilla"}};
104  auto response = cpr::Get(url, cookies);
105  auto expected_text = std::string{"Hello world!"};
106  EXPECT_EQ(expected_text, response.text);
107  EXPECT_EQ(url, response.url);
108  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
109  EXPECT_EQ(200, response.status_code);
110  EXPECT_EQ(ErrorCode::OK, response.error.code);
111 }
112 
113 TEST(CookiesTests, V1CookieTest) {
114  auto url = Url{base + "/v1_cookies.html"};
115  auto response = cpr::Get(url);
116  auto expected_text = std::string{"Hello world!"};
117  EXPECT_EQ(expected_text, response.text);
118  EXPECT_EQ(url, response.url);
119  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
120  EXPECT_EQ(200, response.status_code);
121  EXPECT_EQ(ErrorCode::OK, response.error.code);
122  auto cookies = response.cookies;
123  EXPECT_EQ("\"value with spaces (v1 cookie)\"", cookies["cookie"]);
124 }
125 
126 TEST(CookiesTests, CheckV1CookieTest) {
127  // server validates whether the cookie is indeed present
128  auto url = Url{base + "/check_v1_cookies.html"};
129  auto cookies = Cookies{{"cookie", "\"value with spaces (v1 cookie)\""}};
130  auto response = cpr::Get(url, cookies);
131  auto expected_text = std::string{"Hello world!"};
132  EXPECT_EQ(expected_text, response.text);
133  EXPECT_EQ(url, response.url);
134  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
135  EXPECT_EQ(200, response.status_code);
136  EXPECT_EQ(ErrorCode::OK, response.error.code);
137 }
138 
139 TEST(ParameterTests, SingleParameterTest) {
140  auto url = Url{base + "/hello.html"};
141  auto parameters = Parameters{{"key", "value"}};
142  auto response = cpr::Get(url, parameters);
143  auto expected_text = std::string{"Hello world!"};
144  EXPECT_EQ(expected_text, response.text);
145  EXPECT_EQ(Url{url + "?key=value"}, response.url);
146  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
147  EXPECT_EQ(200, response.status_code);
148  EXPECT_EQ(ErrorCode::OK, response.error.code);
149 }
150 
151 TEST(ParameterTests, SingleParameterOnlyKeyTest) {
152  auto url = Url{base + "/hello.html"};
153  auto parameters = Parameters{{"key", ""}};
154  auto response = cpr::Get(url, parameters);
155  auto expected_text = std::string{"Hello world!"};
156  EXPECT_EQ(expected_text, response.text);
157  EXPECT_EQ(Url{url + "?key"}, response.url);
158  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
159  EXPECT_EQ(200, response.status_code);
160 }
161 
162 TEST(ParameterTests, MultipleParametersTest) {
163  auto url = Url{base + "/hello.html"};
164  auto response = cpr::Get(url, Parameters{{"key", "value"},
165  {"hello", "world"},
166  {"test", "case"}});
167  auto expected_text = std::string{"Hello world!"};
168  EXPECT_EQ(expected_text, response.text);
169  EXPECT_EQ(Url{url + "?key=value&hello=world&test=case"}, response.url);
170  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
171  EXPECT_EQ(200, response.status_code);
172  EXPECT_EQ(ErrorCode::OK, response.error.code);
173 }
174 
175 TEST(ParameterTests, MultipleDynamicParametersTest) {
176  auto url = Url{base + "/hello.html"};
177  auto parameters = Parameters{{"key", "value"}};
178  parameters.AddParameter({"hello", "world"});
179  parameters.AddParameter({"test", "case"});
180  auto response = cpr::Get(url, parameters);
181  auto expected_text = std::string{"Hello world!"};
182  EXPECT_EQ(expected_text, response.text);
183  EXPECT_EQ(Url{url + "?key=value&hello=world&test=case"}, response.url);
184  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
185  EXPECT_EQ(200, response.status_code);
186  EXPECT_EQ(ErrorCode::OK, response.error.code);
187 }
188 
189 TEST(BasicAuthenticationTests, BasicAuthenticationSuccessTest) {
190  auto url = Url{base + "/basic_auth.html"};
191  auto response = cpr::Get(url, Authentication{"user", "password"});
192  auto expected_text = std::string{"Header reflect GET"};
193  EXPECT_EQ(expected_text, response.text);
194  EXPECT_EQ(url, response.url);
195  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
196  EXPECT_EQ(200, response.status_code);
197  EXPECT_EQ(ErrorCode::OK, response.error.code);
198 }
199 
200 TEST(BasicAuthenticationTests, BasicDigestSuccessTest) {
201  auto url = Url{base + "/digest_auth.html"};
202  auto response = cpr::Get(url, Digest{"user", "password"});
203  auto expected_text = std::string{"Header reflect GET"};
204  EXPECT_EQ(expected_text, response.text);
205  EXPECT_EQ(url, response.url);
206  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
207  EXPECT_EQ(200, response.status_code);
208  EXPECT_EQ(ErrorCode::OK, response.error.code);
209 }
210 
211 TEST(BasicAthenticationParameterTests, BasicAuthenticationSuccessSingleParameterTest) {
212  auto url = Url{base + "/basic_auth.html"};
213  auto response = cpr::Get(url, Authentication{"user", "password"},
214  Parameters{{"hello", "world"}});
215  auto expected_text = std::string{"Header reflect GET"};
216  EXPECT_EQ(expected_text, response.text);
217  EXPECT_EQ(Url{url + "?hello=world"}, response.url);
218  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
219  EXPECT_EQ(200, response.status_code);
220  EXPECT_EQ(ErrorCode::OK, response.error.code);
221 }
222 
223 TEST(BasicAuthenticationParameterTests, BasicAuthenticationSuccessMultipleParametersTest) {
224  auto url = Url{base + "/basic_auth.html"};
225  auto response = cpr::Get(url, Authentication{"user", "password"},
226  Parameters{{"key", "value"}, {"hello", "world"}, {"test", "case"}});
227  auto expected_text = std::string{"Header reflect GET"};
228  EXPECT_EQ(expected_text, response.text);
229  EXPECT_EQ(Url{url + "?key=value&hello=world&test=case"}, response.url);
230  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
231  EXPECT_EQ(200, response.status_code);
232  EXPECT_EQ(ErrorCode::OK, response.error.code);
233 }
234 
235 TEST(BasicAuthenticationParameterTests, BasicAuthenticationSuccessSingleParameterReverseTest) {
236  auto url = Url{base + "/basic_auth.html"};
237  auto response = cpr::Get(url, Parameters{{"hello", "world"}},
238  Authentication{"user", "password"});
239  auto expected_text = std::string{"Header reflect GET"};
240  EXPECT_EQ(expected_text, response.text);
241  EXPECT_EQ(Url{url + "?hello=world"}, response.url);
242  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
243  EXPECT_EQ(200, response.status_code);
244  EXPECT_EQ(ErrorCode::OK, response.error.code);
245 }
246 
247 TEST(BasicAuthenticationParameterTests, BasicAuthenticationSuccessMultipleParametersReverseTest) {
248  auto url = Url{base + "/basic_auth.html"};
249  auto response = cpr::Get(url, Parameters{{"key", "value"},
250  {"hello", "world"},
251  {"test", "case"}},
252  Authentication{"user", "password"});
253 
254  auto expected_text = std::string{"Header reflect GET"};
255  EXPECT_EQ(expected_text, response.text);
256  EXPECT_EQ(Url{url + "?key=value&hello=world&test=case"}, response.url);
257  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
258  EXPECT_EQ(200, response.status_code);
259  EXPECT_EQ(ErrorCode::OK, response.error.code);
260 }
261 
262 TEST(BasicAuthenticationHeaderTests, BasicAuthenticationSuccessSingleHeaderTest) {
263  auto url = Url{base + "/basic_auth.html"};
264  auto response = cpr::Get(url, Authentication{"user", "password"},
265  Header{{"hello", "world"}});
266  auto expected_text = std::string{"Header reflect GET"};
267  EXPECT_EQ(expected_text, response.text);
268  EXPECT_EQ(url, response.url);
269  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
270  EXPECT_EQ(std::string{"world"}, response.header["hello"]);
271  EXPECT_EQ(200, response.status_code);
272  EXPECT_EQ(ErrorCode::OK, response.error.code);
273 }
274 
275 TEST(BasicAuthenticationHeaderTests, BasicAuthenticationSuccessMultipleHeadersTest) {
276  auto url = Url{base + "/basic_auth.html"};
277  auto response = cpr::Get(url, Authentication{"user", "password"},
278  Header{{"key", "value"}, {"hello", "world"}, {"test", "case"}});
279  auto expected_text = std::string{"Header reflect GET"};
280  EXPECT_EQ(expected_text, response.text);
281  EXPECT_EQ(url, response.url);
282  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
283  EXPECT_EQ(std::string{"world"}, response.header["hello"]);
284  EXPECT_EQ(std::string{"value"}, response.header["key"]);
285  EXPECT_EQ(std::string{"case"}, response.header["test"]);
286  EXPECT_EQ(200, response.status_code);
287  EXPECT_EQ(ErrorCode::OK, response.error.code);
288 }
289 
290 TEST(BasicAuthenticationHeaderTests, BasicAuthenticationSuccessSingleHeaderReverseTest) {
291  auto url = Url{base + "/basic_auth.html"};
292  auto response = cpr::Get(url, Header{{"hello", "world"}},
293  Authentication{"user", "password"});
294  auto expected_text = std::string{"Header reflect GET"};
295  EXPECT_EQ(expected_text, response.text);
296  EXPECT_EQ(url, response.url);
297  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
298  EXPECT_EQ(std::string{"world"}, response.header["hello"]);
299  EXPECT_EQ(200, response.status_code);
300  EXPECT_EQ(ErrorCode::OK, response.error.code);
301 }
302 
303 TEST(BasicAuthenticationHeaderTests, BasicAuthenticationSuccessMultipleHeadersReverseTest) {
304  auto url = Url{base + "/basic_auth.html"};
305  auto response = cpr::Get(url, Header{{"key", "value"}, {"hello", "world"}, {"test", "case"}},
306  Authentication{"user", "password"});
307  auto expected_text = std::string{"Header reflect GET"};
308  EXPECT_EQ(expected_text, response.text);
309  EXPECT_EQ(url, response.url);
310  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
311  EXPECT_EQ(std::string{"world"}, response.header["hello"]);
312  EXPECT_EQ(std::string{"value"}, response.header["key"]);
313  EXPECT_EQ(std::string{"case"}, response.header["test"]);
314  EXPECT_EQ(200, response.status_code);
315  EXPECT_EQ(ErrorCode::OK, response.error.code);
316 }
317 
318 TEST(BasicAuthenticationTests, BasicAuthenticationNullFailureTest) {
319  auto url = Url{base + "/basic_auth.html"};
320  auto response = cpr::Get(url);
321  EXPECT_EQ(std::string{}, response.text);
322  EXPECT_EQ(url, response.url);
323  EXPECT_EQ(std::string{}, response.header["content-type"]);
324  EXPECT_EQ(401, response.status_code);
325  EXPECT_EQ(ErrorCode::OK, response.error.code);
326 }
327 
328 TEST(BasicAuthenticationTests, BasicAuthenticationFailureTest) {
329  auto url = Url{base + "/basic_auth.html"};
330  auto response = cpr::Get(url, Authentication{"user", "bad_password"});
331  EXPECT_EQ(std::string{}, response.text);
332  EXPECT_EQ(url, response.url);
333  EXPECT_EQ(std::string{}, response.header["content-type"]);
334  EXPECT_EQ(401, response.status_code);
335  EXPECT_EQ(ErrorCode::OK, response.error.code);
336 }
337 
338 TEST(BasicAuthenticationParameterTests, BasicAuthenticationFailureSingleParameterTest) {
339  auto url = Url{base + "/basic_auth.html"};
340  auto response = cpr::Get(url, Authentication{"user", "bad_password"},
341  Parameters{{"hello", "world"}});
342  EXPECT_EQ(std::string{}, response.text);
343  EXPECT_EQ(Url{url + "?hello=world"}, response.url);
344  EXPECT_EQ(std::string{}, response.header["content-type"]);
345  EXPECT_EQ(401, response.status_code);
346  EXPECT_EQ(ErrorCode::OK, response.error.code);
347 }
348 
349 TEST(BasicAuthenticationParameterTests, BasicAuthenticationFailureMultipleParametersTest) {
350  auto url = Url{base + "/basic_auth.html"};
351  auto response = cpr::Get(url, Authentication{"user", "bad_password"},
352  Parameters{{"key", "value"}, {"hello", "world"}, {"test", "case"}});
353  EXPECT_EQ(std::string{}, response.text);
354  EXPECT_EQ(Url{url + "?key=value&hello=world&test=case"}, response.url);
355  EXPECT_EQ(std::string{}, response.header["content-type"]);
356  EXPECT_EQ(401, response.status_code);
357  EXPECT_EQ(ErrorCode::OK, response.error.code);
358 }
359 
360 TEST(HeaderTests, HeaderJsonTest) {
361  auto url = Url{base + "/basic.json"};
362  auto response = cpr::Get(url, Header{{"content-type", "application/json"}});
363  auto expected_text = std::string{"[\n"
364  " {\n"
365  " \"first_key\": \"first_value\",\n"
366  " \"second_key\": \"second_value\"\n"
367  " }\n"
368  "]"};
369  EXPECT_EQ(expected_text, response.text);
370  EXPECT_EQ(url, response.url);
371  EXPECT_EQ(std::string{"application/json"}, response.header["content-type"]);
372  EXPECT_EQ(200, response.status_code);
373  EXPECT_EQ(ErrorCode::OK, response.error.code);
374 }
375 
376 TEST(HeaderTests, HeaderReflectNoneTest) {
377  auto url = Url{base + "/header_reflect.html"};
378  auto response = cpr::Get(url);
379  auto expected_text = std::string{"Header reflect GET"};
380  EXPECT_EQ(expected_text, response.text);
381  EXPECT_EQ(url, response.url);
382  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
383  EXPECT_EQ(std::string{}, response.header["hello"]);
384  EXPECT_EQ(200, response.status_code);
385  EXPECT_EQ(ErrorCode::OK, response.error.code);
386 }
387 
388 TEST(HeaderTests, HeaderReflectEmptyTest) {
389  auto url = Url{base + "/header_reflect.html"};
390  auto response = cpr::Get(url, Header{});
391  auto expected_text = std::string{"Header reflect GET"};
392  EXPECT_EQ(expected_text, response.text);
393  EXPECT_EQ(url, response.url);
394  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
395  EXPECT_EQ(std::string{}, response.header["hello"]);
396  EXPECT_EQ(200, response.status_code);
397  EXPECT_EQ(ErrorCode::OK, response.error.code);
398 }
399 
400 TEST(HeaderTests, HeaderReflectSingleTest) {
401  auto url = Url{base + "/header_reflect.html"};
402  auto response = cpr::Get(url, Header{{"hello", "world"}});
403  auto expected_text = std::string{"Header reflect GET"};
404  EXPECT_EQ(expected_text, response.text);
405  EXPECT_EQ(url, response.url);
406  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
407  EXPECT_EQ(std::string{"world"}, response.header["hello"]);
408  EXPECT_EQ(200, response.status_code);
409  EXPECT_EQ(ErrorCode::OK, response.error.code);
410 }
411 
412 TEST(HeaderTests, HeaderReflectMultipleTest) {
413  auto url = Url{base + "/header_reflect.html"};
414  auto response = cpr::Get(url, Header{{"hello", "world"}, {"key", "value"}, {"test", "case"}});
415  auto expected_text = std::string{"Header reflect GET"};
416  EXPECT_EQ(expected_text, response.text);
417  EXPECT_EQ(url, response.url);
418  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
419  EXPECT_EQ(std::string{"world"}, response.header["hello"]);
420  EXPECT_EQ(std::string{"value"}, response.header["key"]);
421  EXPECT_EQ(std::string{"case"}, response.header["test"]);
422  EXPECT_EQ(200, response.status_code);
423  EXPECT_EQ(ErrorCode::OK, response.error.code);
424 }
425 
426 TEST(HeaderTests, HeaderReflectCaseInsensitiveTest) {
427  auto url = Url{base + "/header_reflect.html"};
428  auto response = cpr::Get(url, Header{{"HeLlO", "wOrLd"}});
429  auto expected_text = std::string{"Header reflect GET"};
430  EXPECT_EQ(expected_text, response.text);
431  EXPECT_EQ(url, response.url);
432  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
433  EXPECT_EQ(std::string{"wOrLd"}, response.header["hello"]);
434  EXPECT_EQ(std::string{"wOrLd"}, response.header["HELLO"]);
435  EXPECT_EQ(std::string{"wOrLd"}, response.header["hElLo"]);
436  EXPECT_EQ(200, response.status_code);
437  EXPECT_EQ(ErrorCode::OK, response.error.code);
438 }
439 
440 TEST(HeaderTests, SetEmptyHeaderTest) {
441  auto url = Url{base + "/header_reflect.html"};
442  auto response = cpr::Get(url, Header{{"hello", ""}});
443  auto expected_text = std::string{"Header reflect GET"};
444  EXPECT_EQ(expected_text, response.text);
445  EXPECT_EQ(url, response.url);
446  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
447  EXPECT_EQ(std::string{}, response.header["hello"]);
448  EXPECT_EQ(200, response.status_code);
449  EXPECT_EQ(ErrorCode::OK, response.error.code);
450 }
451 
452 TEST(ParameterHeaderTests, HeaderReflectNoneParametersTest) {
453  auto url = Url{base + "/header_reflect.html"};
454  auto response = cpr::Get(url, Parameters{{"one", "two"}, {"three", "four"}, {"five", "six"}});
455  auto expected_text = std::string{"Header reflect GET"};
456  EXPECT_EQ(expected_text, response.text);
457  EXPECT_EQ(Url{url + "?one=two&three=four&five=six"}, response.url);
458  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
459  EXPECT_EQ(std::string{}, response.header["hello"]);
460  EXPECT_EQ(200, response.status_code);
461  EXPECT_EQ(ErrorCode::OK, response.error.code);
462 }
463 
464 TEST(ParameterHeaderTests, HeaderReflectEmptyParametersTest) {
465  auto url = Url{base + "/header_reflect.html"};
466  auto response = cpr::Get(url, Header{},
467  Parameters{{"one", "two"}, {"three", "four"}, {"five", "six"}});
468  auto expected_text = std::string{"Header reflect GET"};
469  EXPECT_EQ(expected_text, response.text);
470  EXPECT_EQ(Url{url + "?one=two&three=four&five=six"}, response.url);
471  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
472  EXPECT_EQ(std::string{}, response.header["hello"]);
473  EXPECT_EQ(200, response.status_code);
474  EXPECT_EQ(ErrorCode::OK, response.error.code);
475 }
476 
477 TEST(ParameterHeaderTests, HeaderReflectSingleParametersTest) {
478  auto url = Url{base + "/header_reflect.html"};
479  auto response = cpr::Get(url, Header{{"hello", "world"}},
480  Parameters{{"one", "two"}, {"three", "four"}, {"five", "six"}});
481  auto expected_text = std::string{"Header reflect GET"};
482  EXPECT_EQ(expected_text, response.text);
483  EXPECT_EQ(Url{url + "?one=two&three=four&five=six"}, response.url);
484  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
485  EXPECT_EQ(std::string{"world"}, response.header["hello"]);
486  EXPECT_EQ(200, response.status_code);
487  EXPECT_EQ(ErrorCode::OK, response.error.code);
488 }
489 
490 TEST(ParameterHeaderTests, HeaderReflectMultipleParametersTest) {
491  auto url = Url{base + "/header_reflect.html"};
492  auto response = cpr::Get(url, Header{{"hello", "world"}, {"key", "value"}, {"test", "case"}},
493  Parameters{{"one", "two"}, {"three", "four"}, {"five", "six"}});
494  auto expected_text = std::string{"Header reflect GET"};
495  EXPECT_EQ(expected_text, response.text);
496  EXPECT_EQ(Url{url + "?one=two&three=four&five=six"}, response.url);
497  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
498  EXPECT_EQ(std::string{"world"}, response.header["hello"]);
499  EXPECT_EQ(std::string{"value"}, response.header["key"]);
500  EXPECT_EQ(std::string{"case"}, response.header["test"]);
501  EXPECT_EQ(200, response.status_code);
502  EXPECT_EQ(ErrorCode::OK, response.error.code);
503 }
504 
505 TEST(ParameterHeaderTests, HeaderReflectCaseInsensitiveParametersTest) {
506  auto url = Url{base + "/header_reflect.html"};
507  auto response = cpr::Get(url, Header{{"HeLlO", "wOrLd"}},
508  Parameters{{"one", "two"}, {"three", "four"}, {"five", "six"}});
509  auto expected_text = std::string{"Header reflect GET"};
510  EXPECT_EQ(expected_text, response.text);
511  EXPECT_EQ(Url{url + "?one=two&three=four&five=six"}, response.url);
512  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
513  EXPECT_EQ(std::string{"wOrLd"}, response.header["hello"]);
514  EXPECT_EQ(std::string{"wOrLd"}, response.header["HELLO"]);
515  EXPECT_EQ(std::string{"wOrLd"}, response.header["hElLo"]);
516  EXPECT_EQ(200, response.status_code);
517  EXPECT_EQ(ErrorCode::OK, response.error.code);
518 }
519 
520 TEST(ParameterHeaderTests, HeaderReflectEmptyParametersReverseTest) {
521  auto url = Url{base + "/header_reflect.html"};
522  auto response = cpr::Get(url, Parameters{{"one", "two"}, {"three", "four"}, {"five", "six"}},
523  Header{});
524  auto expected_text = std::string{"Header reflect GET"};
525  EXPECT_EQ(expected_text, response.text);
526  EXPECT_EQ(Url{url + "?one=two&three=four&five=six"}, response.url);
527  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
528  EXPECT_EQ(std::string{}, response.header["hello"]);
529  EXPECT_EQ(200, response.status_code);
530  EXPECT_EQ(ErrorCode::OK, response.error.code);
531 }
532 
533 TEST(ParameterHeaderTests, HeaderReflectSingleParametersReverseTest) {
534  auto url = Url{base + "/header_reflect.html"};
535  auto response = cpr::Get(url, Parameters{{"one", "two"}, {"three", "four"}, {"five", "six"}},
536  Header{{"hello", "world"}});
537  auto expected_text = std::string{"Header reflect GET"};
538  EXPECT_EQ(expected_text, response.text);
539  EXPECT_EQ(Url{url + "?one=two&three=four&five=six"}, response.url);
540  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
541  EXPECT_EQ(std::string{"world"}, response.header["hello"]);
542  EXPECT_EQ(200, response.status_code);
543  EXPECT_EQ(ErrorCode::OK, response.error.code);
544 }
545 
546 TEST(ParameterHeaderTests, HeaderReflectMultipleParametersReverseTest) {
547  auto url = Url{base + "/header_reflect.html"};
548  auto response = cpr::Get(url, Parameters{{"one", "two"}, {"three", "four"}, {"five", "six"}},
549  Header{{"hello", "world"}, {"key", "value"}, {"test", "case"}});
550  auto expected_text = std::string{"Header reflect GET"};
551  EXPECT_EQ(expected_text, response.text);
552  EXPECT_EQ(Url{url + "?one=two&three=four&five=six"}, response.url);
553  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
554  EXPECT_EQ(std::string{"world"}, response.header["hello"]);
555  EXPECT_EQ(std::string{"value"}, response.header["key"]);
556  EXPECT_EQ(std::string{"case"}, response.header["test"]);
557  EXPECT_EQ(200, response.status_code);
558  EXPECT_EQ(ErrorCode::OK, response.error.code);
559 }
560 
561 TEST(ParameterHeaderTests, HeaderReflectCaseInsensitiveParametersReverseTest) {
562  auto url = Url{base + "/header_reflect.html"};
563  auto response = cpr::Get(url, Parameters{{"one", "two"}, {"three", "four"}, {"five", "six"}},
564  Header{{"HeLlO", "wOrLd"}});
565  auto expected_text = std::string{"Header reflect GET"};
566  EXPECT_EQ(expected_text, response.text);
567  EXPECT_EQ(Url{url + "?one=two&three=four&five=six"}, response.url);
568  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
569  EXPECT_EQ(std::string{"wOrLd"}, response.header["hello"]);
570  EXPECT_EQ(std::string{"wOrLd"}, response.header["HELLO"]);
571  EXPECT_EQ(std::string{"wOrLd"}, response.header["hElLo"]);
572  EXPECT_EQ(200, response.status_code);
573  EXPECT_EQ(ErrorCode::OK, response.error.code);
574 }
575 
576 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderAATest) {
577  auto url = Url{base + "/basic_auth.html"};
578  auto response = cpr::Get(url, Authentication{"user", "password"}, Parameters{}, Header{});
579  auto expected_text = std::string{"Header reflect GET"};
580  EXPECT_EQ(expected_text, response.text);
581  EXPECT_EQ(url, response.url);
582  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
583  EXPECT_EQ(std::string{}, response.header["hello"]);
584  EXPECT_EQ(200, response.status_code);
585  EXPECT_EQ(ErrorCode::OK, response.error.code);
586 }
587 
588 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderABTest) {
589  auto url = Url{base + "/basic_auth.html"};
590  auto response = cpr::Get(url, Authentication{"user", "bad_password"}, Parameters{}, Header{});
591  EXPECT_EQ(std::string{}, response.text);
592  EXPECT_EQ(url, response.url);
593  EXPECT_EQ(std::string{}, response.header["content-type"]);
594  EXPECT_EQ(std::string{}, response.header["hello"]);
595  EXPECT_EQ(401, response.status_code);
596  EXPECT_EQ(ErrorCode::OK, response.error.code);
597 }
598 
599 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderACTest) {
600  auto url = Url{base + "/basic_auth.html"};
601  auto response = cpr::Get(url, Authentication{"user", "password"}, Parameters{{"one", "two"}},
602  Header{});
603  auto expected_text = std::string{"Header reflect GET"};
604  EXPECT_EQ(expected_text, response.text);
605  EXPECT_EQ(Url{url + "?one=two"}, response.url);
606  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
607  EXPECT_EQ(std::string{}, response.header["hello"]);
608  EXPECT_EQ(200, response.status_code);
609  EXPECT_EQ(ErrorCode::OK, response.error.code);
610 }
611 
612 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderADTest) {
613  auto url = Url{base + "/basic_auth.html"};
614  auto response = cpr::Get(url, Authentication{"user", "bad_password"},
615  Parameters{{"one", "two"}}, Header{});
616  EXPECT_EQ(std::string{}, response.text);
617  EXPECT_EQ(Url{url + "?one=two"}, response.url);
618  EXPECT_EQ(std::string{}, response.header["content-type"]);
619  EXPECT_EQ(std::string{}, response.header["hello"]);
620  EXPECT_EQ(401, response.status_code);
621  EXPECT_EQ(ErrorCode::OK, response.error.code);
622 }
623 
624 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderAETest) {
625  auto url = Url{base + "/basic_auth.html"};
626  auto response = cpr::Get(url, Authentication{"user", "password"}, Parameters{},
627  Header{{"hello", "world"}});
628  auto expected_text = std::string{"Header reflect GET"};
629  EXPECT_EQ(expected_text, response.text);
630  EXPECT_EQ(url, response.url);
631  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
632  EXPECT_EQ(std::string{"world"}, response.header["hello"]);
633  EXPECT_EQ(200, response.status_code);
634  EXPECT_EQ(ErrorCode::OK, response.error.code);
635 }
636 
637 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderAFTest) {
638  auto url = Url{base + "/basic_auth.html"};
639  auto response = cpr::Get(url, Authentication{"user", "bad_password"}, Parameters{},
640  Header{{"hello", "world"}});
641  EXPECT_EQ(std::string{}, response.text);
642  EXPECT_EQ(url, response.url);
643  EXPECT_EQ(std::string{}, response.header["content-type"]);
644  EXPECT_EQ(std::string{}, response.header["hello"]);
645  EXPECT_EQ(401, response.status_code);
646  EXPECT_EQ(ErrorCode::OK, response.error.code);
647 }
648 
649 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderAGTest) {
650  auto url = Url{base + "/basic_auth.html"};
651  auto response = cpr::Get(url, Authentication{"user", "password"}, Parameters{{"one", "two"}},
652  Header{{"hello", "world"}});
653  auto expected_text = std::string{"Header reflect GET"};
654  EXPECT_EQ(expected_text, response.text);
655  EXPECT_EQ(Url{url + "?one=two"}, response.url);
656  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
657  EXPECT_EQ(std::string{"world"}, response.header["hello"]);
658  EXPECT_EQ(200, response.status_code);
659  EXPECT_EQ(ErrorCode::OK, response.error.code);
660 }
661 
662 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderAHTest) {
663  auto url = Url{base + "/basic_auth.html"};
664  auto response = cpr::Get(url, Authentication{"user", "bad_password"},
665  Parameters{{"one", "two"}}, Header{{"hello", "world"}});
666  EXPECT_EQ(std::string{}, response.text);
667  EXPECT_EQ(Url{url + "?one=two"}, response.url);
668  EXPECT_EQ(std::string{}, response.header["content-type"]);
669  EXPECT_EQ(std::string{}, response.header["hello"]);
670  EXPECT_EQ(401, response.status_code);
671  EXPECT_EQ(ErrorCode::OK, response.error.code);
672 }
673 
674 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderBATest) {
675  auto url = Url{base + "/basic_auth.html"};
676  auto response = cpr::Get(url, Parameters{}, Header{}, Authentication{"user", "password"});
677  auto expected_text = std::string{"Header reflect GET"};
678  EXPECT_EQ(expected_text, response.text);
679  EXPECT_EQ(url, response.url);
680  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
681  EXPECT_EQ(std::string{}, response.header["hello"]);
682  EXPECT_EQ(200, response.status_code);
683  EXPECT_EQ(ErrorCode::OK, response.error.code);
684 }
685 
686 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderBBTest) {
687  auto url = Url{base + "/basic_auth.html"};
688  auto response = cpr::Get(url, Parameters{}, Header{}, Authentication{"user", "bad_password"});
689  EXPECT_EQ(std::string{}, response.text);
690  EXPECT_EQ(url, response.url);
691  EXPECT_EQ(std::string{}, response.header["content-type"]);
692  EXPECT_EQ(std::string{}, response.header["hello"]);
693  EXPECT_EQ(401, response.status_code);
694  EXPECT_EQ(ErrorCode::OK, response.error.code);
695 }
696 
697 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderBCTest) {
698  auto url = Url{base + "/basic_auth.html"};
699  auto response = cpr::Get(url, Parameters{{"one", "two"}}, Header{},
700  Authentication{"user", "password"});
701  auto expected_text = std::string{"Header reflect GET"};
702  EXPECT_EQ(expected_text, response.text);
703  EXPECT_EQ(Url{url + "?one=two"}, response.url);
704  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
705  EXPECT_EQ(std::string{}, response.header["hello"]);
706  EXPECT_EQ(200, response.status_code);
707  EXPECT_EQ(ErrorCode::OK, response.error.code);
708 }
709 
710 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderBDTest) {
711  auto url = Url{base + "/basic_auth.html"};
712  auto response = cpr::Get(url, Parameters{{"one", "two"}}, Header{},
713  Authentication{"user", "bad_password"});
714  EXPECT_EQ(std::string{}, response.text);
715  EXPECT_EQ(Url{url + "?one=two"}, response.url);
716  EXPECT_EQ(std::string{}, response.header["content-type"]);
717  EXPECT_EQ(std::string{}, response.header["hello"]);
718  EXPECT_EQ(401, response.status_code);
719  EXPECT_EQ(ErrorCode::OK, response.error.code);
720 }
721 
722 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderBETest) {
723  auto url = Url{base + "/basic_auth.html"};
724  auto response = cpr::Get(url, Parameters{}, Header{{"hello", "world"}},
725  Authentication{"user", "password"});
726  auto expected_text = std::string{"Header reflect GET"};
727  EXPECT_EQ(expected_text, response.text);
728  EXPECT_EQ(url, response.url);
729  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
730  EXPECT_EQ(std::string{"world"}, response.header["hello"]);
731  EXPECT_EQ(200, response.status_code);
732  EXPECT_EQ(ErrorCode::OK, response.error.code);
733 }
734 
735 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderBFTest) {
736  auto url = Url{base + "/basic_auth.html"};
737  auto response = cpr::Get(url, Parameters{}, Header{{"hello", "world"}},
738  Authentication{"user", "bad_password"});
739  EXPECT_EQ(std::string{}, response.text);
740  EXPECT_EQ(url, response.url);
741  EXPECT_EQ(std::string{}, response.header["content-type"]);
742  EXPECT_EQ(std::string{}, response.header["hello"]);
743  EXPECT_EQ(401, response.status_code);
744  EXPECT_EQ(ErrorCode::OK, response.error.code);
745 }
746 
747 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderBGTest) {
748  auto url = Url{base + "/basic_auth.html"};
749  auto response = cpr::Get(url, Parameters{{"one", "two"}}, Header{{"hello", "world"}},
750  Authentication{"user", "password"});
751  auto expected_text = std::string{"Header reflect GET"};
752  EXPECT_EQ(expected_text, response.text);
753  EXPECT_EQ(Url{url + "?one=two"}, response.url);
754  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
755  EXPECT_EQ(std::string{"world"}, response.header["hello"]);
756  EXPECT_EQ(200, response.status_code);
757  EXPECT_EQ(ErrorCode::OK, response.error.code);
758 }
759 
760 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderBHTest) {
761  auto url = Url{base + "/basic_auth.html"};
762  auto response = cpr::Get(url, Parameters{{"one", "two"}}, Header{{"hello", "world"}},
763  Authentication{"user", "bad_password"});
764  EXPECT_EQ(std::string{}, response.text);
765  EXPECT_EQ(Url{url + "?one=two"}, response.url);
766  EXPECT_EQ(std::string{}, response.header["content-type"]);
767  EXPECT_EQ(std::string{}, response.header["hello"]);
768  EXPECT_EQ(401, response.status_code);
769  EXPECT_EQ(ErrorCode::OK, response.error.code);
770 }
771 
772 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderCATest) {
773  auto url = Url{base + "/basic_auth.html"};
774  auto response = cpr::Get(url, Header{}, Authentication{"user", "password"}, Parameters{});
775  auto expected_text = std::string{"Header reflect GET"};
776  EXPECT_EQ(expected_text, response.text);
777  EXPECT_EQ(url, response.url);
778  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
779  EXPECT_EQ(std::string{}, response.header["hello"]);
780  EXPECT_EQ(200, response.status_code);
781  EXPECT_EQ(ErrorCode::OK, response.error.code);
782 }
783 
784 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderCBTest) {
785  auto url = Url{base + "/basic_auth.html"};
786  auto response = cpr::Get(url, Header{}, Authentication{"user", "bad_password"}, Parameters{});
787  EXPECT_EQ(std::string{}, response.text);
788  EXPECT_EQ(url, response.url);
789  EXPECT_EQ(std::string{}, response.header["content-type"]);
790  EXPECT_EQ(std::string{}, response.header["hello"]);
791  EXPECT_EQ(401, response.status_code);
792  EXPECT_EQ(ErrorCode::OK, response.error.code);
793 }
794 
795 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderCCTest) {
796  auto url = Url{base + "/basic_auth.html"};
797  auto response = cpr::Get(url, Header{}, Authentication{"user", "password"},
798  Parameters{{"one", "two"}});
799  auto expected_text = std::string{"Header reflect GET"};
800  EXPECT_EQ(expected_text, response.text);
801  EXPECT_EQ(Url{url + "?one=two"}, response.url);
802  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
803  EXPECT_EQ(std::string{}, response.header["hello"]);
804  EXPECT_EQ(200, response.status_code);
805  EXPECT_EQ(ErrorCode::OK, response.error.code);
806 }
807 
808 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderCDTest) {
809  auto url = Url{base + "/basic_auth.html"};
810  auto response = cpr::Get(url, Header{}, Authentication{"user", "bad_password"},
811  Parameters{{"one", "two"}});
812  EXPECT_EQ(std::string{}, response.text);
813  EXPECT_EQ(Url{url + "?one=two"}, response.url);
814  EXPECT_EQ(std::string{}, response.header["content-type"]);
815  EXPECT_EQ(std::string{}, response.header["hello"]);
816  EXPECT_EQ(401, response.status_code);
817  EXPECT_EQ(ErrorCode::OK, response.error.code);
818 }
819 
820 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderCETest) {
821  auto url = Url{base + "/basic_auth.html"};
822  auto response = cpr::Get(url, Header{{"hello", "world"}}, Authentication{"user", "password"},
823  Parameters{});
824  auto expected_text = std::string{"Header reflect GET"};
825  EXPECT_EQ(expected_text, response.text);
826  EXPECT_EQ(url, response.url);
827  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
828  EXPECT_EQ(std::string{"world"}, response.header["hello"]);
829  EXPECT_EQ(200, response.status_code);
830  EXPECT_EQ(ErrorCode::OK, response.error.code);
831 }
832 
833 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderCFTest) {
834  auto url = Url{base + "/basic_auth.html"};
835  auto response = cpr::Get(url, Header{{"hello", "world"}},
836  Authentication{"user", "bad_password"}, Parameters{});
837  EXPECT_EQ(std::string{}, response.text);
838  EXPECT_EQ(url, response.url);
839  EXPECT_EQ(std::string{}, response.header["content-type"]);
840  EXPECT_EQ(std::string{}, response.header["hello"]);
841  EXPECT_EQ(401, response.status_code);
842  EXPECT_EQ(ErrorCode::OK, response.error.code);
843 }
844 
845 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderCGTest) {
846  auto url = Url{base + "/basic_auth.html"};
847  auto response = cpr::Get(url, Header{{"hello", "world"}}, Authentication{"user", "password"},
848  Parameters{{"one", "two"}});
849  auto expected_text = std::string{"Header reflect GET"};
850  EXPECT_EQ(expected_text, response.text);
851  EXPECT_EQ(Url{url + "?one=two"}, response.url);
852  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
853  EXPECT_EQ(std::string{"world"}, response.header["hello"]);
854  EXPECT_EQ(200, response.status_code);
855  EXPECT_EQ(ErrorCode::OK, response.error.code);
856 }
857 
858 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderCHTest) {
859  auto url = Url{base + "/basic_auth.html"};
860  auto response = cpr::Get(url, Header{{"hello", "world"}},
861  Authentication{"user", "bad_password"}, Parameters{{"one", "two"}});
862  EXPECT_EQ(std::string{}, response.text);
863  EXPECT_EQ(Url{url + "?one=two"}, response.url);
864  EXPECT_EQ(std::string{}, response.header["content-type"]);
865  EXPECT_EQ(std::string{}, response.header["hello"]);
866  EXPECT_EQ(401, response.status_code);
867  EXPECT_EQ(ErrorCode::OK, response.error.code);
868 }
869 
870 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderDATest) {
871  auto url = Url{base + "/basic_auth.html"};
872  auto response = cpr::Get(url, Authentication{"user", "password"}, Header{}, Parameters{});
873  auto expected_text = std::string{"Header reflect GET"};
874  EXPECT_EQ(expected_text, response.text);
875  EXPECT_EQ(url, response.url);
876  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
877  EXPECT_EQ(std::string{}, response.header["hello"]);
878  EXPECT_EQ(200, response.status_code);
879  EXPECT_EQ(ErrorCode::OK, response.error.code);
880 }
881 
882 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderDBTest) {
883  auto url = Url{base + "/basic_auth.html"};
884  auto response = cpr::Get(url, Authentication{"user", "bad_password"}, Header{}, Parameters{});
885  EXPECT_EQ(std::string{}, response.text);
886  EXPECT_EQ(url, response.url);
887  EXPECT_EQ(std::string{}, response.header["content-type"]);
888  EXPECT_EQ(std::string{}, response.header["hello"]);
889  EXPECT_EQ(401, response.status_code);
890  EXPECT_EQ(ErrorCode::OK, response.error.code);
891 }
892 
893 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderDCTest) {
894  auto url = Url{base + "/basic_auth.html"};
895  auto response = cpr::Get(url, Authentication{"user", "password"}, Header{},
896  Parameters{{"one", "two"}});
897  auto expected_text = std::string{"Header reflect GET"};
898  EXPECT_EQ(expected_text, response.text);
899  EXPECT_EQ(Url{url + "?one=two"}, response.url);
900  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
901  EXPECT_EQ(std::string{}, response.header["hello"]);
902  EXPECT_EQ(200, response.status_code);
903  EXPECT_EQ(ErrorCode::OK, response.error.code);
904 }
905 
906 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderDDTest) {
907  auto url = Url{base + "/basic_auth.html"};
908  auto response = cpr::Get(url, Authentication{"user", "bad_password"}, Header{},
909  Parameters{{"one", "two"}});
910  EXPECT_EQ(std::string{}, response.text);
911  EXPECT_EQ(Url{url + "?one=two"}, response.url);
912  EXPECT_EQ(std::string{}, response.header["content-type"]);
913  EXPECT_EQ(std::string{}, response.header["hello"]);
914  EXPECT_EQ(401, response.status_code);
915  EXPECT_EQ(ErrorCode::OK, response.error.code);
916 }
917 
918 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderDETest) {
919  auto url = Url{base + "/basic_auth.html"};
920  auto response = cpr::Get(url, Authentication{"user", "password"}, Header{{"hello", "world"}},
921  Parameters{});
922  auto expected_text = std::string{"Header reflect GET"};
923  EXPECT_EQ(expected_text, response.text);
924  EXPECT_EQ(url, response.url);
925  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
926  EXPECT_EQ(std::string{"world"}, response.header["hello"]);
927  EXPECT_EQ(200, response.status_code);
928  EXPECT_EQ(ErrorCode::OK, response.error.code);
929 }
930 
931 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderDFTest) {
932  auto url = Url{base + "/basic_auth.html"};
933  auto response = cpr::Get(url, Authentication{"user", "bad_password"},
934  Header{{"hello", "world"}}, Parameters{});
935  EXPECT_EQ(std::string{}, response.text);
936  EXPECT_EQ(url, response.url);
937  EXPECT_EQ(std::string{}, response.header["content-type"]);
938  EXPECT_EQ(std::string{}, response.header["hello"]);
939  EXPECT_EQ(401, response.status_code);
940  EXPECT_EQ(ErrorCode::OK, response.error.code);
941 }
942 
943 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderDGTest) {
944  auto url = Url{base + "/basic_auth.html"};
945  auto response = cpr::Get(url, Authentication{"user", "password"}, Header{{"hello", "world"}},
946  Parameters{{"one", "two"}});
947  auto expected_text = std::string{"Header reflect GET"};
948  EXPECT_EQ(expected_text, response.text);
949  EXPECT_EQ(Url{url + "?one=two"}, response.url);
950  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
951  EXPECT_EQ(std::string{"world"}, response.header["hello"]);
952  EXPECT_EQ(200, response.status_code);
953  EXPECT_EQ(ErrorCode::OK, response.error.code);
954 }
955 
956 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderDHTest) {
957  auto url = Url{base + "/basic_auth.html"};
958  auto response = cpr::Get(url, Authentication{"user", "bad_password"},
959  Header{{"hello", "world"}}, Parameters{{"one", "two"}});
960  EXPECT_EQ(std::string{}, response.text);
961  EXPECT_EQ(Url{url + "?one=two"}, response.url);
962  EXPECT_EQ(std::string{}, response.header["content-type"]);
963  EXPECT_EQ(std::string{}, response.header["hello"]);
964  EXPECT_EQ(401, response.status_code);
965  EXPECT_EQ(ErrorCode::OK, response.error.code);
966 }
967 
968 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderEATest) {
969  auto url = Url{base + "/basic_auth.html"};
970  auto response = cpr::Get(url, Header{}, Parameters{}, Authentication{"user", "password"});
971  auto expected_text = std::string{"Header reflect GET"};
972  EXPECT_EQ(expected_text, response.text);
973  EXPECT_EQ(url, response.url);
974  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
975  EXPECT_EQ(std::string{}, response.header["hello"]);
976  EXPECT_EQ(200, response.status_code);
977  EXPECT_EQ(ErrorCode::OK, response.error.code);
978 }
979 
980 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderEBTest) {
981  auto url = Url{base + "/basic_auth.html"};
982  auto response = cpr::Get(url, Header{}, Parameters{}, Authentication{"user", "bad_password"});
983  EXPECT_EQ(std::string{}, response.text);
984  EXPECT_EQ(url, response.url);
985  EXPECT_EQ(std::string{}, response.header["content-type"]);
986  EXPECT_EQ(std::string{}, response.header["hello"]);
987  EXPECT_EQ(401, response.status_code);
988  EXPECT_EQ(ErrorCode::OK, response.error.code);
989 }
990 
991 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderECTest) {
992  auto url = Url{base + "/basic_auth.html"};
993  auto response = cpr::Get(url, Header{}, Parameters{{"one", "two"}}, Authentication{"user", "password"});
994  auto expected_text = std::string{"Header reflect GET"};
995  EXPECT_EQ(expected_text, response.text);
996  EXPECT_EQ(Url{url + "?one=two"}, response.url);
997  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
998  EXPECT_EQ(std::string{}, response.header["hello"]);
999  EXPECT_EQ(200, response.status_code);
1000  EXPECT_EQ(ErrorCode::OK, response.error.code);
1001 }
1002 
1003 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderEDTest) {
1004  auto url = Url{base + "/basic_auth.html"};
1005  auto response = cpr::Get(url, Header{}, Parameters{{"one", "two"}}, Authentication{"user", "bad_password"});
1006  EXPECT_EQ(std::string{}, response.text);
1007  EXPECT_EQ(Url{url + "?one=two"}, response.url);
1008  EXPECT_EQ(std::string{}, response.header["content-type"]);
1009  EXPECT_EQ(std::string{}, response.header["hello"]);
1010  EXPECT_EQ(401, response.status_code);
1011  EXPECT_EQ(ErrorCode::OK, response.error.code);
1012 }
1013 
1014 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderEETest) {
1015  auto url = Url{base + "/basic_auth.html"};
1016  auto response = cpr::Get(url, Header{{"hello", "world"}}, Parameters{}, Authentication{"user", "password"});
1017  auto expected_text = std::string{"Header reflect GET"};
1018  EXPECT_EQ(expected_text, response.text);
1019  EXPECT_EQ(url, response.url);
1020  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
1021  EXPECT_EQ(std::string{"world"}, response.header["hello"]);
1022  EXPECT_EQ(200, response.status_code);
1023  EXPECT_EQ(ErrorCode::OK, response.error.code);
1024 }
1025 
1026 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderEFTest) {
1027  auto url = Url{base + "/basic_auth.html"};
1028  auto response = cpr::Get(url, Header{{"hello", "world"}}, Parameters{}, Authentication{"user", "bad_password"});
1029  EXPECT_EQ(std::string{}, response.text);
1030  EXPECT_EQ(url, response.url);
1031  EXPECT_EQ(std::string{}, response.header["content-type"]);
1032  EXPECT_EQ(std::string{}, response.header["hello"]);
1033  EXPECT_EQ(401, response.status_code);
1034  EXPECT_EQ(ErrorCode::OK, response.error.code);
1035 }
1036 
1037 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderEGTest) {
1038  auto url = Url{base + "/basic_auth.html"};
1039  auto response = cpr::Get(url, Header{{"hello", "world"}}, Parameters{{"one", "two"}}, Authentication{"user", "password"});
1040  auto expected_text = std::string{"Header reflect GET"};
1041  EXPECT_EQ(expected_text, response.text);
1042  EXPECT_EQ(Url{url + "?one=two"}, response.url);
1043  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
1044  EXPECT_EQ(std::string{"world"}, response.header["hello"]);
1045  EXPECT_EQ(200, response.status_code);
1046  EXPECT_EQ(ErrorCode::OK, response.error.code);
1047 }
1048 
1049 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderEHTest) {
1050  auto url = Url{base + "/basic_auth.html"};
1051  auto response = cpr::Get(url, Header{{"hello", "world"}}, Parameters{{"one", "two"}}, Authentication{"user", "bad_password"});
1052  EXPECT_EQ(std::string{}, response.text);
1053  EXPECT_EQ(Url{url + "?one=two"}, response.url);
1054  EXPECT_EQ(std::string{}, response.header["content-type"]);
1055  EXPECT_EQ(std::string{}, response.header["hello"]);
1056  EXPECT_EQ(401, response.status_code);
1057  EXPECT_EQ(ErrorCode::OK, response.error.code);
1058 }
1059 
1060 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderFATest) {
1061  auto url = Url{base + "/basic_auth.html"};
1062  auto response = cpr::Get(url, Parameters{}, Authentication{"user", "password"}, Header{});
1063  auto expected_text = std::string{"Header reflect GET"};
1064  EXPECT_EQ(expected_text, response.text);
1065  EXPECT_EQ(url, response.url);
1066  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
1067  EXPECT_EQ(std::string{}, response.header["hello"]);
1068  EXPECT_EQ(200, response.status_code);
1069  EXPECT_EQ(ErrorCode::OK, response.error.code);
1070 }
1071 
1072 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderFBTest) {
1073  auto url = Url{base + "/basic_auth.html"};
1074  auto response = cpr::Get(url, Parameters{}, Authentication{"user", "bad_password"}, Header{});
1075  EXPECT_EQ(std::string{}, response.text);
1076  EXPECT_EQ(url, response.url);
1077  EXPECT_EQ(std::string{}, response.header["content-type"]);
1078  EXPECT_EQ(std::string{}, response.header["hello"]);
1079  EXPECT_EQ(401, response.status_code);
1080  EXPECT_EQ(ErrorCode::OK, response.error.code);
1081 }
1082 
1083 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderFCTest) {
1084  auto url = Url{base + "/basic_auth.html"};
1085  auto response = cpr::Get(url, Parameters{{"one", "two"}}, Authentication{"user", "password"}, Header{});
1086  auto expected_text = std::string{"Header reflect GET"};
1087  EXPECT_EQ(expected_text, response.text);
1088  EXPECT_EQ(Url{url + "?one=two"}, response.url);
1089  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
1090  EXPECT_EQ(std::string{}, response.header["hello"]);
1091  EXPECT_EQ(200, response.status_code);
1092  EXPECT_EQ(ErrorCode::OK, response.error.code);
1093 }
1094 
1095 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderFDTest) {
1096  auto url = Url{base + "/basic_auth.html"};
1097  auto response = cpr::Get(url, Parameters{{"one", "two"}}, Authentication{"user", "bad_password"}, Header{});
1098  EXPECT_EQ(std::string{}, response.text);
1099  EXPECT_EQ(Url{url + "?one=two"}, response.url);
1100  EXPECT_EQ(std::string{}, response.header["content-type"]);
1101  EXPECT_EQ(std::string{}, response.header["hello"]);
1102  EXPECT_EQ(401, response.status_code);
1103  EXPECT_EQ(ErrorCode::OK, response.error.code);
1104 }
1105 
1106 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderFETest) {
1107  auto url = Url{base + "/basic_auth.html"};
1108  auto response = cpr::Get(url, Parameters{}, Authentication{"user", "password"}, Header{{"hello", "world"}});
1109  auto expected_text = std::string{"Header reflect GET"};
1110  EXPECT_EQ(expected_text, response.text);
1111  EXPECT_EQ(url, response.url);
1112  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
1113  EXPECT_EQ(std::string{"world"}, response.header["hello"]);
1114  EXPECT_EQ(200, response.status_code);
1115  EXPECT_EQ(ErrorCode::OK, response.error.code);
1116 }
1117 
1118 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderFFTest) {
1119  auto url = Url{base + "/basic_auth.html"};
1120  auto response = cpr::Get(url, Parameters{}, Authentication{"user", "bad_password"}, Header{{"hello", "world"}});
1121  EXPECT_EQ(std::string{}, response.text);
1122  EXPECT_EQ(url, response.url);
1123  EXPECT_EQ(std::string{}, response.header["content-type"]);
1124  EXPECT_EQ(std::string{}, response.header["hello"]);
1125  EXPECT_EQ(401, response.status_code);
1126  EXPECT_EQ(ErrorCode::OK, response.error.code);
1127 }
1128 
1129 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderFGTest) {
1130  auto url = Url{base + "/basic_auth.html"};
1131  auto response = cpr::Get(url, Parameters{{"one", "two"}}, Authentication{"user", "password"}, Header{{"hello", "world"}});
1132  auto expected_text = std::string{"Header reflect GET"};
1133  EXPECT_EQ(expected_text, response.text);
1134  EXPECT_EQ(Url{url + "?one=two"}, response.url);
1135  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
1136  EXPECT_EQ(std::string{"world"}, response.header["hello"]);
1137  EXPECT_EQ(200, response.status_code);
1138  EXPECT_EQ(ErrorCode::OK, response.error.code);
1139 }
1140 
1141 TEST(BasicAuthenticationParameterHeaderTests, BasicAuthenticationParameterHeaderFHTest) {
1142  auto url = Url{base + "/basic_auth.html"};
1143  auto response = cpr::Get(url, Parameters{{"one", "two"}}, Authentication{"user", "bad_password"}, Header{{"hello", "world"}});
1144  EXPECT_EQ(std::string{}, response.text);
1145  EXPECT_EQ(Url{url + "?one=two"}, response.url);
1146  EXPECT_EQ(std::string{}, response.header["content-type"]);
1147  EXPECT_EQ(std::string{}, response.header["hello"]);
1148  EXPECT_EQ(401, response.status_code);
1149  EXPECT_EQ(ErrorCode::OK, response.error.code);
1150 }
1151 
1152 TEST(GetRedirectTests, RedirectTest) {
1153  auto url = Url{base + "/temporary_redirect.html"};
1154  auto response = cpr::Get(url, false); // This should be turned into an object
1155  auto expected_text = std::string{"Found"};
1156  EXPECT_EQ(expected_text, response.text);
1157  EXPECT_EQ(url, response.url);
1158  EXPECT_EQ(std::string{}, response.header["content-type"]);
1159  EXPECT_EQ(302, response.status_code);
1160  EXPECT_EQ(ErrorCode::OK, response.error.code);
1161 }
1162 
1163 TEST(GetRedirectTests, ZeroMaxRedirectsTest) {
1164  auto url = Url{base + "/hello.html"};
1165  auto response = cpr::Get(url, MaxRedirects(0));
1166  auto expected_text = std::string{"Hello world!"};
1167  EXPECT_EQ(expected_text, response.text);
1168  EXPECT_EQ(url, response.url);
1169  EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
1170  EXPECT_EQ(200, response.status_code);
1171  EXPECT_EQ(ErrorCode::OK, response.error.code);
1172 }
1173 
1174 int main(int argc, char** argv) {
1175  ::testing::InitGoogleTest(&argc, argv);
1177  return RUN_ALL_TESTS();
1178 }
Environment * AddGlobalTestEnvironment(Environment *env)
Definition: gtest.h:1342
Definition: server.h:12
std::string Url
Definition: cprtypes.h:14
Definition: body.h:13
void AddParameter(const Parameter &parameter)
Definition: parameters.cpp:16
::std::string string
Definition: gtest-port.h:1129
static const void * body(MD5_CTX *ctx, const void *data, unsigned long size)
Definition: md5.c:281
static Server * server
Definition: get_tests.cpp:11
int main(int argc, char **argv)
Definition: get_tests.cpp:1174
auto base
Definition: get_tests.cpp:12
Url GetBaseUrl()
Definition: server.cpp:625
#define EXPECT_EQ(expected, actual)
Definition: gtest.h:2015
TEST(BasicTests, HelloWorldTest)
Definition: get_tests.cpp:14
Response Get(Ts &&...ts)
Definition: api.h:38
Definition: auth.cpp:3
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: gtest.h:2325
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: gtest.cc:5292


rc_tagdetect_client
Author(s): Monika Florek-Jasinska , Raphael Schaller
autogenerated on Sat Feb 13 2021 03:42:09