|
1 | 1 | require "test_helper" |
2 | 2 |
|
3 | | -# Every authorization server response is uncacheable and sends no Referer, |
4 | | -# whether it succeeds, fails, or never reaches its action. |
| 3 | +# Every authorization server response is uncacheable and sends no Referer to |
| 4 | +# another site, whether it succeeds, fails, or never reaches its action. The |
| 5 | +# pages a GET renders send ours to us alone (same-origin), so a browser keeps |
| 6 | +# its Origin on the forms they post back; every other answer sends none. |
5 | 7 | class OauthResponseHeadersTest < ActionDispatch::IntegrationTest |
6 | 8 | include OauthAvailabilityTestHelper |
7 | 9 |
|
@@ -32,18 +34,36 @@ class OauthResponseHeadersTest < ActionDispatch::IntegrationTest |
32 | 34 |
|
33 | 35 | assert_response :redirect |
34 | 36 | assert_match %r{/session/new}, response.location |
35 | | - assert_uncached_without_referrer |
| 37 | + assert_uncached_without_cross_site_referrer |
36 | 38 | end |
37 | 39 |
|
38 | 40 | test "the consent screen and its redirect to the client" do |
39 | 41 | sign_in_as :david |
40 | 42 |
|
41 | 43 | untenanted { get new_oauth_authorization_path, params: authorization_params } |
42 | 44 | assert_response :success |
43 | | - assert_uncached_without_referrer |
| 45 | + assert_uncached_without_cross_site_referrer |
44 | 46 |
|
45 | 47 | untenanted { post oauth_authorization_path, params: authorization_params } |
46 | 48 | assert_response :redirect |
| 49 | + assert_match %r{\Ahttp://127\.0\.0\.1:8888/callback\?.*code=}, response.location |
| 50 | + assert_uncached_without_referrer |
| 51 | + end |
| 52 | + |
| 53 | + test "an error a GET redirects to the client" do |
| 54 | + sign_in_as :david |
| 55 | + |
| 56 | + untenanted { get new_oauth_authorization_path, params: authorization_params.merge(response_type: "token") } |
| 57 | + assert_response :redirect |
| 58 | + assert_match %r{\Ahttp://127\.0\.0\.1:8888/callback\?.*error=unsupported_response_type}, response.location |
| 59 | + assert_uncached_without_cross_site_referrer |
| 60 | + end |
| 61 | + |
| 62 | + test "the not-you switch" do |
| 63 | + sign_in_as :david |
| 64 | + |
| 65 | + untenanted { post oauth_authorization_switch_path, params: authorization_params } |
| 66 | + assert_response :redirect |
47 | 67 | assert_uncached_without_referrer |
48 | 68 | end |
49 | 69 |
|
@@ -78,4 +98,9 @@ def assert_uncached_without_referrer |
78 | 98 | assert_equal "no-store", response.headers["Cache-Control"] |
79 | 99 | assert_equal "no-referrer", response.headers["Referrer-Policy"] |
80 | 100 | end |
| 101 | + |
| 102 | + def assert_uncached_without_cross_site_referrer |
| 103 | + assert_equal "no-store", response.headers["Cache-Control"] |
| 104 | + assert_equal "same-origin", response.headers["Referrer-Policy"] |
| 105 | + end |
81 | 106 | end |
0 commit comments