doorkeeper-mongodb 5.2.1 → 5.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/lib/doorkeeper-mongodb.rb +1 -0
  3. data/lib/doorkeeper-mongodb/mixins/mongoid/access_grant_mixin.rb +1 -0
  4. data/lib/doorkeeper-mongodb/mixins/mongoid/access_token_mixin.rb +1 -0
  5. data/lib/doorkeeper-mongodb/mixins/mongoid/application_mixin.rb +76 -0
  6. data/lib/doorkeeper-mongodb/mixins/mongoid/base_mixin.rb +0 -8
  7. data/lib/doorkeeper-mongodb/mixins/mongoid/json_serializable.rb +17 -0
  8. data/lib/doorkeeper-mongodb/version.rb +1 -1
  9. data/spec/controllers/application_metal_controller_spec.rb +4 -4
  10. data/spec/controllers/applications_controller_spec.rb +198 -202
  11. data/spec/controllers/authorizations_controller_spec.rb +32 -31
  12. data/spec/controllers/protected_resources_controller_spec.rb +10 -10
  13. data/spec/controllers/token_info_controller_spec.rb +1 -1
  14. data/spec/controllers/tokens_controller_spec.rb +105 -62
  15. data/spec/doorkeeper/redirect_uri_validator_spec.rb +183 -0
  16. data/spec/{lib → doorkeeper}/server_spec.rb +5 -4
  17. data/spec/{lib → doorkeeper}/stale_records_cleaner_spec.rb +8 -7
  18. data/spec/{version → doorkeeper}/version_spec.rb +3 -3
  19. data/spec/dummy/log/test.log +4220 -4184
  20. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{eS/eSL1QMz46gKLM0GR6S9fL6uyARPxOImcappZ9_ZtSyg.cache → Pm/PmheG0PGFqDws1qgFOxOyIL-gpMof3Ar9eSRKVLYuik.cache} +0 -0
  21. data/spec/grape/grape_integration_spec.rb +1 -1
  22. data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +1 -1
  23. data/spec/lib/config_spec.rb +23 -12
  24. data/spec/lib/doorkeeper_spec.rb +4 -4
  25. data/spec/lib/models/expirable_spec.rb +9 -9
  26. data/spec/lib/models/reusable_spec.rb +2 -2
  27. data/spec/lib/models/revocable_spec.rb +4 -7
  28. data/spec/lib/models/scopes_spec.rb +7 -7
  29. data/spec/lib/models/secret_storable_spec.rb +9 -8
  30. data/spec/lib/oauth/authorization/uri_builder_spec.rb +23 -27
  31. data/spec/lib/oauth/authorization_code_request_spec.rb +6 -6
  32. data/spec/lib/oauth/base_request_spec.rb +11 -27
  33. data/spec/lib/oauth/base_response_spec.rb +2 -2
  34. data/spec/lib/oauth/client/credentials_spec.rb +25 -25
  35. data/spec/lib/oauth/client_credentials/creator_spec.rb +89 -91
  36. data/spec/lib/oauth/client_credentials/issuer_spec.rb +84 -86
  37. data/spec/lib/oauth/client_credentials/validation_spec.rb +72 -39
  38. data/spec/lib/oauth/client_credentials_integration_spec.rb +5 -5
  39. data/spec/lib/oauth/client_credentials_request_spec.rb +7 -10
  40. data/spec/lib/oauth/client_spec.rb +8 -8
  41. data/spec/lib/oauth/code_request_spec.rb +5 -5
  42. data/spec/lib/oauth/code_response_spec.rb +4 -4
  43. data/spec/lib/oauth/error_response_spec.rb +6 -5
  44. data/spec/lib/oauth/error_spec.rb +1 -1
  45. data/spec/lib/oauth/forbidden_token_response_spec.rb +2 -2
  46. data/spec/lib/oauth/helpers/scope_checker_spec.rb +37 -37
  47. data/spec/lib/oauth/helpers/unique_token_spec.rb +2 -2
  48. data/spec/lib/oauth/helpers/uri_checker_spec.rb +54 -54
  49. data/spec/lib/oauth/invalid_request_response_spec.rb +6 -6
  50. data/spec/lib/oauth/invalid_token_response_spec.rb +4 -4
  51. data/spec/lib/oauth/password_access_token_request_spec.rb +10 -9
  52. data/spec/lib/oauth/pre_authorization_spec.rb +20 -8
  53. data/spec/lib/oauth/refresh_token_request_spec.rb +10 -10
  54. data/spec/lib/oauth/scopes_spec.rb +14 -14
  55. data/spec/lib/oauth/token_request_spec.rb +9 -9
  56. data/spec/lib/oauth/token_response_spec.rb +5 -5
  57. data/spec/lib/oauth/token_spec.rb +5 -5
  58. data/spec/lib/option_spec.rb +1 -1
  59. data/spec/lib/request/strategy_spec.rb +34 -37
  60. data/spec/lib/secret_storing/base_spec.rb +3 -2
  61. data/spec/lib/secret_storing/bcrypt_spec.rb +2 -1
  62. data/spec/lib/secret_storing/plain_spec.rb +2 -1
  63. data/spec/lib/secret_storing/sha256_hash_spec.rb +2 -1
  64. data/spec/models/doorkeeper/access_grant_spec.rb +7 -9
  65. data/spec/models/doorkeeper/access_token_spec.rb +20 -26
  66. data/spec/models/doorkeeper/application_spec.rb +83 -26
  67. data/spec/requests/applications/applications_request_spec.rb +91 -93
  68. data/spec/requests/endpoints/authorization_spec.rb +1 -1
  69. data/spec/requests/endpoints/token_spec.rb +22 -16
  70. data/spec/requests/flows/authorization_code_errors_spec.rb +12 -8
  71. data/spec/requests/flows/authorization_code_spec.rb +108 -79
  72. data/spec/requests/flows/client_credentials_spec.rb +57 -45
  73. data/spec/requests/flows/implicit_grant_spec.rb +4 -4
  74. data/spec/requests/flows/password_spec.rb +253 -213
  75. data/spec/requests/flows/refresh_token_spec.rb +53 -39
  76. data/spec/requests/flows/revoke_token_spec.rb +24 -24
  77. data/spec/requests/flows/skip_authorization_spec.rb +1 -1
  78. data/spec/requests/protected_resources/metal_spec.rb +2 -2
  79. data/spec/routing/custom_controller_routes_spec.rb +1 -1
  80. data/spec/routing/default_routes_spec.rb +1 -1
  81. data/spec/routing/scoped_routes_spec.rb +1 -1
  82. data/spec/support/helpers/request_spec_helper.rb +1 -13
  83. data/spec/support/helpers/url_helper.rb +2 -2
  84. data/spec/support/shared/controllers_shared_context.rb +5 -38
  85. data/spec/support/shared/hashing_shared_context.rb +4 -0
  86. data/spec/support/shared/models_shared_examples.rb +6 -6
  87. metadata +13 -10
@@ -2,127 +2,125 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- feature "Adding applications" do
6
- context "in application form" do
7
- background do
8
- i_am_logged_in
9
- visit "/oauth/applications/new"
10
- end
5
+ feature "Adding applications in application form" do
6
+ background do
7
+ i_am_logged_in
8
+ visit "/oauth/applications/new"
9
+ end
11
10
 
12
- scenario "adding a valid app" do
13
- fill_in "doorkeeper_application[name]", with: "My Application"
14
- fill_in "doorkeeper_application[redirect_uri]",
15
- with: "https://example.com"
11
+ scenario "adding a valid app" do
12
+ fill_in "doorkeeper_application[name]", with: "My Application"
13
+ fill_in "doorkeeper_application[redirect_uri]",
14
+ with: "https://example.com"
16
15
 
17
- click_button "Submit"
18
- i_should_see "Application created"
19
- i_should_see "My Application"
20
- end
16
+ click_button "Submit"
17
+ i_should_see "Application created"
18
+ i_should_see "My Application"
19
+ end
21
20
 
22
- scenario "adding invalid app" do
23
- click_button "Submit"
24
- i_should_see "Whoops! Check your form for possible errors"
25
- end
21
+ scenario "adding invalid app" do
22
+ click_button "Submit"
23
+ i_should_see "Whoops! Check your form for possible errors"
24
+ end
26
25
 
27
- scenario "adding app ignoring bad scope" do
28
- config_is_set("enforce_configured_scopes", false)
26
+ scenario "adding app ignoring bad scope" do
27
+ config_is_set("enforce_configured_scopes", false)
29
28
 
30
- fill_in "doorkeeper_application[name]", with: "My Application"
31
- fill_in "doorkeeper_application[redirect_uri]",
32
- with: "https://example.com"
33
- fill_in "doorkeeper_application[scopes]", with: "blahblah"
29
+ fill_in "doorkeeper_application[name]", with: "My Application"
30
+ fill_in "doorkeeper_application[redirect_uri]",
31
+ with: "https://example.com"
32
+ fill_in "doorkeeper_application[scopes]", with: "blahblah"
34
33
 
35
- click_button "Submit"
36
- i_should_see "Application created"
37
- i_should_see "My Application"
38
- end
34
+ click_button "Submit"
35
+ i_should_see "Application created"
36
+ i_should_see "My Application"
37
+ end
39
38
 
40
- scenario "adding app validating bad scope" do
41
- config_is_set("enforce_configured_scopes", true)
39
+ scenario "adding app validating bad scope" do
40
+ config_is_set("enforce_configured_scopes", true)
42
41
 
43
- fill_in "doorkeeper_application[name]", with: "My Application"
44
- fill_in "doorkeeper_application[redirect_uri]",
45
- with: "https://example.com"
46
- fill_in "doorkeeper_application[scopes]", with: "blahblah"
42
+ fill_in "doorkeeper_application[name]", with: "My Application"
43
+ fill_in "doorkeeper_application[redirect_uri]",
44
+ with: "https://example.com"
45
+ fill_in "doorkeeper_application[scopes]", with: "blahblah"
47
46
 
48
- click_button "Submit"
49
- i_should_see "Whoops! Check your form for possible errors"
50
- end
47
+ click_button "Submit"
48
+ i_should_see "Whoops! Check your form for possible errors"
49
+ end
51
50
 
52
- scenario "adding app validating scope, blank scope is accepted" do
53
- config_is_set("enforce_configured_scopes", true)
51
+ scenario "adding app validating scope, blank scope is accepted" do
52
+ config_is_set("enforce_configured_scopes", true)
54
53
 
55
- fill_in "doorkeeper_application[name]", with: "My Application"
56
- fill_in "doorkeeper_application[redirect_uri]",
57
- with: "https://example.com"
58
- fill_in "doorkeeper_application[scopes]", with: ""
54
+ fill_in "doorkeeper_application[name]", with: "My Application"
55
+ fill_in "doorkeeper_application[redirect_uri]",
56
+ with: "https://example.com"
57
+ fill_in "doorkeeper_application[scopes]", with: ""
59
58
 
60
- click_button "Submit"
61
- i_should_see "Application created"
62
- i_should_see "My Application"
63
- end
59
+ click_button "Submit"
60
+ i_should_see "Application created"
61
+ i_should_see "My Application"
62
+ end
64
63
 
65
- scenario "adding app validating scope, multiple scopes configured" do
66
- config_is_set("enforce_configured_scopes", true)
67
- scopes = Doorkeeper::OAuth::Scopes.from_array(%w[read write admin])
68
- config_is_set("optional_scopes", scopes)
64
+ scenario "adding app validating scope, multiple scopes configured" do
65
+ config_is_set("enforce_configured_scopes", true)
66
+ scopes = Doorkeeper::OAuth::Scopes.from_array(%w[read write admin])
67
+ config_is_set("optional_scopes", scopes)
69
68
 
70
- fill_in "doorkeeper_application[name]", with: "My Application"
71
- fill_in "doorkeeper_application[redirect_uri]",
72
- with: "https://example.com"
73
- fill_in "doorkeeper_application[scopes]", with: "read write"
69
+ fill_in "doorkeeper_application[name]", with: "My Application"
70
+ fill_in "doorkeeper_application[redirect_uri]",
71
+ with: "https://example.com"
72
+ fill_in "doorkeeper_application[scopes]", with: "read write"
74
73
 
75
- click_button "Submit"
76
- i_should_see "Application created"
77
- i_should_see "My Application"
78
- end
74
+ click_button "Submit"
75
+ i_should_see "Application created"
76
+ i_should_see "My Application"
77
+ end
78
+
79
+ scenario "adding app validating scope, bad scope with multiple scopes configured" do
80
+ config_is_set("enforce_configured_scopes", true)
81
+ scopes = Doorkeeper::OAuth::Scopes.from_array(%w[read write admin])
82
+ config_is_set("optional_scopes", scopes)
83
+
84
+ fill_in "doorkeeper_application[name]", with: "My Application"
85
+ fill_in "doorkeeper_application[redirect_uri]",
86
+ with: "https://example.com"
87
+ fill_in "doorkeeper_application[scopes]", with: "read blah"
88
+
89
+ click_button "Submit"
90
+ i_should_see "Whoops! Check your form for possible errors"
91
+ i_should_see Regexp.new(
92
+ I18n.t("activerecord.errors.models.doorkeeper/application.attributes.scopes.not_match_configured"),
93
+ true,
94
+ )
95
+ end
79
96
 
80
- scenario "adding app validating scope, bad scope with multiple scopes configured" do
81
- config_is_set("enforce_configured_scopes", true)
82
- scopes = Doorkeeper::OAuth::Scopes.from_array(%w[read write admin])
83
- config_is_set("optional_scopes", scopes)
97
+ context "with blank redirect URI" do
98
+ scenario "adding app with blank redirect URI when configured flows requires redirect uri" do
99
+ config_is_set("grant_flows", %w[authorization_code implicit client_credentials])
84
100
 
85
101
  fill_in "doorkeeper_application[name]", with: "My Application"
86
102
  fill_in "doorkeeper_application[redirect_uri]",
87
- with: "https://example.com"
88
- fill_in "doorkeeper_application[scopes]", with: "read blah"
103
+ with: ""
89
104
 
90
105
  click_button "Submit"
91
106
  i_should_see "Whoops! Check your form for possible errors"
92
- i_should_see Regexp.new(
93
- I18n.t("activerecord.errors.models.doorkeeper/application.attributes.scopes.not_match_configured"),
94
- true,
95
- )
96
107
  end
97
108
 
98
- context "redirect URI" do
99
- scenario "adding app with blank redirect URI when configured flows requires redirect uri" do
100
- config_is_set("grant_flows", %w[authorization_code implicit client_credentials])
101
-
102
- fill_in "doorkeeper_application[name]", with: "My Application"
103
- fill_in "doorkeeper_application[redirect_uri]",
104
- with: ""
109
+ scenario "adding app with blank redirect URI when configured flows without redirect uri" do
110
+ config_is_set("grant_flows", %w[client_credentials password])
105
111
 
106
- click_button "Submit"
107
- i_should_see "Whoops! Check your form for possible errors"
108
- end
109
-
110
- scenario "adding app with blank redirect URI when configured flows without redirect uri" do
111
- config_is_set("grant_flows", %w[client_credentials password])
112
-
113
- # Visit it once again to consider grant flows
114
- visit "/oauth/applications/new"
112
+ # Visit it once again to consider grant flows
113
+ visit "/oauth/applications/new"
115
114
 
116
- i_should_see I18n.t("doorkeeper.applications.help.blank_redirect_uri")
115
+ i_should_see I18n.t("doorkeeper.applications.help.blank_redirect_uri")
117
116
 
118
- fill_in "doorkeeper_application[name]", with: "My Application"
119
- fill_in "doorkeeper_application[redirect_uri]",
120
- with: ""
117
+ fill_in "doorkeeper_application[name]", with: "My Application"
118
+ fill_in "doorkeeper_application[redirect_uri]",
119
+ with: ""
121
120
 
122
- click_button "Submit"
123
- i_should_see "Application created"
124
- i_should_see "My Application"
125
- end
121
+ click_button "Submit"
122
+ i_should_see "Application created"
123
+ i_should_see "My Application"
126
124
  end
127
125
  end
128
126
  end
@@ -70,7 +70,7 @@ feature "Authorization endpoint" do
70
70
  end
71
71
  end
72
72
 
73
- context "forgery protection enabled" do
73
+ context "when forgery protection enabled" do
74
74
  background do
75
75
  create_resource_owner
76
76
  sign_in
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- describe "Token endpoint" do
5
+ RSpec.describe "Token endpoint" do
6
6
  before do
7
7
  client_exists
8
8
  create_resource_owner
@@ -34,46 +34,52 @@ describe "Token endpoint" do
34
34
  },
35
35
  headers: { "HTTP_AUTHORIZATION" => basic_auth_header_for_client(@client) }
36
36
 
37
- should_have_json "access_token", Doorkeeper::AccessToken.first.token
37
+ expect(json_response).to include("access_token" => Doorkeeper::AccessToken.first.token)
38
38
  end
39
39
 
40
40
  it "returns null for expires_in when a permanent token is set" do
41
41
  config_is_set(:access_token_expires_in, nil)
42
+
42
43
  post token_endpoint_url(code: @authorization.token, client: @client)
43
- should_have_json "access_token", Doorkeeper::AccessToken.first.token
44
- should_not_have_json "expires_in"
44
+
45
+ expect(json_response).to include("access_token" => Doorkeeper::AccessToken.first.token)
46
+ expect(json_response).not_to include("expires_in")
45
47
  end
46
48
 
47
49
  it "returns unsupported_grant_type for invalid grant_type param" do
48
50
  post token_endpoint_url(code: @authorization.token, client: @client, grant_type: "nothing")
49
51
 
50
- should_not_have_json "access_token"
51
- should_have_json "error", "unsupported_grant_type"
52
- should_have_json "error_description", translated_error_message("unsupported_grant_type")
52
+ expect(json_response).to match(
53
+ "error" => "unsupported_grant_type",
54
+ "error_description" => translated_error_message("unsupported_grant_type"),
55
+ )
53
56
  end
54
57
 
55
58
  it "returns unsupported_grant_type for disabled grant flows" do
56
59
  config_is_set(:grant_flows, ["implicit"])
57
60
  post token_endpoint_url(code: @authorization.token, client: @client, grant_type: "authorization_code")
58
61
 
59
- should_not_have_json "access_token"
60
- should_have_json "error", "unsupported_grant_type"
61
- should_have_json "error_description", translated_error_message("unsupported_grant_type")
62
+ expect(json_response).to match(
63
+ "error" => "unsupported_grant_type",
64
+ "error_description" => translated_error_message("unsupported_grant_type"),
65
+ )
62
66
  end
63
67
 
64
68
  it "returns unsupported_grant_type when refresh_token is not in use" do
65
69
  post token_endpoint_url(code: @authorization.token, client: @client, grant_type: "refresh_token")
66
70
 
67
- should_not_have_json "access_token"
68
- should_have_json "error", "unsupported_grant_type"
69
- should_have_json "error_description", translated_error_message("unsupported_grant_type")
71
+ expect(json_response).to match(
72
+ "error" => "unsupported_grant_type",
73
+ "error_description" => translated_error_message("unsupported_grant_type"),
74
+ )
70
75
  end
71
76
 
72
77
  it "returns invalid_request if grant_type is missing" do
73
78
  post token_endpoint_url(code: @authorization.token, client: @client, grant_type: "")
74
79
 
75
- should_not_have_json "access_token"
76
- should_have_json "error", "invalid_request"
77
- should_have_json "error_description", translated_invalid_request_error_message(:missing_param, :grant_type)
80
+ expect(json_response).to match(
81
+ "error" => "invalid_request",
82
+ "error_description" => translated_invalid_request_error_message(:missing_param, :grant_type),
83
+ )
78
84
  end
79
85
  end
@@ -4,6 +4,7 @@ require "spec_helper"
4
4
 
5
5
  feature "Authorization Code Flow Errors" do
6
6
  let(:client_params) { {} }
7
+
7
8
  background do
8
9
  default_scopes_exist :default
9
10
  config_is_set(:authenticate_resource_owner) { User.first || redirect_to("/sign_in") }
@@ -19,6 +20,7 @@ feature "Authorization Code Flow Errors" do
19
20
  context "with a client trying to xss resource owner" do
20
21
  let(:client_name) { "<div id='xss'>XSS</div>" }
21
22
  let(:client_params) { { name: client_name } }
23
+
22
24
  scenario "resource owner visit authorization endpoint" do
23
25
  visit authorization_endpoint_url(client: @client)
24
26
  expect(page).not_to have_css("#xss")
@@ -47,7 +49,7 @@ feature "Authorization Code Flow Errors" do
47
49
  end
48
50
  end
49
51
 
50
- describe "Authorization Code Flow Errors", "after authorization" do
52
+ RSpec.describe "Authorization Code Flow Errors after authorization" do
51
53
  before do
52
54
  client_exists
53
55
  create_resource_owner
@@ -63,11 +65,12 @@ describe "Authorization Code Flow Errors", "after authorization" do
63
65
  # Second attempt with same token
64
66
  expect do
65
67
  post token_endpoint_url(code: @authorization.token, client: @client)
66
- end.to_not(change { Doorkeeper::AccessToken.count })
68
+ end.not_to(change { Doorkeeper::AccessToken.count })
67
69
 
68
- should_not_have_json "access_token"
69
- should_have_json "error", "invalid_grant"
70
- should_have_json "error_description", translated_error_message("invalid_grant")
70
+ expect(json_response).to match(
71
+ "error" => "invalid_grant",
72
+ "error_description" => translated_error_message("invalid_grant"),
73
+ )
71
74
  end
72
75
 
73
76
  it "returns :invalid_grant error for invalid grant code" do
@@ -75,8 +78,9 @@ describe "Authorization Code Flow Errors", "after authorization" do
75
78
 
76
79
  access_token_should_not_exist
77
80
 
78
- should_not_have_json "access_token"
79
- should_have_json "error", "invalid_grant"
80
- should_have_json "error_description", translated_error_message("invalid_grant")
81
+ expect(json_response).to match(
82
+ "error" => "invalid_grant",
83
+ "error_description" => translated_error_message("invalid_grant"),
84
+ )
81
85
  end
82
86
  end
@@ -49,11 +49,13 @@ feature "Authorization Code Flow" do
49
49
 
50
50
  access_token_should_exist_for(@client, @resource_owner)
51
51
 
52
- should_not_have_json "error"
53
-
54
- should_have_json "access_token", Doorkeeper::AccessToken.first.token
55
- should_have_json "token_type", "Bearer"
56
- should_have_json_within "expires_in", Doorkeeper::AccessToken.first.expires_in, 1
52
+ expect(json_response).to match(
53
+ "access_token" => Doorkeeper::AccessToken.first.token,
54
+ "token_type" => "Bearer",
55
+ "expires_in" => 7200,
56
+ "scope" => "default",
57
+ "created_at" => an_instance_of(Integer),
58
+ )
57
59
  end
58
60
  end
59
61
 
@@ -124,8 +126,10 @@ feature "Authorization Code Flow" do
124
126
 
125
127
  expect(Doorkeeper::AccessToken.count).to be_zero
126
128
 
127
- should_have_json "error", "invalid_request"
128
- should_have_json "error_description", translated_invalid_request_error_message(:missing_param, :code)
129
+ expect(json_response).to match(
130
+ "error" => "invalid_request",
131
+ "error_description" => translated_invalid_request_error_message(:missing_param, :code),
132
+ )
129
133
  end
130
134
 
131
135
  scenario "resource owner requests an access token with authorization code" do
@@ -137,11 +141,13 @@ feature "Authorization Code Flow" do
137
141
 
138
142
  access_token_should_exist_for(@client, @resource_owner)
139
143
 
140
- should_not_have_json "error"
141
-
142
- should_have_json "access_token", Doorkeeper::AccessToken.first.token
143
- should_have_json "token_type", "Bearer"
144
- should_have_json_within "expires_in", Doorkeeper::AccessToken.first.expires_in, 1
144
+ expect(json_response).to match(
145
+ "access_token" => Doorkeeper::AccessToken.first.token,
146
+ "token_type" => "Bearer",
147
+ "expires_in" => 7200,
148
+ "scope" => "default",
149
+ "created_at" => an_instance_of(Integer),
150
+ )
145
151
  end
146
152
 
147
153
  scenario "resource owner requests an access token with authorization code but without secret" do
@@ -156,8 +162,10 @@ feature "Authorization Code Flow" do
156
162
 
157
163
  expect(Doorkeeper::AccessToken.count).to be_zero
158
164
 
159
- should_have_json "error", "invalid_client"
160
- should_have_json "error_description", translated_error_message(:invalid_client)
165
+ expect(json_response).to match(
166
+ "error" => "invalid_client",
167
+ "error_description" => translated_error_message(:invalid_client),
168
+ )
161
169
  end
162
170
 
163
171
  scenario "resource owner requests an access token with authorization code but without client id" do
@@ -172,8 +180,10 @@ feature "Authorization Code Flow" do
172
180
 
173
181
  expect(Doorkeeper::AccessToken.count).to be_zero
174
182
 
175
- should_have_json "error", "invalid_client"
176
- should_have_json "error_description", translated_error_message(:invalid_client)
183
+ expect(json_response).to match(
184
+ "error" => "invalid_client",
185
+ "error_description" => translated_error_message(:invalid_client),
186
+ )
177
187
  end
178
188
 
179
189
  scenario "silently authorizes if matching token exists" do
@@ -192,7 +202,7 @@ feature "Authorization Code Flow" do
192
202
  end
193
203
 
194
204
  context "with PKCE" do
195
- context "plain" do
205
+ context "when plain" do
196
206
  let(:code_challenge) { "a45a9fea-0676-477e-95b1-a40f72ac3cfb" }
197
207
  let(:code_verifier) { "a45a9fea-0676-477e-95b1-a40f72ac3cfb" }
198
208
 
@@ -216,8 +226,10 @@ feature "Authorization Code Flow" do
216
226
  authorization_code = current_params["code"]
217
227
  create_access_token authorization_code, @client, code_verifier
218
228
 
219
- should_have_json "error", "invalid_grant"
220
- should_have_json "error_description", translated_error_message(:invalid_grant)
229
+ expect(json_response).to match(
230
+ "error" => "invalid_grant",
231
+ "error_description" => translated_error_message(:invalid_grant),
232
+ )
221
233
  end
222
234
 
223
235
  scenario "mobile app requests an access token with authorization code and plain code challenge method" do
@@ -233,11 +245,13 @@ feature "Authorization Code Flow" do
233
245
 
234
246
  access_token_should_exist_for(@client, @resource_owner)
235
247
 
236
- should_not_have_json "error"
237
-
238
- should_have_json "access_token", Doorkeeper::AccessToken.first.token
239
- should_have_json "token_type", "Bearer"
240
- should_have_json_within "expires_in", Doorkeeper::AccessToken.first.expires_in, 1
248
+ expect(json_response).to match(
249
+ "access_token" => Doorkeeper::AccessToken.first.token,
250
+ "token_type" => "Bearer",
251
+ "expires_in" => 7200,
252
+ "scope" => "default",
253
+ "created_at" => an_instance_of(Integer),
254
+ )
241
255
  end
242
256
 
243
257
  scenario "mobile app requests an access token with authorization code but without code_verifier" do
@@ -251,9 +265,10 @@ feature "Authorization Code Flow" do
251
265
  authorization_code = current_params["code"]
252
266
  create_access_token authorization_code, @client, nil
253
267
 
254
- should_not_have_json "access_token"
255
- should_have_json "error", "invalid_request"
256
- should_have_json "error_description", translated_invalid_request_error_message(:missing_param, :code_verifier)
268
+ expect(json_response).to match(
269
+ "error" => "invalid_request",
270
+ "error_description" => translated_invalid_request_error_message(:missing_param, :code_verifier),
271
+ )
257
272
  end
258
273
 
259
274
  scenario "mobile app requests an access token with authorization code with wrong code_verifier" do
@@ -267,13 +282,15 @@ feature "Authorization Code Flow" do
267
282
  authorization_code = current_params["code"]
268
283
  create_access_token authorization_code, @client, "wrong_code_verifier"
269
284
 
270
- should_not_have_json "access_token"
271
- should_have_json "error", "invalid_grant"
272
- should_have_json "error_description", translated_error_message(:invalid_grant)
285
+ expect(json_response).not_to include("access_token")
286
+ expect(json_response).to match(
287
+ "error" => "invalid_grant",
288
+ "error_description" => translated_error_message(:invalid_grant),
289
+ )
273
290
  end
274
291
  end
275
292
 
276
- context "s256" do
293
+ context "when S256" do
277
294
  let(:code_challenge) { "Oz733NtQ0rJP8b04fgZMJMwprn6Iw8sMCT_9bR1q4tA" }
278
295
  let(:code_verifier) { "a45a9fea-0676-477e-95b1-a40f72ac3cfb" }
279
296
 
@@ -303,11 +320,13 @@ feature "Authorization Code Flow" do
303
320
 
304
321
  access_token_should_exist_for(@client, @resource_owner)
305
322
 
306
- should_not_have_json "error"
307
-
308
- should_have_json "access_token", Doorkeeper::AccessToken.first.token
309
- should_have_json "token_type", "Bearer"
310
- should_have_json_within "expires_in", Doorkeeper::AccessToken.first.expires_in, 1
323
+ expect(json_response).to match(
324
+ "access_token" => Doorkeeper::AccessToken.first.token,
325
+ "token_type" => "Bearer",
326
+ "expires_in" => 7200,
327
+ "scope" => "default",
328
+ "created_at" => an_instance_of(Integer),
329
+ )
311
330
  end
312
331
 
313
332
  scenario "mobile app requests an access token with authorization code and without secret" do
@@ -325,9 +344,11 @@ feature "Authorization Code Flow" do
325
344
  redirect_uri: @client.redirect_uri,
326
345
  code_verifier: code_verifier,
327
346
  )
328
- should_not_have_json "access_token"
329
- should_have_json "error", "invalid_client"
330
- should_have_json "error_description", translated_error_message(:invalid_client)
347
+
348
+ expect(json_response).to match(
349
+ "error" => "invalid_client",
350
+ "error_description" => translated_error_message(:invalid_client),
351
+ )
331
352
  end
332
353
 
333
354
  scenario "mobile app requests an access token with authorization code and without secret but is marked as not confidential" do
@@ -342,11 +363,14 @@ feature "Authorization Code Flow" do
342
363
  redirect_uri: @client.redirect_uri,
343
364
  code_verifier: code_verifier,
344
365
  )
345
- should_not_have_json "error"
346
366
 
347
- should_have_json "access_token", Doorkeeper::AccessToken.first.token
348
- should_have_json "token_type", "Bearer"
349
- should_have_json_within "expires_in", Doorkeeper::AccessToken.first.expires_in, 1
367
+ expect(json_response).to match(
368
+ "access_token" => Doorkeeper::AccessToken.first.token,
369
+ "token_type" => "Bearer",
370
+ "expires_in" => 7200,
371
+ "scope" => "default",
372
+ "created_at" => an_instance_of(Integer),
373
+ )
350
374
  end
351
375
 
352
376
  scenario "mobile app requests an access token with authorization code but no code verifier" do
@@ -360,9 +384,11 @@ feature "Authorization Code Flow" do
360
384
  authorization_code = current_params["code"]
361
385
  create_access_token authorization_code, @client
362
386
 
363
- should_not_have_json "access_token"
364
- should_have_json "error", "invalid_request"
365
- should_have_json "error_description", translated_invalid_request_error_message(:missing_param, :code_verifier)
387
+ expect(json_response).not_to include("access_token")
388
+ expect(json_response).to match(
389
+ "error" => "invalid_request",
390
+ "error_description" => translated_invalid_request_error_message(:missing_param, :code_verifier),
391
+ )
366
392
  end
367
393
 
368
394
  scenario "mobile app requests an access token with authorization code with wrong verifier" do
@@ -376,12 +402,13 @@ feature "Authorization Code Flow" do
376
402
  authorization_code = current_params["code"]
377
403
  create_access_token authorization_code, @client, "incorrect-code-verifier"
378
404
 
379
- should_not_have_json "access_token"
380
- should_have_json "error", "invalid_grant"
381
- should_have_json "error_description", translated_error_message(:invalid_grant)
405
+ expect(json_response).to match(
406
+ "error" => "invalid_grant",
407
+ "error_description" => translated_error_message(:invalid_grant),
408
+ )
382
409
  end
383
410
 
384
- scenario "code_challenge_mehthod in token request is totally ignored" do
411
+ scenario "code_challenge_methhod in token request is totally ignored" do
385
412
  visit authorization_endpoint_url(
386
413
  client: @client,
387
414
  code_challenge: code_challenge,
@@ -397,9 +424,10 @@ feature "Authorization Code Flow" do
397
424
  code_challenge_method: "plain",
398
425
  )
399
426
 
400
- should_not_have_json "access_token"
401
- should_have_json "error", "invalid_grant"
402
- should_have_json "error_description", translated_error_message(:invalid_grant)
427
+ expect(json_response).to match(
428
+ "error" => "invalid_grant",
429
+ "error_description" => translated_error_message(:invalid_grant),
430
+ )
403
431
  end
404
432
 
405
433
  scenario "expects to set code_challenge_method explicitely without fallback" do
@@ -477,7 +505,7 @@ feature "Authorization Code Flow" do
477
505
 
478
506
  expect(Doorkeeper::AccessToken.count).to be(2)
479
507
 
480
- should_have_json "access_token", Doorkeeper::AccessToken.last.token
508
+ expect(json_response).to include("access_token" => Doorkeeper::AccessToken.last.token)
481
509
  end
482
510
 
483
511
  scenario "resource owner authorizes the client with extra scopes" do
@@ -490,41 +518,42 @@ feature "Authorization Code Flow" do
490
518
 
491
519
  expect(Doorkeeper::AccessToken.count).to be(2)
492
520
 
493
- should_have_json "access_token", Doorkeeper::AccessToken.last.token
521
+ expect(json_response).to include("access_token" => Doorkeeper::AccessToken.last.token)
494
522
  access_token_should_have_scopes :public, :write
495
523
  end
496
524
  end
497
- end
498
525
 
499
- describe "Authorization Code Flow" do
500
- before do
501
- Doorkeeper.configure do
502
- orm DOORKEEPER_ORM
503
- use_refresh_token
504
- end
526
+ context "when two requests sent" do
527
+ before do
528
+ Doorkeeper.configure do
529
+ orm DOORKEEPER_ORM
530
+ use_refresh_token
531
+ end
505
532
 
506
- client_exists
507
- end
533
+ client_exists
534
+ end
508
535
 
509
- context "issuing a refresh token" do
510
- let(:resource_owner) { FactoryBot.create(:resource_owner) }
536
+ describe "issuing a refresh token" do
537
+ let(:resource_owner) { FactoryBot.create(:resource_owner) }
511
538
 
512
- before do
513
- authorization_code_exists application: @client,
514
- resource_owner_id: resource_owner.id,
515
- resource_owner_type: resource_owner.class.name
516
- end
539
+ before do
540
+ authorization_code_exists application: @client,
541
+ resource_owner_id: resource_owner.id,
542
+ resource_owner_type: resource_owner.class.name
543
+ end
517
544
 
518
- it "second of simultaneous client requests get an error for revoked acccess token" do
519
- authorization_code = Doorkeeper::AccessGrant.first.token
520
- allow_any_instance_of(Doorkeeper::AccessGrant)
521
- .to receive(:revoked?).and_return(false, true)
545
+ it "second of simultaneous client requests get an error for revoked access token" do
546
+ authorization_code = Doorkeeper::AccessGrant.first.token
547
+ allow_any_instance_of(Doorkeeper::AccessGrant)
548
+ .to receive(:revoked?).and_return(false, true)
522
549
 
523
- post token_endpoint_url(code: authorization_code, client: @client)
550
+ page.driver.post token_endpoint_url(code: authorization_code, client: @client)
524
551
 
525
- should_not_have_json "access_token"
526
- should_have_json "error", "invalid_grant"
527
- should_have_json "error_description", translated_error_message(:invalid_grant)
552
+ expect(json_response).to match(
553
+ "error" => "invalid_grant",
554
+ "error_description" => translated_error_message(:invalid_grant),
555
+ )
556
+ end
528
557
  end
529
558
  end
530
559
  end