15
15
// See the License for the specific language governing permissions and
16
16
// limitations under the License.
17
17
18
- #include " ../cookie.hpp "
19
- #include < lest/lest .hpp>
18
+ #include < common.cxx >
19
+ #include < net/http/cookie .hpp>
20
20
21
21
using namespace std ;
22
- using namespace cookie ;
22
+ using namespace http ;
23
23
24
- const lest::test test_cookie_creation[] =
25
- {
26
24
// --------------- Testing Cookie name ------------------
27
25
28
26
CASE (" CookieException thrown when creating Cookie with no name" )
29
27
{
30
28
EXPECT_THROWS_AS ( (Cookie{" " , " value" }), CookieException );
31
29
EXPECT_THROWS ( (Cookie{" " , " value" }) );
32
- },
30
+ }
33
31
34
32
CASE (" CookieException thrown when creating Cookie with name containing invalid character" )
35
33
{
@@ -54,7 +52,7 @@ const lest::test test_cookie_creation[] =
54
52
EXPECT_THROWS ( (Cookie{" n{ame" , " value" }) );
55
53
EXPECT_THROWS ( (Cookie{" name}" , " value" }) );
56
54
EXPECT_THROWS ( (Cookie{" :nam[]{e" , " value" }) );
57
- },
55
+ }
58
56
59
57
CASE (" No CookieException thrown when creating Cookie with valid name" )
60
58
{
@@ -74,14 +72,14 @@ const lest::test test_cookie_creation[] =
74
72
* SP = <US-ASCII SP, space (32)>
75
73
* HT = <US-ASCII HT, horizontal-tab (9)>
76
74
*/
77
- },
75
+ }
78
76
79
77
// --------------- Testing Cookie value ------------------
80
78
81
79
CASE (" No CookieException thrown when creating Cookie with no value" )
82
80
{
83
81
EXPECT_NO_THROW ( (Cookie{" name" , " " }) );
84
- },
82
+ }
85
83
86
84
CASE (" CookieException thrown when creating Cookie with value containing invalid character" )
87
85
{
@@ -106,14 +104,14 @@ const lest::test test_cookie_creation[] =
106
104
EXPECT_THROWS ( (Cookie{" name" , " va{lue" }) );
107
105
EXPECT_THROWS ( (Cookie{" name" , " value}" }) );
108
106
EXPECT_THROWS ( (Cookie{" name" , " v:a[]l{ue" }) );
109
- },
107
+ }
110
108
111
109
CASE (" No CookieException thrown when creating Cookie with valid value" )
112
110
{
113
111
EXPECT_NO_THROW ( (Cookie{" name" , " value" }) );
114
112
EXPECT_NO_THROW ( (Cookie{" name" , " 1928sdfg'" }) );
115
113
EXPECT_NO_THROW ( (Cookie{" name" , " &INAann'dp21" }) );
116
- },
114
+ }
117
115
118
116
// --------------- Testing Cookie options ------------------
119
117
@@ -124,20 +122,20 @@ const lest::test test_cookie_creation[] =
124
122
CASE (" CookieException thrown when creating Cookie with empty option name" )
125
123
{
126
124
EXPECT_THROWS ( (Cookie{" name" , " value" , {" " , " Sun, 06 Nov 1994 08:49:37 GMT" }}) );
127
- },
125
+ }
128
126
129
127
CASE (" CookieException thrown when creating Cookie with invalid option name" )
130
128
{
131
129
EXPECT_THROWS ( (Cookie{" name" , " value" , {" something" , " something" }}) );
132
130
EXPECT_THROWS ( (Cookie{" name" , " value" , {" expires_" , " Sun, 06 Nov 1994 08:49:37 GMT" }}) );
133
- },
131
+ }
134
132
135
133
CASE (" CookieException thrown when creating Cookie with odd number of vector-elements" )
136
134
{
137
135
EXPECT_THROWS ( (Cookie{" name" , " value" , {" Expires" , " Sun, 06 Nov 1994 08:49:37 GMT" , " Path" }}) );
138
136
EXPECT_THROWS ( (Cookie{" name" , " value" , {" Expires" }}) );
139
137
EXPECT_THROWS ( (Cookie{" name" , " value" , {" Expires" , " Sun, 06 Nov 1994 08:49:37 GMT" , " Path" , " /something123" , " Domain" }}) );
140
- },
138
+ }
141
139
142
140
CASE (" No CookieException thrown when creating Cookie with multiple valid options" )
143
141
{
@@ -149,11 +147,11 @@ const lest::test test_cookie_creation[] =
149
147
" domain" , " example.com" , " secure" , " true" , " httponly" , " true" }}) );
150
148
EXPECT_NO_THROW ( (Cookie{" name" , " value" , {" Expires" , " Sun, 06 Nov 1994 08:49:37 GMT" , " Path" , " /anotherPath134" ,
151
149
" secure" , " true" , " domain" , " example.com" }}) );
152
- },
150
+ }
153
151
154
152
// Scenario when creating cookie. Check the set values.
155
153
156
- SCENARIO (" Creating cookies with valid values and changing these values" )
154
+ CASE (" Creating cookies with valid values and changing these values" )
157
155
{
158
156
GIVEN (" An option vector with all possible options sent to Cookie constructor" )
159
157
{
@@ -277,7 +275,7 @@ const lest::test test_cookie_creation[] =
277
275
}
278
276
}
279
277
}
280
- },
278
+ }
281
279
282
280
// Option: Expires (string GMT datetime)
283
281
@@ -312,7 +310,7 @@ const lest::test test_cookie_creation[] =
312
310
EXPECT_NO_THROW ( (Cookie{" name" , " value" , {" expires" , " Thu Feb 22 19:17:11 2013" }}) );
313
311
EXPECT_NO_THROW ( (Cookie{" name" , " value" , {" Expires" , " fri Mar 1 13:00:06 2023" }}) );
314
312
EXPECT_NO_THROW ( (Cookie{" name" , " value" , {" expiRes" , " saT Apr 9 00:09:44 2016" }}) );
315
- },
313
+ }
316
314
317
315
CASE (" CookieException thrown when creating Cookie with invalid Expires option" )
318
316
{
@@ -329,7 +327,7 @@ const lest::test test_cookie_creation[] =
329
327
EXPECT_THROWS ( (Cookie{" name" , " value" , {" Expires" , " abc" }}) );
330
328
EXPECT_THROWS ( (Cookie{" name" , " value" , {" Expires" , " saT, Apr 16 00:09:44 GMT" }}) );
331
329
EXPECT_THROWS ( (Cookie{" name" , " value" , {" Expires" , " Sun Nov 6 08:49:37" }}) );
332
- },
330
+ }
333
331
334
332
// Option: Max-Age (int)
335
333
@@ -339,15 +337,15 @@ const lest::test test_cookie_creation[] =
339
337
EXPECT_NO_THROW ( (Cookie{" name" , " value" , {" Max-AgE" , " 0" }}) );
340
338
EXPECT_NO_THROW ( (Cookie{" name" , " value" , {" MAX-Age" , " 100000" }}) );
341
339
EXPECT_NO_THROW ( (Cookie{" name" , " value" , {" max-age" , " 5011010" }}) );
342
- },
340
+ }
343
341
344
342
CASE (" CookieException thrown when creating Cookie with invalid Max-Age option" )
345
343
{
346
344
EXPECT_THROWS ( (Cookie{" name" , " value" , {" Max-Age" , " -1" }}) );
347
345
EXPECT_THROWS ( (Cookie{" name" , " value" , {" Max-Age" , " ab" }}) );
348
346
EXPECT_THROWS ( (Cookie{" name" , " value" , {" Max-Age" , " ;12" }}) );
349
347
EXPECT_THROWS ( (Cookie{" name" , " value" , {" Max-Age" , " 9999999999" }}) );
350
- },
348
+ }
351
349
352
350
// Option: Domain (string)
353
351
@@ -358,7 +356,7 @@ const lest::test test_cookie_creation[] =
358
356
EXPECT_NO_THROW ( (Cookie{" name" , " value" , {" DOMAIN" , " service.example.com" }}) );
359
357
EXPECT_NO_THROW ( (Cookie{" name" , " value" , {" Domain" , " whateverdomainyouwant123.thebrowserremovesitifnotyourdomain" }}) );
360
358
EXPECT_NO_THROW ( (Cookie{" name" , " value" , {" Domain" , " " }}) );
361
- },
359
+ }
362
360
363
361
/* All characters are allowed in the domain option, but the browser will ignore it if the domain you enter isn't yours
364
362
CASE("CookieException thrown when creating Cookie with invalid Domain option") {},
@@ -373,7 +371,7 @@ const lest::test test_cookie_creation[] =
373
371
EXPECT_NO_THROW ( (Cookie{" name" , " value" , {" PATH" , " /ex?mypath even with whitespaces" }}) );
374
372
EXPECT_NO_THROW ( (Cookie{" name" , " value" , {" Path" , " /whatever/path/you/want/:&something" }}) );
375
373
EXPECT_NO_THROW ( (Cookie{" name" , " value" , {" Path" , " " }}) );
376
- },
374
+ }
377
375
378
376
CASE (" Path is set" )
379
377
{
@@ -388,7 +386,7 @@ const lest::test test_cookie_creation[] =
388
386
EXPECT ( c3.get_path () == " /ex?mypath even with whitespaces" );
389
387
EXPECT ( c4.get_path () == " /whatever/path/you/want/:&something" );
390
388
EXPECT ( c5.get_path () == " /" );
391
- },
389
+ }
392
390
393
391
CASE (" CookieException thrown when creating Cookie with invalid Path option" )
394
392
{
@@ -397,7 +395,7 @@ const lest::test test_cookie_creation[] =
397
395
EXPECT_THROWS ( (Cookie{" name" , " value" , {" Path" , " /12\r myPath" }}) );
398
396
EXPECT_THROWS ( (Cookie{" name" , " value" , {" Path" , " /12\n myPath" }}) );
399
397
EXPECT_THROWS ( (Cookie{" name" , " value" , {" Path" , " /12\t myPath" }}) );
400
- },
398
+ }
401
399
402
400
// Option: Secure (bool)
403
401
@@ -414,7 +412,7 @@ const lest::test test_cookie_creation[] =
414
412
EXPECT ( c3.is_secure () );
415
413
EXPECT_NOT ( c4.is_secure () );
416
414
EXPECT_NOT ( c5.is_secure () );
417
- },
415
+ }
418
416
419
417
// Option: HttpOnly (bool)
420
418
@@ -432,15 +430,4 @@ const lest::test test_cookie_creation[] =
432
430
EXPECT_NOT ( c4.is_http_only () );
433
431
EXPECT_NOT ( c5.is_http_only () );
434
432
}
435
- };
436
-
437
- int main (int argc, char * argv[])
438
- {
439
- printf (" Running tests of cookie-creation...\n " );
440
-
441
- int res = lest::run (test_cookie_creation, argc, argv);
442
-
443
- printf (" Tests completed.\n " );
444
433
445
- return res;
446
- }
0 commit comments