@@ -334,6 +334,16 @@ def rails_5_2_stable_signed_cookie_with_authenticated_encryption_flag_off
334
334
335
335
head :ok
336
336
end
337
+
338
+ def set_same_site_strict
339
+ cookies [ "user_name" ] = { value : "david" , same_site : :strict }
340
+ head :ok
341
+ end
342
+
343
+ def set_same_site_nil
344
+ cookies [ "user_name" ] = { value : "david" , same_site : nil }
345
+ head :ok
346
+ end
337
347
end
338
348
339
349
tests TestController
@@ -362,15 +372,15 @@ def setup
362
372
@request . host = "www.nextangle.com"
363
373
end
364
374
365
- def test_setting_cookie_with_no_protection
375
+ def test_setting_cookie_with_no_same_site_protection
366
376
@request . env [ "action_dispatch.cookies_same_site_protection" ] = proc { :none }
367
377
368
378
get :authenticate
369
379
assert_cookie_header "user_name=david; path=/; SameSite=None"
370
380
assert_equal ( { "user_name" => "david" } , @response . cookies )
371
381
end
372
382
373
- def test_setting_cookie_with_protection_proc_normal_user_agent
383
+ def test_setting_cookie_with_same_site_protection_proc_normal_user_agent
374
384
@request . env [ "action_dispatch.cookies_same_site_protection" ] = Proc . new do |request |
375
385
:strict unless request . user_agent == "spooky browser"
376
386
end
@@ -380,7 +390,7 @@ def test_setting_cookie_with_protection_proc_normal_user_agent
380
390
assert_equal ( { "user_name" => "david" } , @response . cookies )
381
391
end
382
392
383
- def test_setting_cookie_with_protection_proc_special_user_agent
393
+ def test_setting_cookie_with_same_site_protection_proc_special_user_agent
384
394
@request . env [ "action_dispatch.cookies_same_site_protection" ] = Proc . new do |request |
385
395
:strict unless request . user_agent == "spooky browser"
386
396
end
@@ -391,7 +401,7 @@ def test_setting_cookie_with_protection_proc_special_user_agent
391
401
assert_equal ( { "user_name" => "david" } , @response . cookies )
392
402
end
393
403
394
- def test_setting_cookie_with_misspelled_protection_raises
404
+ def test_setting_cookie_with_misspelled_same_site_protection_raises
395
405
@request . env [ "action_dispatch.cookies_same_site_protection" ] = proc { :funky }
396
406
397
407
error = assert_raise ArgumentError do
@@ -400,14 +410,38 @@ def test_setting_cookie_with_misspelled_protection_raises
400
410
assert_match "Invalid SameSite value: :funky" , error . message
401
411
end
402
412
403
- def test_setting_cookie_with_strict
413
+ def test_setting_cookie_with_same_site_strict
404
414
@request . env [ "action_dispatch.cookies_same_site_protection" ] = proc { :strict }
405
415
406
416
get :authenticate
407
417
assert_cookie_header "user_name=david; path=/; SameSite=Strict"
408
418
assert_equal ( { "user_name" => "david" } , @response . cookies )
409
419
end
410
420
421
+ def test_setting_cookie_with_same_site_nil
422
+ @request . env [ "action_dispatch.cookies_same_site_protection" ] = proc { nil }
423
+
424
+ get :authenticate
425
+ assert_cookie_header "user_name=david; path=/"
426
+ assert_equal ( { "user_name" => "david" } , @response . cookies )
427
+ end
428
+
429
+ def test_setting_cookie_with_specific_same_site_strict
430
+ @request . env [ "action_dispatch.cookies_same_site_protection" ] = proc { :lax }
431
+
432
+ get :set_same_site_strict
433
+ assert_cookie_header "user_name=david; path=/; SameSite=Strict"
434
+ assert_equal ( { "user_name" => "david" } , @response . cookies )
435
+ end
436
+
437
+ def test_setting_cookie_with_specific_same_site_nil
438
+ @request . env [ "action_dispatch.cookies_same_site_protection" ] = proc { :lax }
439
+
440
+ get :set_same_site_nil
441
+ assert_cookie_header "user_name=david; path=/"
442
+ assert_equal ( { "user_name" => "david" } , @response . cookies )
443
+ end
444
+
411
445
def test_setting_cookie
412
446
get :authenticate
413
447
assert_cookie_header "user_name=david; path=/; SameSite=Lax"
0 commit comments