File tree 2 files changed +25
-2
lines changed
2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -12,9 +12,15 @@ def set_xsrf_token_cookie
12
12
return unless protect_against_forgery? && !respond_to? ( :__exclude_xsrf_token_cookie? )
13
13
14
14
config = Rails . application . config
15
- domain = config . respond_to? ( :angular_rails_csrf_domain ) ? config . angular_rails_csrf_domain : nil
15
+
16
+ cookie_options = {
17
+ value : form_authenticity_token ,
18
+ domain : config . respond_to? ( :angular_rails_csrf_domain ) ? config . angular_rails_csrf_domain : nil
19
+ }
20
+ cookie_options [ :secure ] = config . angular_rails_csrf_secure if config . respond_to? ( :angular_rails_csrf_secure )
21
+
16
22
cookie_name = config . respond_to? ( :angular_rails_csrf_cookie_name ) ? config . angular_rails_csrf_cookie_name : 'XSRF-TOKEN'
17
- cookies [ cookie_name ] = { value : form_authenticity_token , domain : domain }
23
+ cookies [ cookie_name ] = cookie_options
18
24
end
19
25
20
26
def verified_request?
Original file line number Diff line number Diff line change @@ -41,6 +41,23 @@ def config.angular_rails_csrf_domain
41
41
assert @response . headers [ 'Set-Cookie' ] . include? ( '.test.host' )
42
42
assert_valid_cookie
43
43
assert_response :success
44
+ ensure
45
+ config . instance_eval ( 'undef :angular_rails_csrf_domain' )
46
+ end
47
+
48
+ test 'the secure flag is set if configured' do
49
+ @request . headers [ 'HTTPS' ] = 'on'
50
+
51
+ config = Rails . application . config
52
+ config . define_singleton_method ( :angular_rails_csrf_secure ) { true }
53
+
54
+ get :index
55
+ assert @response . headers [ 'Set-Cookie' ] . include? ( 'secure' )
56
+ assert_valid_cookie
57
+ assert_response :success
58
+ ensure
59
+ @request . headers [ 'HTTPS' ] = nil
60
+ config . instance_eval ( 'undef :angular_rails_csrf_secure' )
44
61
end
45
62
46
63
test 'a custom name is used if present' do
You can’t perform that action at this time.
0 commit comments