File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change 1
1
require 'test_helper'
2
2
3
- def sso_response ( url )
3
+ def sso_response ( url , secret = Rails . application . secrets . sso_secret )
4
4
parsed = Rack ::Utils . parse_query ( url . split ( '?' ) [ -1 ] )
5
5
decoded = Base64 . decode64 ( parsed [ 'sso' ] )
6
6
decoded_hash = Rack ::Utils . parse_query ( decoded )
@@ -16,7 +16,7 @@ def sso_response(url)
16
16
query = Rack ::Utils . build_query ( user_data )
17
17
payload = Base64 . strict_encode64 ( query )
18
18
escaped = CGI ::escape ( payload )
19
- signed = OpenSSL ::HMAC . hexdigest ( 'sha256' , Rails . application . secrets . sso_secret , payload )
19
+ signed = OpenSSL ::HMAC . hexdigest ( 'sha256' , secret , payload )
20
20
21
21
[ "#{ return_sso_url } ?sso=#{ escaped } &sig=#{ signed } " , decoded_hash [ 'nonce' ] ]
22
22
end
@@ -47,4 +47,14 @@ class SessionControllerTest < ActionDispatch::IntegrationTest
47
47
assert_equal ( 422 , response . status )
48
48
assert_nil ( controller . current_user )
49
49
end
50
+
51
+ test 'shouldn\'t allow users to login if incoming payload is signed with a different secret' do
52
+ get '/login'
53
+ location = response . headers [ 'Location' ]
54
+ url , _ = sso_response ( location , 'wr0ng$ecret' )
55
+ assert_raise RuntimeError do
56
+ get url
57
+ end
58
+ assert_nil ( controller . current_user )
59
+ end
50
60
end
You can’t perform that action at this time.
0 commit comments