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.
- checksums.yaml +4 -4
- data/lib/doorkeeper-mongodb.rb +1 -0
- data/lib/doorkeeper-mongodb/mixins/mongoid/access_grant_mixin.rb +1 -0
- data/lib/doorkeeper-mongodb/mixins/mongoid/access_token_mixin.rb +1 -0
- data/lib/doorkeeper-mongodb/mixins/mongoid/application_mixin.rb +76 -0
- data/lib/doorkeeper-mongodb/mixins/mongoid/base_mixin.rb +0 -8
- data/lib/doorkeeper-mongodb/mixins/mongoid/json_serializable.rb +17 -0
- data/lib/doorkeeper-mongodb/version.rb +1 -1
- data/spec/controllers/application_metal_controller_spec.rb +4 -4
- data/spec/controllers/applications_controller_spec.rb +198 -202
- data/spec/controllers/authorizations_controller_spec.rb +32 -31
- data/spec/controllers/protected_resources_controller_spec.rb +10 -10
- data/spec/controllers/token_info_controller_spec.rb +1 -1
- data/spec/controllers/tokens_controller_spec.rb +105 -62
- data/spec/doorkeeper/redirect_uri_validator_spec.rb +183 -0
- data/spec/{lib → doorkeeper}/server_spec.rb +5 -4
- data/spec/{lib → doorkeeper}/stale_records_cleaner_spec.rb +8 -7
- data/spec/{version → doorkeeper}/version_spec.rb +3 -3
- data/spec/dummy/log/test.log +4220 -4184
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{eS/eSL1QMz46gKLM0GR6S9fL6uyARPxOImcappZ9_ZtSyg.cache → Pm/PmheG0PGFqDws1qgFOxOyIL-gpMof3Ar9eSRKVLYuik.cache} +0 -0
- data/spec/grape/grape_integration_spec.rb +1 -1
- data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +1 -1
- data/spec/lib/config_spec.rb +23 -12
- data/spec/lib/doorkeeper_spec.rb +4 -4
- data/spec/lib/models/expirable_spec.rb +9 -9
- data/spec/lib/models/reusable_spec.rb +2 -2
- data/spec/lib/models/revocable_spec.rb +4 -7
- data/spec/lib/models/scopes_spec.rb +7 -7
- data/spec/lib/models/secret_storable_spec.rb +9 -8
- data/spec/lib/oauth/authorization/uri_builder_spec.rb +23 -27
- data/spec/lib/oauth/authorization_code_request_spec.rb +6 -6
- data/spec/lib/oauth/base_request_spec.rb +11 -27
- data/spec/lib/oauth/base_response_spec.rb +2 -2
- data/spec/lib/oauth/client/credentials_spec.rb +25 -25
- data/spec/lib/oauth/client_credentials/creator_spec.rb +89 -91
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +84 -86
- data/spec/lib/oauth/client_credentials/validation_spec.rb +72 -39
- data/spec/lib/oauth/client_credentials_integration_spec.rb +5 -5
- data/spec/lib/oauth/client_credentials_request_spec.rb +7 -10
- data/spec/lib/oauth/client_spec.rb +8 -8
- data/spec/lib/oauth/code_request_spec.rb +5 -5
- data/spec/lib/oauth/code_response_spec.rb +4 -4
- data/spec/lib/oauth/error_response_spec.rb +6 -5
- data/spec/lib/oauth/error_spec.rb +1 -1
- data/spec/lib/oauth/forbidden_token_response_spec.rb +2 -2
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +37 -37
- data/spec/lib/oauth/helpers/unique_token_spec.rb +2 -2
- data/spec/lib/oauth/helpers/uri_checker_spec.rb +54 -54
- data/spec/lib/oauth/invalid_request_response_spec.rb +6 -6
- data/spec/lib/oauth/invalid_token_response_spec.rb +4 -4
- data/spec/lib/oauth/password_access_token_request_spec.rb +10 -9
- data/spec/lib/oauth/pre_authorization_spec.rb +20 -8
- data/spec/lib/oauth/refresh_token_request_spec.rb +10 -10
- data/spec/lib/oauth/scopes_spec.rb +14 -14
- data/spec/lib/oauth/token_request_spec.rb +9 -9
- data/spec/lib/oauth/token_response_spec.rb +5 -5
- data/spec/lib/oauth/token_spec.rb +5 -5
- data/spec/lib/option_spec.rb +1 -1
- data/spec/lib/request/strategy_spec.rb +34 -37
- data/spec/lib/secret_storing/base_spec.rb +3 -2
- data/spec/lib/secret_storing/bcrypt_spec.rb +2 -1
- data/spec/lib/secret_storing/plain_spec.rb +2 -1
- data/spec/lib/secret_storing/sha256_hash_spec.rb +2 -1
- data/spec/models/doorkeeper/access_grant_spec.rb +7 -9
- data/spec/models/doorkeeper/access_token_spec.rb +20 -26
- data/spec/models/doorkeeper/application_spec.rb +83 -26
- data/spec/requests/applications/applications_request_spec.rb +91 -93
- data/spec/requests/endpoints/authorization_spec.rb +1 -1
- data/spec/requests/endpoints/token_spec.rb +22 -16
- data/spec/requests/flows/authorization_code_errors_spec.rb +12 -8
- data/spec/requests/flows/authorization_code_spec.rb +108 -79
- data/spec/requests/flows/client_credentials_spec.rb +57 -45
- data/spec/requests/flows/implicit_grant_spec.rb +4 -4
- data/spec/requests/flows/password_spec.rb +253 -213
- data/spec/requests/flows/refresh_token_spec.rb +53 -39
- data/spec/requests/flows/revoke_token_spec.rb +24 -24
- data/spec/requests/flows/skip_authorization_spec.rb +1 -1
- data/spec/requests/protected_resources/metal_spec.rb +2 -2
- data/spec/routing/custom_controller_routes_spec.rb +1 -1
- data/spec/routing/default_routes_spec.rb +1 -1
- data/spec/routing/scoped_routes_spec.rb +1 -1
- data/spec/support/helpers/request_spec_helper.rb +1 -13
- data/spec/support/helpers/url_helper.rb +2 -2
- data/spec/support/shared/controllers_shared_context.rb +5 -38
- data/spec/support/shared/hashing_shared_context.rb +4 -0
- data/spec/support/shared/models_shared_examples.rb +6 -6
- metadata +13 -10
@@ -2,127 +2,125 @@
|
|
2
2
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
|
-
feature "Adding applications" do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
click_button "Submit"
|
17
|
+
i_should_see "Application created"
|
18
|
+
i_should_see "My Application"
|
19
|
+
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
28
|
-
|
26
|
+
scenario "adding app ignoring bad scope" do
|
27
|
+
config_is_set("enforce_configured_scopes", false)
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
click_button "Submit"
|
35
|
+
i_should_see "Application created"
|
36
|
+
i_should_see "My Application"
|
37
|
+
end
|
39
38
|
|
40
|
-
|
41
|
-
|
39
|
+
scenario "adding app validating bad scope" do
|
40
|
+
config_is_set("enforce_configured_scopes", true)
|
42
41
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
47
|
+
click_button "Submit"
|
48
|
+
i_should_see "Whoops! Check your form for possible errors"
|
49
|
+
end
|
51
50
|
|
52
|
-
|
53
|
-
|
51
|
+
scenario "adding app validating scope, blank scope is accepted" do
|
52
|
+
config_is_set("enforce_configured_scopes", true)
|
54
53
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
59
|
+
click_button "Submit"
|
60
|
+
i_should_see "Application created"
|
61
|
+
i_should_see "My Application"
|
62
|
+
end
|
64
63
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
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
|
-
|
81
|
-
|
82
|
-
|
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: "
|
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
|
-
|
99
|
-
|
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
|
-
|
107
|
-
|
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
|
-
|
115
|
+
i_should_see I18n.t("doorkeeper.applications.help.blank_redirect_uri")
|
117
116
|
|
118
|
-
|
119
|
-
|
120
|
-
|
117
|
+
fill_in "doorkeeper_application[name]", with: "My Application"
|
118
|
+
fill_in "doorkeeper_application[redirect_uri]",
|
119
|
+
with: ""
|
121
120
|
|
122
|
-
|
123
|
-
|
124
|
-
|
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
|
@@ -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
|
-
|
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
|
-
|
44
|
-
|
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
|
-
|
51
|
-
|
52
|
-
|
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
|
-
|
60
|
-
|
61
|
-
|
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
|
-
|
68
|
-
|
69
|
-
|
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
|
-
|
76
|
-
|
77
|
-
|
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
|
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.
|
68
|
+
end.not_to(change { Doorkeeper::AccessToken.count })
|
67
69
|
|
68
|
-
|
69
|
-
|
70
|
-
|
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
|
-
|
79
|
-
|
80
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
128
|
-
|
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
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
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
|
-
|
160
|
-
|
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
|
-
|
176
|
-
|
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
|
-
|
220
|
-
|
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
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
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
|
-
|
255
|
-
|
256
|
-
|
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
|
-
|
271
|
-
|
272
|
-
|
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 "
|
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
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
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
|
-
|
329
|
-
|
330
|
-
|
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
|
-
|
348
|
-
|
349
|
-
|
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
|
-
|
364
|
-
|
365
|
-
|
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
|
-
|
380
|
-
|
381
|
-
|
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 "
|
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
|
-
|
401
|
-
|
402
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
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
|
-
|
507
|
-
|
533
|
+
client_exists
|
534
|
+
end
|
508
535
|
|
509
|
-
|
510
|
-
|
536
|
+
describe "issuing a refresh token" do
|
537
|
+
let(:resource_owner) { FactoryBot.create(:resource_owner) }
|
511
538
|
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
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
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
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
|
-
|
550
|
+
page.driver.post token_endpoint_url(code: authorization_code, client: @client)
|
524
551
|
|
525
|
-
|
526
|
-
|
527
|
-
|
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
|