doorkeeper-mongodb 5.2.1 → 5.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -27
- data/lib/doorkeeper/orm/concerns/mongoid/ownership.rb +1 -1
- data/lib/doorkeeper/orm/concerns/mongoid/resource_ownerable.rb +1 -1
- data/lib/doorkeeper/orm/mongoid4.rb +18 -0
- data/lib/doorkeeper/orm/mongoid5.rb +18 -0
- data/lib/doorkeeper/orm/mongoid6.rb +18 -0
- data/lib/doorkeeper/orm/mongoid7.rb +18 -0
- data/lib/doorkeeper-mongodb/mixins/mongoid/access_grant_mixin.rb +7 -6
- data/lib/doorkeeper-mongodb/mixins/mongoid/access_token_mixin.rb +8 -5
- data/lib/doorkeeper-mongodb/mixins/mongoid/application_mixin.rb +82 -5
- 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/lib/doorkeeper-mongodb.rb +1 -0
- 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/app/assets/config/manifest.js +0 -0
- data/spec/dummy/app/controllers/application_controller.rb +0 -0
- data/spec/dummy/app/controllers/custom_authorizations_controller.rb +0 -0
- data/spec/dummy/app/controllers/full_protected_resources_controller.rb +0 -0
- data/spec/dummy/app/controllers/home_controller.rb +0 -0
- data/spec/dummy/app/controllers/metal_controller.rb +0 -0
- data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +0 -0
- data/spec/dummy/app/models/user.rb +0 -1
- data/spec/dummy/app/views/home/index.html.erb +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +0 -0
- data/spec/dummy/config/application.rb +0 -0
- data/spec/dummy/config/boot.rb +0 -0
- data/spec/dummy/config/database.yml +0 -0
- data/spec/dummy/config/environment.rb +0 -0
- data/spec/dummy/config/environments/development.rb +0 -0
- data/spec/dummy/config/environments/production.rb +0 -0
- data/spec/dummy/config/environments/test.rb +0 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -0
- data/spec/dummy/config/initializers/doorkeeper.rb +0 -0
- data/spec/dummy/config/initializers/secret_token.rb +0 -0
- data/spec/dummy/config/initializers/session_store.rb +0 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -0
- data/spec/dummy/config/locales/doorkeeper.en.yml +0 -0
- data/spec/dummy/config/mongo.yml +2 -2
- data/spec/dummy/config/routes.rb +0 -0
- data/spec/dummy/config.ru +0 -0
- data/spec/dummy/db/migrate/20111122132257_create_users.rb +0 -0
- data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +0 -0
- data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +0 -0
- data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +0 -0
- data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +0 -0
- data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +0 -0
- data/spec/dummy/db/migrate/20180210183654_add_confidential_to_applications.rb +0 -0
- data/spec/dummy/db/schema.rb +0 -0
- data/spec/dummy/public/404.html +0 -0
- data/spec/dummy/public/422.html +0 -0
- data/spec/dummy/public/500.html +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/-o/-ofn45zIfO5vx4VD6m6NXesLf6da5usA-Sbw2SVju3o.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/0_/0_ouGcG_o_1zmVmBe-tdQYk594LBwVa1bumjrKtdfEw.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/2X/2XMMcHbyTSRqh1GkV0xzyIETNtt-zgN6iniziShaKmQ.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/4Q/4QQw-pMQ98JIj3xdcFhGBQdysdGPY9rWffRqWMmyjew.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/7H/7HjRsym0tTpXFCVhWt6kteMs_-CozKVbr9s5syHm8es.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/8B/8BxJyv22HPFHu1se_l2J8qW1N9NzZ16UOWOy1YMSgs4.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/8D/8DJG7JfPvShfLLyeSom6NZ_TcQc6QH27tJ7prEWZPfI.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/9x/9xjtGv-yKjj62x9uFwBZg8pTSh9ERPAgANwNo9uwIaA.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Bt/BtXO7f0PZ8DNt3TMLYM-zY7LkbWa_KgyB0v1V98M1CQ.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/E0/E02f1Q2tutWumMulGCFNfqQNjvEP_hMAK_5E83eWepI.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/EZ/EZGpd6pUEJZxO6uT2yIS4Fpn5KX7VDgC9VB3AaemF5Q.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/FJ/FJlQpfMtpRbrM5P8A7d2FAelFKwo6GrVs2xks8z5GKU.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/L8/L8mOWakJlWKr6MU85rj0V7yGFfNyIR6vE6YXtqArPGw.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Lk/LklIq5hrBAPESXVUpFMwQ9L-1qTj90sPVi6U19_Xi-Q.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/MB/MBWRxa9S470ee8suxVKp0jYgv6K6FQOqKGV0kPGQNMs.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Ma/MaK3K1AoZZ4xM5fOOifhROd73hfZJpP4yGbkGdoYtEk.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/PA/PAH_jI20wRw12tngeJ-V619c30avNLDu5U9Z-9Pc5SQ.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Ph/Ph7RtH_NvG2I8XpTa8mA8SBQXZDzBPVIh4CH6g7OXJ0.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{eS/eSL1QMz46gKLM0GR6S9fL6uyARPxOImcappZ9_ZtSyg.cache → Pm/PmheG0PGFqDws1qgFOxOyIL-gpMof3Ar9eSRKVLYuik.cache} +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Pn/PnXU_mkG2fLZFm9BwiZ03BZdBTjKuInP-cRXjHS7yJo.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Qs/QsVgO6vM5Yn9oeYTYlrqtyVnK6sdVDWDa083N7zpfHw.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/So/So59ksdx2dw-_A3-zFZ6Palr7fROjm7_0JDZb04temw.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Wt/WtXL_iDofLeTH_v0Yf3PM421r9b1V0g-VBvMPeu9KA0.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/b6/b6QRH6ZdCc0e6bUWu4qni_kZmptaMgWciO8Jl9q6_p8.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/dX/dX6FDdUIy8yBCOoaoXcjf71rX9N_bpiXGJ4Urt32NTk.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/jC/jCTZ1jAldKBn4OTANBBmCKzxLrDgok1ur4meoTqlDNg.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/qT/qTQIQsmS0Wbbg2JxNn9rxdI5qVOTg5SfyQdaTvr9vLo.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/yN/yNOFGOsnHmxXNMkuEAWuL1u3jlmdvrdeoTx6DDJ1in8.cache +0 -0
- data/spec/factories.rb +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/applications/authorized_applications_spec.rb +0 -0
- 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_errors_spec.rb +0 -0
- 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/requests/protected_resources/private_api_spec.rb +0 -0
- 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/spec_helper.rb +0 -0
- data/spec/spec_helper_integration.rb +0 -0
- data/spec/support/dependencies/factory_bot.rb +0 -0
- data/spec/support/doorkeeper_rspec.rb +0 -0
- data/spec/support/helpers/access_token_request_helper.rb +0 -0
- data/spec/support/helpers/authorization_request_helper.rb +0 -0
- data/spec/support/helpers/config_helper.rb +0 -0
- data/spec/support/helpers/model_helper.rb +0 -0
- data/spec/support/helpers/request_spec_helper.rb +1 -13
- data/spec/support/helpers/url_helper.rb +2 -2
- data/spec/support/orm/active_record.rb +0 -0
- data/spec/support/orm/mongoid4.rb +1 -1
- data/spec/support/orm/mongoid5.rb +1 -1
- data/spec/support/orm/mongoid6.rb +1 -1
- data/spec/support/orm/mongoid7.rb +1 -1
- 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 +154 -167
- data/spec/dummy/log/test.log +0 -6108
@@ -2,315 +2,355 @@
|
|
2
2
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
|
-
describe "Resource Owner Password Credentials Flow
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
RSpec.describe "Resource Owner Password Credentials Flow" do
|
6
|
+
context "when not setup properly" do
|
7
|
+
before do
|
8
|
+
client_exists
|
9
|
+
create_resource_owner
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
context "with valid user credentials" do
|
13
|
+
it "does not issue new token" do
|
14
|
+
expect do
|
15
|
+
post password_token_endpoint_url(client: @client, resource_owner: @resource_owner)
|
16
|
+
end.not_to(change { Doorkeeper::AccessToken.count })
|
17
|
+
end
|
16
18
|
end
|
17
19
|
end
|
18
|
-
end
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
context "when grant type configured" do
|
22
|
+
let(:client_attributes) { { redirect_uri: nil } }
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
before do
|
25
|
+
config_is_set(:grant_flows, ["password"])
|
26
|
+
config_is_set(:resource_owner_from_credentials) { User.authenticate! params[:username], params[:password] }
|
27
|
+
client_exists(client_attributes)
|
28
|
+
create_resource_owner
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
context "with valid user credentials" do
|
32
|
+
context "with confidential client authorized using Basic auth" do
|
33
|
+
it "issues a new token" do
|
34
|
+
expect do
|
35
|
+
post password_token_endpoint_url(
|
36
|
+
resource_owner: @resource_owner,
|
37
|
+
), headers: { "HTTP_AUTHORIZATION" => basic_auth_header_for_client(@client) }
|
38
|
+
end.to(change { Doorkeeper::AccessToken.count })
|
33
39
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
40
|
+
token = Doorkeeper::AccessToken.first
|
41
|
+
expect(token.application_id).to eq(@client.id)
|
42
|
+
|
43
|
+
expect(json_response).to match(
|
44
|
+
"access_token" => token.token,
|
45
|
+
"expires_in" => an_instance_of(Integer),
|
46
|
+
"token_type" => "Bearer",
|
47
|
+
"created_at" => an_instance_of(Integer),
|
39
48
|
)
|
40
49
|
end
|
50
|
+
end
|
41
51
|
|
42
|
-
|
43
|
-
|
52
|
+
context "with non-confidential/public client" do
|
53
|
+
let(:client_attributes) { { confidential: false } }
|
44
54
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
55
|
+
context "when configured to check application supported grant flow" do
|
56
|
+
before do
|
57
|
+
Doorkeeper.configuration.instance_variable_set(
|
58
|
+
:@allow_grant_flow_for_client,
|
59
|
+
->(_grant_flow, client) { client.name == "admin" },
|
50
60
|
)
|
51
|
-
end
|
61
|
+
end
|
52
62
|
|
53
|
-
|
54
|
-
|
55
|
-
|
63
|
+
scenario "forbids the request when doesn't satisfy condition" do
|
64
|
+
@client.update(name: "sample app")
|
65
|
+
|
66
|
+
expect do
|
67
|
+
post password_token_endpoint_url(
|
68
|
+
client_id: @client.uid,
|
69
|
+
client_secret: "foobar",
|
70
|
+
resource_owner: @resource_owner,
|
71
|
+
)
|
72
|
+
end.not_to(change { Doorkeeper::AccessToken.count })
|
56
73
|
|
57
|
-
|
58
|
-
|
74
|
+
expect(response.status).to eq(401)
|
75
|
+
expect(json_response).to match(
|
76
|
+
"error" => "invalid_client",
|
77
|
+
"error_description" => an_instance_of(String),
|
78
|
+
)
|
79
|
+
end
|
59
80
|
|
60
|
-
|
61
|
-
|
62
|
-
end.to change { Doorkeeper::AccessToken.count }.by(1)
|
81
|
+
scenario "allows the request when satisfies condition" do
|
82
|
+
@client.update(name: "admin")
|
63
83
|
|
64
|
-
|
84
|
+
expect do
|
85
|
+
post password_token_endpoint_url(client_id: @client.uid, resource_owner: @resource_owner)
|
86
|
+
end.to change { Doorkeeper::AccessToken.count }.by(1)
|
87
|
+
|
88
|
+
token = Doorkeeper::AccessToken.first
|
89
|
+
expect(token.application_id).to eq(@client.id)
|
65
90
|
|
66
|
-
|
67
|
-
|
91
|
+
expect(json_response).to include("access_token" => token.token)
|
92
|
+
end
|
68
93
|
end
|
69
|
-
end
|
70
94
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
95
|
+
context "when client_secret absent" do
|
96
|
+
it "issues a new token" do
|
97
|
+
expect do
|
98
|
+
post password_token_endpoint_url(client_id: @client.uid, resource_owner: @resource_owner)
|
99
|
+
end.to change { Doorkeeper::AccessToken.count }.by(1)
|
76
100
|
|
77
|
-
|
101
|
+
token = Doorkeeper::AccessToken.first
|
78
102
|
|
79
|
-
|
80
|
-
|
103
|
+
expect(token.application_id).to eq(@client.id)
|
104
|
+
expect(json_response).to include("access_token" => token.token)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "when client_secret present" do
|
109
|
+
it "issues a new token" do
|
110
|
+
expect do
|
111
|
+
post password_token_endpoint_url(client: @client, resource_owner: @resource_owner)
|
112
|
+
end.to change { Doorkeeper::AccessToken.count }.by(1)
|
113
|
+
|
114
|
+
token = Doorkeeper::AccessToken.first
|
115
|
+
|
116
|
+
expect(token.application_id).to eq(@client.id)
|
117
|
+
expect(json_response).to include("access_token" => token.token)
|
118
|
+
end
|
119
|
+
|
120
|
+
context "when client_secret incorrect" do
|
121
|
+
it "doesn't issue new token" do
|
122
|
+
expect do
|
123
|
+
post password_token_endpoint_url(
|
124
|
+
client_id: @client.uid,
|
125
|
+
client_secret: "foobar",
|
126
|
+
resource_owner: @resource_owner,
|
127
|
+
)
|
128
|
+
end.not_to(change { Doorkeeper::AccessToken.count })
|
129
|
+
|
130
|
+
expect(response.status).to eq(401)
|
131
|
+
expect(json_response).to include(
|
132
|
+
"error" => "invalid_client",
|
133
|
+
"error_description" => an_instance_of(String),
|
134
|
+
)
|
135
|
+
end
|
136
|
+
end
|
81
137
|
end
|
82
138
|
end
|
83
139
|
|
84
|
-
context "
|
85
|
-
it "
|
140
|
+
context "with confidential/private client" do
|
141
|
+
it "issues a new token" do
|
86
142
|
expect do
|
87
143
|
post password_token_endpoint_url(client: @client, resource_owner: @resource_owner)
|
88
144
|
end.to change { Doorkeeper::AccessToken.count }.by(1)
|
89
145
|
|
90
146
|
token = Doorkeeper::AccessToken.first
|
91
147
|
|
92
|
-
expect(token.application_id).to eq
|
93
|
-
|
148
|
+
expect(token.application_id).to eq(@client.id)
|
149
|
+
expect(json_response).to include("access_token" => token.token)
|
94
150
|
end
|
95
151
|
|
96
|
-
context "when client_secret
|
97
|
-
it "
|
152
|
+
context "when client_secret absent" do
|
153
|
+
it "doesn't issue new token" do
|
98
154
|
expect do
|
99
|
-
post password_token_endpoint_url(
|
100
|
-
client_id: @client.uid,
|
101
|
-
client_secret: "foobar",
|
102
|
-
resource_owner: @resource_owner,
|
103
|
-
)
|
155
|
+
post password_token_endpoint_url(client_id: @client.uid, resource_owner: @resource_owner)
|
104
156
|
end.not_to(change { Doorkeeper::AccessToken.count })
|
105
157
|
|
106
158
|
expect(response.status).to eq(401)
|
107
|
-
|
159
|
+
expect(json_response).to match(
|
160
|
+
"error" => "invalid_client",
|
161
|
+
"error_description" => an_instance_of(String),
|
162
|
+
)
|
108
163
|
end
|
109
164
|
end
|
110
165
|
end
|
111
|
-
end
|
112
166
|
|
113
|
-
|
114
|
-
it "should issue new token" do
|
167
|
+
it "issues new token without client credentials" do
|
115
168
|
expect do
|
116
|
-
post password_token_endpoint_url(
|
117
|
-
end.to
|
169
|
+
post password_token_endpoint_url(resource_owner: @resource_owner)
|
170
|
+
end.to(change { Doorkeeper::AccessToken.count }.by(1))
|
118
171
|
|
119
172
|
token = Doorkeeper::AccessToken.first
|
120
173
|
|
121
|
-
expect(token.application_id).to
|
122
|
-
|
123
|
-
end
|
124
|
-
|
125
|
-
context "when client_secret absent" do
|
126
|
-
it "should not issue new token" do
|
127
|
-
expect do
|
128
|
-
post password_token_endpoint_url(client_id: @client.uid, resource_owner: @resource_owner)
|
129
|
-
end.not_to(change { Doorkeeper::AccessToken.count })
|
130
|
-
|
131
|
-
expect(response.status).to eq(401)
|
132
|
-
should_have_json "error", "invalid_client"
|
133
|
-
end
|
174
|
+
expect(token.application_id).to be_nil
|
175
|
+
expect(json_response).to include("access_token" => token.token)
|
134
176
|
end
|
135
|
-
end
|
136
177
|
|
137
|
-
|
138
|
-
|
139
|
-
post password_token_endpoint_url(resource_owner: @resource_owner)
|
140
|
-
end.to(change { Doorkeeper::AccessToken.count }.by(1))
|
178
|
+
it "issues a refresh token if enabled" do
|
179
|
+
config_is_set(:refresh_token_enabled, true)
|
141
180
|
|
142
|
-
|
181
|
+
post password_token_endpoint_url(client: @client, resource_owner: @resource_owner)
|
143
182
|
|
144
|
-
|
145
|
-
|
146
|
-
|
183
|
+
token = Doorkeeper::AccessToken.first
|
184
|
+
expect(json_response).to include("refresh_token" => token.refresh_token)
|
185
|
+
end
|
147
186
|
|
148
|
-
|
149
|
-
|
187
|
+
it "returns the same token if it is still accessible" do
|
188
|
+
allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(true)
|
150
189
|
|
151
|
-
|
190
|
+
client_is_authorized(@client, @resource_owner)
|
152
191
|
|
153
|
-
|
192
|
+
post password_token_endpoint_url(client: @client, resource_owner: @resource_owner)
|
154
193
|
|
155
|
-
|
156
|
-
|
194
|
+
expect(Doorkeeper::AccessToken.count).to be(1)
|
195
|
+
expect(json_response).to include("access_token" => Doorkeeper::AccessToken.first.token)
|
196
|
+
end
|
157
197
|
|
158
|
-
|
159
|
-
|
198
|
+
context "with valid, default scope" do
|
199
|
+
before do
|
200
|
+
default_scopes_exist :public
|
201
|
+
end
|
160
202
|
|
161
|
-
|
203
|
+
it "issues new token" do
|
204
|
+
expect do
|
205
|
+
post password_token_endpoint_url(client: @client, resource_owner: @resource_owner, scope: "public")
|
206
|
+
end.to change { Doorkeeper::AccessToken.count }.by(1)
|
162
207
|
|
163
|
-
|
208
|
+
token = Doorkeeper::AccessToken.first
|
164
209
|
|
165
|
-
|
166
|
-
|
210
|
+
expect(token.application_id).to eq(@client.id)
|
211
|
+
expect(json_response).to include(
|
212
|
+
"access_token" => token.token,
|
213
|
+
"scope" => "public",
|
214
|
+
)
|
215
|
+
end
|
216
|
+
end
|
167
217
|
end
|
168
218
|
|
169
|
-
context "
|
219
|
+
context "when application scopes are present and differs from configured default scopes and no scope is passed" do
|
170
220
|
before do
|
171
221
|
default_scopes_exist :public
|
222
|
+
@client.update(scopes: "abc")
|
172
223
|
end
|
173
224
|
|
174
|
-
it "
|
225
|
+
it "issues new token without any scope" do
|
175
226
|
expect do
|
176
|
-
post password_token_endpoint_url(client: @client, resource_owner: @resource_owner
|
227
|
+
post password_token_endpoint_url(client: @client, resource_owner: @resource_owner)
|
177
228
|
end.to change { Doorkeeper::AccessToken.count }.by(1)
|
178
229
|
|
179
230
|
token = Doorkeeper::AccessToken.first
|
180
231
|
|
181
|
-
expect(token.application_id).to eq
|
182
|
-
|
183
|
-
|
232
|
+
expect(token.application_id).to eq(@client.id)
|
233
|
+
expect(token.scopes).to be_empty
|
234
|
+
expect(json_response).to include("access_token" => token.token)
|
235
|
+
expect(json_response).not_to include("scope")
|
184
236
|
end
|
185
237
|
end
|
186
|
-
end
|
187
238
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
end
|
239
|
+
context "when application scopes contain some of the default scopes and no scope is passed" do
|
240
|
+
before do
|
241
|
+
@client.update(scopes: "read write public")
|
242
|
+
end
|
193
243
|
|
194
|
-
|
195
|
-
|
196
|
-
post password_token_endpoint_url(client: @client, resource_owner: @resource_owner)
|
197
|
-
end.to change { Doorkeeper::AccessToken.count }.by(1)
|
244
|
+
it "issues new token with one default scope that are present in application scopes" do
|
245
|
+
default_scopes_exist :public, :admin
|
198
246
|
|
199
|
-
|
247
|
+
expect do
|
248
|
+
post password_token_endpoint_url(client: @client, resource_owner: @resource_owner)
|
249
|
+
end.to change { Doorkeeper::AccessToken.count }.by(1)
|
200
250
|
|
201
|
-
|
202
|
-
expect(token.scopes).to be_empty
|
203
|
-
should_have_json "access_token", token.token
|
204
|
-
should_not_have_json "scope"
|
205
|
-
end
|
206
|
-
end
|
251
|
+
token = Doorkeeper::AccessToken.first
|
207
252
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
253
|
+
expect(token.application_id).to eq(@client.id)
|
254
|
+
expect(json_response).to include(
|
255
|
+
"access_token" => token.token,
|
256
|
+
"scope" => "public",
|
257
|
+
)
|
258
|
+
end
|
212
259
|
|
213
|
-
|
214
|
-
|
260
|
+
it "issues new token with multiple default scopes that are present in application scopes" do
|
261
|
+
default_scopes_exist :public, :read, :update
|
215
262
|
|
216
|
-
|
217
|
-
|
218
|
-
|
263
|
+
expect do
|
264
|
+
post password_token_endpoint_url(client: @client, resource_owner: @resource_owner)
|
265
|
+
end.to change { Doorkeeper::AccessToken.count }.by(1)
|
219
266
|
|
220
|
-
|
267
|
+
token = Doorkeeper::AccessToken.first
|
221
268
|
|
222
|
-
|
223
|
-
|
224
|
-
|
269
|
+
expect(token.application_id).to eq(@client.id)
|
270
|
+
expect(json_response).to include(
|
271
|
+
"access_token" => token.token,
|
272
|
+
"scope" => "public read",
|
273
|
+
)
|
274
|
+
end
|
225
275
|
end
|
226
276
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
277
|
+
context "with invalid scopes" do
|
278
|
+
subject do
|
279
|
+
post password_token_endpoint_url(
|
280
|
+
client: @client,
|
281
|
+
resource_owner: @resource_owner,
|
282
|
+
scope: "random",
|
283
|
+
)
|
284
|
+
end
|
235
285
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
end
|
240
|
-
end
|
286
|
+
it "doesn't issue new token" do
|
287
|
+
expect { subject }.not_to(change { Doorkeeper::AccessToken.count })
|
288
|
+
end
|
241
289
|
|
242
|
-
|
243
|
-
|
244
|
-
post password_token_endpoint_url(
|
245
|
-
client: @client,
|
246
|
-
resource_owner: @resource_owner,
|
247
|
-
scope: "random",
|
248
|
-
)
|
249
|
-
end
|
290
|
+
it "returns invalid_scope error" do
|
291
|
+
subject
|
250
292
|
|
251
|
-
|
252
|
-
|
253
|
-
|
293
|
+
expect(json_response).to include(
|
294
|
+
"error" => "invalid_scope",
|
295
|
+
"error_description" => translated_error_message(:invalid_scope),
|
296
|
+
)
|
254
297
|
|
255
|
-
|
256
|
-
subject
|
257
|
-
should_have_json "error", "invalid_scope"
|
258
|
-
should_have_json "error_description", translated_error_message(:invalid_scope)
|
259
|
-
should_not_have_json "access_token"
|
298
|
+
expect(json_response).not_to include("access_token")
|
260
299
|
|
261
|
-
|
300
|
+
expect(response.status).to eq(400)
|
301
|
+
end
|
262
302
|
end
|
263
|
-
end
|
264
303
|
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
304
|
+
context "with invalid user credentials" do
|
305
|
+
it "doesn't issue new token with bad password" do
|
306
|
+
expect do
|
307
|
+
post password_token_endpoint_url(
|
308
|
+
client: @client,
|
309
|
+
resource_owner_username: @resource_owner.name,
|
310
|
+
resource_owner_password: "wrongpassword",
|
311
|
+
)
|
312
|
+
end.not_to(change { Doorkeeper::AccessToken.count })
|
313
|
+
end
|
275
314
|
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
315
|
+
it "doesn't issue new token without credentials" do
|
316
|
+
expect do
|
317
|
+
post password_token_endpoint_url(client: @client)
|
318
|
+
end.not_to(change { Doorkeeper::AccessToken.count })
|
319
|
+
end
|
281
320
|
|
282
|
-
|
283
|
-
|
321
|
+
it "doesn't issue new token if resource_owner_from_credentials returned false or nil" do
|
322
|
+
config_is_set(:resource_owner_from_credentials) { false }
|
284
323
|
|
285
|
-
|
286
|
-
|
287
|
-
|
324
|
+
expect do
|
325
|
+
post password_token_endpoint_url(client: @client)
|
326
|
+
end.not_to(change { Doorkeeper::AccessToken.count })
|
288
327
|
|
289
|
-
|
328
|
+
config_is_set(:resource_owner_from_credentials) { nil }
|
290
329
|
|
291
|
-
|
292
|
-
|
293
|
-
|
330
|
+
expect do
|
331
|
+
post password_token_endpoint_url(client: @client)
|
332
|
+
end.not_to(change { Doorkeeper::AccessToken.count })
|
333
|
+
end
|
294
334
|
end
|
295
|
-
end
|
296
335
|
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
336
|
+
context "with invalid confidential client credentials" do
|
337
|
+
it "doesn't issue new token with bad client credentials" do
|
338
|
+
expect do
|
339
|
+
post password_token_endpoint_url(
|
340
|
+
client_id: @client.uid,
|
341
|
+
client_secret: "bad_secret",
|
342
|
+
resource_owner: @resource_owner,
|
343
|
+
)
|
344
|
+
end.not_to(change { Doorkeeper::AccessToken.count })
|
345
|
+
end
|
306
346
|
end
|
307
|
-
end
|
308
347
|
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
348
|
+
context "with invalid public client id" do
|
349
|
+
it "doesn't issue new token with bad client id" do
|
350
|
+
expect do
|
351
|
+
post password_token_endpoint_url(client_id: "bad_id", resource_owner: @resource_owner)
|
352
|
+
end.not_to(change { Doorkeeper::AccessToken.count })
|
353
|
+
end
|
314
354
|
end
|
315
355
|
end
|
316
356
|
end
|