doorkeeper 4.2.5 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE.md +25 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +17 -0
- data/.gitignore +2 -1
- data/.gitlab-ci.yml +16 -0
- data/.hound.yml +2 -13
- data/.rubocop.yml +17 -0
- data/.travis.yml +19 -4
- data/Appraisals +8 -4
- data/CODE_OF_CONDUCT.md +46 -0
- data/Gemfile +1 -1
- data/NEWS.md +115 -0
- data/README.md +175 -39
- data/RELEASING.md +5 -12
- data/Rakefile +6 -0
- data/SECURITY.md +15 -0
- data/UPGRADE.md +2 -0
- data/app/assets/stylesheets/doorkeeper/admin/application.css +2 -2
- data/app/controllers/doorkeeper/application_controller.rb +2 -5
- data/app/controllers/doorkeeper/application_metal_controller.rb +4 -0
- data/app/controllers/doorkeeper/applications_controller.rb +47 -13
- data/app/controllers/doorkeeper/authorizations_controller.rb +55 -12
- data/app/controllers/doorkeeper/authorized_applications_controller.rb +19 -2
- data/app/controllers/doorkeeper/tokens_controller.rb +24 -17
- data/app/helpers/doorkeeper/dashboard_helper.rb +8 -6
- data/app/validators/redirect_uri_validator.rb +13 -2
- data/app/views/doorkeeper/applications/_delete_form.html.erb +3 -1
- data/app/views/doorkeeper/applications/_form.html.erb +31 -19
- data/app/views/doorkeeper/applications/edit.html.erb +1 -1
- data/app/views/doorkeeper/applications/index.html.erb +18 -6
- data/app/views/doorkeeper/applications/new.html.erb +1 -1
- data/app/views/doorkeeper/applications/show.html.erb +8 -5
- data/app/views/doorkeeper/authorizations/error.html.erb +1 -1
- data/app/views/doorkeeper/authorizations/new.html.erb +5 -1
- data/app/views/doorkeeper/authorized_applications/index.html.erb +0 -1
- data/app/views/layouts/doorkeeper/admin.html.erb +15 -15
- data/config/locales/en.yml +19 -6
- data/doorkeeper.gemspec +20 -20
- data/gemfiles/rails_4_2.gemfile +6 -4
- data/gemfiles/rails_5_0.gemfile +4 -4
- data/gemfiles/rails_5_1.gemfile +6 -7
- data/gemfiles/rails_5_2.gemfile +12 -0
- data/gemfiles/rails_master.gemfile +17 -0
- data/lib/doorkeeper/config.rb +123 -71
- data/lib/doorkeeper/engine.rb +7 -3
- data/lib/doorkeeper/errors.rb +20 -5
- data/lib/doorkeeper/grape/helpers.rb +14 -9
- data/lib/doorkeeper/helpers/controller.rb +16 -22
- data/lib/doorkeeper/models/access_grant_mixin.rb +67 -23
- data/lib/doorkeeper/models/access_token_mixin.rb +54 -55
- data/lib/doorkeeper/models/application_mixin.rb +16 -30
- data/lib/doorkeeper/models/concerns/expirable.rb +7 -5
- data/lib/doorkeeper/models/concerns/orderable.rb +13 -0
- data/lib/doorkeeper/models/concerns/scopes.rb +1 -1
- data/lib/doorkeeper/oauth/authorization/code.rb +31 -8
- data/lib/doorkeeper/oauth/authorization/context.rb +15 -0
- data/lib/doorkeeper/oauth/authorization/token.rb +46 -20
- data/lib/doorkeeper/oauth/authorization_code_request.rb +33 -3
- data/lib/doorkeeper/oauth/base_request.rb +23 -7
- data/lib/doorkeeper/oauth/client/credentials.rb +6 -4
- data/lib/doorkeeper/oauth/client.rb +2 -4
- data/lib/doorkeeper/oauth/client_credentials/creator.rb +2 -1
- data/lib/doorkeeper/oauth/client_credentials/issuer.rb +6 -3
- data/lib/doorkeeper/oauth/client_credentials/validation.rb +4 -6
- data/lib/doorkeeper/oauth/client_credentials_request.rb +0 -4
- data/lib/doorkeeper/oauth/error.rb +2 -2
- data/lib/doorkeeper/oauth/error_response.rb +11 -4
- data/lib/doorkeeper/oauth/forbidden_token_response.rb +1 -1
- data/lib/doorkeeper/oauth/helpers/scope_checker.rb +0 -8
- data/lib/doorkeeper/oauth/helpers/uri_checker.rb +15 -0
- data/lib/doorkeeper/oauth/invalid_token_response.rb +3 -4
- data/lib/doorkeeper/oauth/password_access_token_request.rb +8 -4
- data/lib/doorkeeper/oauth/pre_authorization.rb +45 -13
- data/lib/doorkeeper/oauth/refresh_token_request.rb +7 -1
- data/lib/doorkeeper/oauth/scopes.rb +19 -9
- data/lib/doorkeeper/oauth/token.rb +6 -3
- data/lib/doorkeeper/oauth/token_introspection.rb +128 -0
- data/lib/doorkeeper/oauth/token_response.rb +4 -2
- data/lib/doorkeeper/oauth.rb +13 -0
- data/lib/doorkeeper/orm/active_record/access_grant.rb +27 -0
- data/lib/doorkeeper/orm/active_record/access_token.rb +21 -20
- data/lib/doorkeeper/orm/active_record/application.rb +45 -0
- data/lib/doorkeeper/orm/active_record/stale_records_cleaner.rb +26 -0
- data/lib/doorkeeper/orm/active_record.rb +21 -8
- data/lib/doorkeeper/rails/helpers.rb +7 -10
- data/lib/doorkeeper/rails/routes.rb +21 -7
- data/lib/doorkeeper/rake/db.rake +40 -0
- data/lib/doorkeeper/rake/setup.rake +6 -0
- data/lib/doorkeeper/rake.rb +14 -0
- data/lib/doorkeeper/request/authorization_code.rb +0 -2
- data/lib/doorkeeper/request/client_credentials.rb +0 -2
- data/lib/doorkeeper/request/code.rb +0 -2
- data/lib/doorkeeper/request/password.rb +1 -13
- data/lib/doorkeeper/request/refresh_token.rb +0 -2
- data/lib/doorkeeper/request/token.rb +0 -2
- data/lib/doorkeeper/request.rb +29 -30
- data/lib/doorkeeper/validations.rb +3 -2
- data/lib/doorkeeper/version.rb +14 -1
- data/lib/doorkeeper.rb +21 -17
- data/lib/generators/doorkeeper/application_owner_generator.rb +26 -12
- data/lib/generators/doorkeeper/confidential_applications_generator.rb +32 -0
- data/lib/generators/doorkeeper/install_generator.rb +17 -9
- data/lib/generators/doorkeeper/migration_generator.rb +26 -9
- data/lib/generators/doorkeeper/pkce_generator.rb +32 -0
- data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +31 -20
- data/lib/generators/doorkeeper/templates/add_confidential_to_applications.rb.erb +13 -0
- data/lib/generators/doorkeeper/templates/{add_owner_to_application_migration.rb → add_owner_to_application_migration.rb.erb} +1 -1
- data/lib/generators/doorkeeper/templates/{add_previous_refresh_token_to_access_tokens.rb → add_previous_refresh_token_to_access_tokens.rb.erb} +1 -1
- data/lib/generators/doorkeeper/templates/enable_pkce_migration.rb.erb +6 -0
- data/lib/generators/doorkeeper/templates/initializer.rb +104 -12
- data/lib/generators/doorkeeper/templates/{migration.rb → migration.rb.erb} +2 -1
- data/lib/generators/doorkeeper/views_generator.rb +3 -1
- data/spec/controllers/application_metal_controller_spec.rb +50 -0
- data/spec/controllers/applications_controller_spec.rb +141 -17
- data/spec/controllers/authorizations_controller_spec.rb +304 -27
- data/spec/controllers/protected_resources_controller_spec.rb +44 -35
- data/spec/controllers/token_info_controller_spec.rb +17 -21
- data/spec/controllers/tokens_controller_spec.rb +201 -17
- data/spec/dummy/app/assets/config/manifest.js +2 -0
- data/spec/dummy/config/environments/test.rb +4 -5
- data/spec/dummy/config/initializers/doorkeeper.rb +23 -2
- data/spec/dummy/config/initializers/{active_record_belongs_to_required_by_default.rb → new_framework_defaults.rb} +5 -1
- data/spec/dummy/config/initializers/secret_token.rb +0 -1
- data/spec/dummy/config/routes.rb +3 -42
- data/spec/dummy/db/migrate/20111122132257_create_users.rb +3 -1
- data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +3 -1
- data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +3 -1
- data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +3 -1
- data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +3 -1
- data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +6 -0
- data/spec/dummy/db/migrate/20180210183654_add_confidential_to_applications.rb +13 -0
- data/spec/dummy/db/schema.rb +38 -37
- data/spec/factories.rb +1 -1
- data/spec/generators/application_owner_generator_spec.rb +25 -6
- data/spec/generators/confidential_applications_generator_spec.rb +45 -0
- data/spec/generators/install_generator_spec.rb +1 -1
- data/spec/generators/migration_generator_spec.rb +25 -4
- data/spec/generators/pkce_generator_spec.rb +43 -0
- data/spec/generators/previous_refresh_token_generator_spec.rb +57 -0
- data/spec/generators/views_generator_spec.rb +1 -1
- data/spec/grape/grape_integration_spec.rb +135 -0
- data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +2 -2
- data/spec/lib/config_spec.rb +199 -22
- data/spec/lib/doorkeeper_spec.rb +1 -126
- data/spec/lib/models/expirable_spec.rb +0 -4
- data/spec/lib/models/revocable_spec.rb +2 -4
- data/spec/lib/models/scopes_spec.rb +0 -4
- data/spec/lib/oauth/authorization/uri_builder_spec.rb +0 -4
- data/spec/lib/oauth/authorization_code_request_spec.rb +63 -13
- data/spec/lib/oauth/base_request_spec.rb +43 -10
- data/spec/lib/oauth/base_response_spec.rb +1 -1
- data/spec/lib/oauth/client/credentials_spec.rb +5 -5
- data/spec/lib/oauth/client_credentials/creator_spec.rb +6 -2
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +26 -7
- data/spec/lib/oauth/client_credentials/validation_spec.rb +2 -3
- data/spec/lib/oauth/client_credentials_integration_spec.rb +2 -2
- data/spec/lib/oauth/client_credentials_request_spec.rb +4 -5
- data/spec/lib/oauth/client_spec.rb +0 -3
- data/spec/lib/oauth/code_request_spec.rb +5 -5
- data/spec/lib/oauth/error_response_spec.rb +0 -3
- data/spec/lib/oauth/error_spec.rb +1 -3
- data/spec/lib/oauth/forbidden_token_response_spec.rb +1 -4
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +0 -3
- data/spec/lib/oauth/helpers/unique_token_spec.rb +0 -1
- data/spec/lib/oauth/helpers/uri_checker_spec.rb +115 -3
- data/spec/lib/oauth/invalid_token_response_spec.rb +2 -5
- data/spec/lib/oauth/password_access_token_request_spec.rb +46 -5
- data/spec/lib/oauth/pre_authorization_spec.rb +40 -6
- data/spec/lib/oauth/refresh_token_request_spec.rb +30 -14
- data/spec/lib/oauth/scopes_spec.rb +28 -4
- data/spec/lib/oauth/token_request_spec.rb +10 -13
- data/spec/lib/oauth/token_response_spec.rb +0 -1
- data/spec/lib/oauth/token_spec.rb +37 -14
- data/spec/lib/orm/active_record/stale_records_cleaner_spec.rb +79 -0
- data/spec/lib/request/strategy_spec.rb +0 -1
- data/spec/lib/server_spec.rb +10 -0
- data/spec/models/doorkeeper/access_grant_spec.rb +45 -2
- data/spec/models/doorkeeper/access_token_spec.rb +132 -64
- data/spec/models/doorkeeper/application_spec.rb +114 -23
- data/spec/requests/applications/applications_request_spec.rb +139 -6
- data/spec/requests/applications/authorized_applications_spec.rb +1 -1
- data/spec/requests/endpoints/authorization_spec.rb +1 -1
- data/spec/requests/endpoints/token_spec.rb +15 -6
- data/spec/requests/flows/authorization_code_errors_spec.rb +12 -2
- data/spec/requests/flows/authorization_code_spec.rb +199 -2
- data/spec/requests/flows/client_credentials_spec.rb +73 -5
- data/spec/requests/flows/implicit_grant_errors_spec.rb +3 -3
- data/spec/requests/flows/implicit_grant_spec.rb +38 -11
- data/spec/requests/flows/password_spec.rb +160 -24
- data/spec/requests/flows/refresh_token_spec.rb +6 -6
- data/spec/requests/flows/revoke_token_spec.rb +26 -26
- data/spec/requests/flows/skip_authorization_spec.rb +16 -11
- data/spec/requests/protected_resources/metal_spec.rb +2 -2
- data/spec/requests/protected_resources/private_api_spec.rb +2 -2
- data/spec/routing/custom_controller_routes_spec.rb +63 -7
- data/spec/routing/default_routes_spec.rb +6 -2
- data/spec/routing/scoped_routes_spec.rb +16 -2
- data/spec/spec_helper.rb +54 -3
- data/spec/spec_helper_integration.rb +2 -64
- data/spec/support/dependencies/factory_bot.rb +2 -0
- data/spec/support/doorkeeper_rspec.rb +19 -0
- data/spec/support/helpers/access_token_request_helper.rb +1 -1
- data/spec/support/helpers/authorization_request_helper.rb +4 -4
- data/spec/support/helpers/model_helper.rb +9 -4
- data/spec/support/helpers/request_spec_helper.rb +18 -6
- data/spec/support/helpers/url_helper.rb +15 -10
- data/spec/support/http_method_shim.rb +12 -16
- data/spec/support/shared/controllers_shared_context.rb +2 -6
- data/spec/support/shared/models_shared_examples.rb +4 -4
- data/spec/validators/redirect_uri_validator_spec.rb +58 -7
- data/spec/version/version_spec.rb +15 -0
- data/vendor/assets/stylesheets/doorkeeper/bootstrap.min.css +4 -5
- metadata +75 -33
- data/spec/controllers/application_metal_controller.rb +0 -10
- data/spec/support/dependencies/factory_girl.rb +0 -2
data/spec/lib/config_spec.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Doorkeeper, 'configuration' do
|
|
4
4
|
subject { Doorkeeper.configuration }
|
|
@@ -10,8 +10,43 @@ describe Doorkeeper, 'configuration' do
|
|
|
10
10
|
orm DOORKEEPER_ORM
|
|
11
11
|
resource_owner_authenticator(&block)
|
|
12
12
|
end
|
|
13
|
+
|
|
13
14
|
expect(subject.authenticate_resource_owner).to eq(block)
|
|
14
15
|
end
|
|
16
|
+
|
|
17
|
+
it 'prints warning message by default' do
|
|
18
|
+
Doorkeeper.configure do
|
|
19
|
+
orm DOORKEEPER_ORM
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
expect(Rails.logger).to receive(:warn).with(
|
|
23
|
+
I18n.t('doorkeeper.errors.messages.resource_owner_authenticator_not_configured')
|
|
24
|
+
)
|
|
25
|
+
subject.authenticate_resource_owner.call(nil)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe 'resource_owner_from_credentials' do
|
|
30
|
+
it 'sets the block that is accessible via authenticate_resource_owner' do
|
|
31
|
+
block = proc {}
|
|
32
|
+
Doorkeeper.configure do
|
|
33
|
+
orm DOORKEEPER_ORM
|
|
34
|
+
resource_owner_from_credentials(&block)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
expect(subject.resource_owner_from_credentials).to eq(block)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'prints warning message by default' do
|
|
41
|
+
Doorkeeper.configure do
|
|
42
|
+
orm DOORKEEPER_ORM
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
expect(Rails.logger).to receive(:warn).with(
|
|
46
|
+
I18n.t('doorkeeper.errors.messages.credential_flow_not_configured')
|
|
47
|
+
)
|
|
48
|
+
subject.resource_owner_from_credentials.call(nil)
|
|
49
|
+
end
|
|
15
50
|
end
|
|
16
51
|
|
|
17
52
|
describe 'setup_orm_adapter' do
|
|
@@ -31,12 +66,24 @@ describe Doorkeeper, 'configuration' do
|
|
|
31
66
|
end
|
|
32
67
|
|
|
33
68
|
describe 'admin_authenticator' do
|
|
69
|
+
it 'sets the block that is accessible via authenticate_admin' do
|
|
70
|
+
default_behaviour = 'default behaviour'
|
|
71
|
+
allow(Doorkeeper::Config).to receive(:head).and_return(default_behaviour)
|
|
72
|
+
|
|
73
|
+
Doorkeeper.configure do
|
|
74
|
+
orm DOORKEEPER_ORM
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
expect(subject.authenticate_admin.call({})).to eq(default_behaviour)
|
|
78
|
+
end
|
|
79
|
+
|
|
34
80
|
it 'sets the block that is accessible via authenticate_admin' do
|
|
35
81
|
block = proc {}
|
|
36
82
|
Doorkeeper.configure do
|
|
37
83
|
orm DOORKEEPER_ORM
|
|
38
84
|
admin_authenticator(&block)
|
|
39
85
|
end
|
|
86
|
+
|
|
40
87
|
expect(subject.authenticate_admin).to eq(block)
|
|
41
88
|
end
|
|
42
89
|
end
|
|
@@ -59,6 +106,7 @@ describe Doorkeeper, 'configuration' do
|
|
|
59
106
|
orm DOORKEEPER_ORM
|
|
60
107
|
access_token_expires_in nil
|
|
61
108
|
end
|
|
109
|
+
|
|
62
110
|
expect(subject.access_token_expires_in).to be_nil
|
|
63
111
|
end
|
|
64
112
|
end
|
|
@@ -69,6 +117,7 @@ describe Doorkeeper, 'configuration' do
|
|
|
69
117
|
orm DOORKEEPER_ORM
|
|
70
118
|
default_scopes :public
|
|
71
119
|
end
|
|
120
|
+
|
|
72
121
|
expect(subject.default_scopes).to include('public')
|
|
73
122
|
end
|
|
74
123
|
|
|
@@ -77,22 +126,24 @@ describe Doorkeeper, 'configuration' do
|
|
|
77
126
|
orm DOORKEEPER_ORM
|
|
78
127
|
optional_scopes :write, :update
|
|
79
128
|
end
|
|
129
|
+
|
|
80
130
|
expect(subject.optional_scopes).to include('write', 'update')
|
|
81
131
|
end
|
|
82
132
|
|
|
83
133
|
it 'has all scopes' do
|
|
84
134
|
Doorkeeper.configure do
|
|
85
135
|
orm DOORKEEPER_ORM
|
|
86
|
-
default_scopes
|
|
136
|
+
default_scopes :normal
|
|
87
137
|
optional_scopes :admin
|
|
88
138
|
end
|
|
139
|
+
|
|
89
140
|
expect(subject.scopes).to include('normal', 'admin')
|
|
90
141
|
end
|
|
91
142
|
end
|
|
92
143
|
|
|
93
144
|
describe 'use_refresh_token' do
|
|
94
145
|
it 'is false by default' do
|
|
95
|
-
expect(subject.refresh_token_enabled?).to
|
|
146
|
+
expect(subject.refresh_token_enabled?).to eq(false)
|
|
96
147
|
end
|
|
97
148
|
|
|
98
149
|
it 'can change the value' do
|
|
@@ -100,7 +151,26 @@ describe Doorkeeper, 'configuration' do
|
|
|
100
151
|
orm DOORKEEPER_ORM
|
|
101
152
|
use_refresh_token
|
|
102
153
|
end
|
|
103
|
-
|
|
154
|
+
|
|
155
|
+
expect(subject.refresh_token_enabled?).to eq(true)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
it 'can accept a boolean parameter' do
|
|
159
|
+
Doorkeeper.configure do
|
|
160
|
+
orm DOORKEEPER_ORM
|
|
161
|
+
use_refresh_token false
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
expect(subject.refresh_token_enabled?).to eq(false)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
it 'can accept a block parameter' do
|
|
168
|
+
Doorkeeper.configure do
|
|
169
|
+
orm DOORKEEPER_ORM
|
|
170
|
+
use_refresh_token { |_context| nil }
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
expect(subject.refresh_token_enabled?).to be_a(Proc)
|
|
104
174
|
end
|
|
105
175
|
|
|
106
176
|
it "does not includes 'refresh_token' in authorization_response_types" do
|
|
@@ -121,6 +191,21 @@ describe Doorkeeper, 'configuration' do
|
|
|
121
191
|
end
|
|
122
192
|
end
|
|
123
193
|
|
|
194
|
+
describe 'enforce_configured_scopes' do
|
|
195
|
+
it 'is false by default' do
|
|
196
|
+
expect(subject.enforce_configured_scopes?).to eq(false)
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
it 'can change the value' do
|
|
200
|
+
Doorkeeper.configure do
|
|
201
|
+
orm DOORKEEPER_ORM
|
|
202
|
+
enforce_configured_scopes
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
expect(subject.enforce_configured_scopes?).to eq(true)
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
|
|
124
209
|
describe 'client_credentials' do
|
|
125
210
|
it 'has defaults order' do
|
|
126
211
|
expect(subject.client_credentials_methods).to eq([:from_basic, :from_params])
|
|
@@ -131,13 +216,14 @@ describe Doorkeeper, 'configuration' do
|
|
|
131
216
|
orm DOORKEEPER_ORM
|
|
132
217
|
client_credentials :from_digest, :from_params
|
|
133
218
|
end
|
|
219
|
+
|
|
134
220
|
expect(subject.client_credentials_methods).to eq([:from_digest, :from_params])
|
|
135
221
|
end
|
|
136
222
|
end
|
|
137
223
|
|
|
138
224
|
describe 'force_ssl_in_redirect_uri' do
|
|
139
225
|
it 'is true by default in non-development environments' do
|
|
140
|
-
expect(subject.force_ssl_in_redirect_uri).to
|
|
226
|
+
expect(subject.force_ssl_in_redirect_uri).to eq(true)
|
|
141
227
|
end
|
|
142
228
|
|
|
143
229
|
it 'can change the value' do
|
|
@@ -145,7 +231,19 @@ describe Doorkeeper, 'configuration' do
|
|
|
145
231
|
orm DOORKEEPER_ORM
|
|
146
232
|
force_ssl_in_redirect_uri(false)
|
|
147
233
|
end
|
|
148
|
-
|
|
234
|
+
|
|
235
|
+
expect(subject.force_ssl_in_redirect_uri).to eq(false)
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
it 'can be a callable object' do
|
|
239
|
+
block = proc { false }
|
|
240
|
+
Doorkeeper.configure do
|
|
241
|
+
orm DOORKEEPER_ORM
|
|
242
|
+
force_ssl_in_redirect_uri(&block)
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
expect(subject.force_ssl_in_redirect_uri).to eq(block)
|
|
246
|
+
expect(subject.force_ssl_in_redirect_uri.call).to eq(false)
|
|
149
247
|
end
|
|
150
248
|
end
|
|
151
249
|
|
|
@@ -159,13 +257,31 @@ describe Doorkeeper, 'configuration' do
|
|
|
159
257
|
orm DOORKEEPER_ORM
|
|
160
258
|
access_token_methods :from_access_token_param, :from_bearer_param
|
|
161
259
|
end
|
|
260
|
+
|
|
162
261
|
expect(subject.access_token_methods).to eq([:from_access_token_param, :from_bearer_param])
|
|
163
262
|
end
|
|
164
263
|
end
|
|
165
264
|
|
|
265
|
+
describe 'forbid_redirect_uri' do
|
|
266
|
+
it 'is false by default' do
|
|
267
|
+
expect(subject.forbid_redirect_uri.call(URI.parse('https://localhost'))).to eq(false)
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
it 'can be a callable object' do
|
|
271
|
+
block = proc { true }
|
|
272
|
+
Doorkeeper.configure do
|
|
273
|
+
orm DOORKEEPER_ORM
|
|
274
|
+
forbid_redirect_uri(&block)
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
expect(subject.forbid_redirect_uri).to eq(block)
|
|
278
|
+
expect(subject.forbid_redirect_uri.call).to eq(true)
|
|
279
|
+
end
|
|
280
|
+
end
|
|
281
|
+
|
|
166
282
|
describe 'enable_application_owner' do
|
|
167
283
|
it 'is disabled by default' do
|
|
168
|
-
expect(Doorkeeper.configuration.enable_application_owner?).not_to
|
|
284
|
+
expect(Doorkeeper.configuration.enable_application_owner?).not_to eq(true)
|
|
169
285
|
end
|
|
170
286
|
|
|
171
287
|
context 'when enabled without confirmation' do
|
|
@@ -175,11 +291,13 @@ describe Doorkeeper, 'configuration' do
|
|
|
175
291
|
enable_application_owner
|
|
176
292
|
end
|
|
177
293
|
end
|
|
294
|
+
|
|
178
295
|
it 'adds support for application owner' do
|
|
179
296
|
expect(Doorkeeper::Application.new).to respond_to :owner
|
|
180
297
|
end
|
|
298
|
+
|
|
181
299
|
it 'Doorkeeper.configuration.confirm_application_owner? returns false' do
|
|
182
|
-
expect(Doorkeeper.configuration.confirm_application_owner?).not_to
|
|
300
|
+
expect(Doorkeeper.configuration.confirm_application_owner?).not_to eq(true)
|
|
183
301
|
end
|
|
184
302
|
end
|
|
185
303
|
|
|
@@ -190,11 +308,13 @@ describe Doorkeeper, 'configuration' do
|
|
|
190
308
|
enable_application_owner confirmation: true
|
|
191
309
|
end
|
|
192
310
|
end
|
|
311
|
+
|
|
193
312
|
it 'adds support for application owner' do
|
|
194
313
|
expect(Doorkeeper::Application.new).to respond_to :owner
|
|
195
314
|
end
|
|
315
|
+
|
|
196
316
|
it 'Doorkeeper.configuration.confirm_application_owner? returns true' do
|
|
197
|
-
expect(Doorkeeper.configuration.confirm_application_owner?).to
|
|
317
|
+
expect(Doorkeeper.configuration.confirm_application_owner?).to eq(true)
|
|
198
318
|
end
|
|
199
319
|
end
|
|
200
320
|
end
|
|
@@ -209,6 +329,7 @@ describe Doorkeeper, 'configuration' do
|
|
|
209
329
|
orm DOORKEEPER_ORM
|
|
210
330
|
realm 'Example'
|
|
211
331
|
end
|
|
332
|
+
|
|
212
333
|
expect(subject.realm).to eq('Example')
|
|
213
334
|
end
|
|
214
335
|
end
|
|
@@ -216,23 +337,24 @@ describe Doorkeeper, 'configuration' do
|
|
|
216
337
|
describe "grant_flows" do
|
|
217
338
|
it "is set to all grant flows by default" do
|
|
218
339
|
expect(Doorkeeper.configuration.grant_flows).
|
|
219
|
-
to eq(%w
|
|
340
|
+
to eq(%w[authorization_code client_credentials])
|
|
220
341
|
end
|
|
221
342
|
|
|
222
343
|
it "can change the value" do
|
|
223
|
-
Doorkeeper.configure
|
|
344
|
+
Doorkeeper.configure do
|
|
224
345
|
orm DOORKEEPER_ORM
|
|
225
|
-
grant_flows [
|
|
226
|
-
|
|
227
|
-
|
|
346
|
+
grant_flows %w[authorization_code implicit]
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
expect(subject.grant_flows).to eq %w[authorization_code implicit]
|
|
228
350
|
end
|
|
229
351
|
|
|
230
352
|
context "when including 'authorization_code'" do
|
|
231
353
|
before do
|
|
232
|
-
Doorkeeper.configure
|
|
354
|
+
Doorkeeper.configure do
|
|
233
355
|
orm DOORKEEPER_ORM
|
|
234
356
|
grant_flows ['authorization_code']
|
|
235
|
-
|
|
357
|
+
end
|
|
236
358
|
end
|
|
237
359
|
|
|
238
360
|
it "includes 'code' in authorization_response_types" do
|
|
@@ -246,10 +368,10 @@ describe Doorkeeper, 'configuration' do
|
|
|
246
368
|
|
|
247
369
|
context "when including 'implicit'" do
|
|
248
370
|
before do
|
|
249
|
-
Doorkeeper.configure
|
|
371
|
+
Doorkeeper.configure do
|
|
250
372
|
orm DOORKEEPER_ORM
|
|
251
373
|
grant_flows ['implicit']
|
|
252
|
-
|
|
374
|
+
end
|
|
253
375
|
end
|
|
254
376
|
|
|
255
377
|
it "includes 'token' in authorization_response_types" do
|
|
@@ -259,10 +381,10 @@ describe Doorkeeper, 'configuration' do
|
|
|
259
381
|
|
|
260
382
|
context "when including 'password'" do
|
|
261
383
|
before do
|
|
262
|
-
Doorkeeper.configure
|
|
384
|
+
Doorkeeper.configure do
|
|
263
385
|
orm DOORKEEPER_ORM
|
|
264
386
|
grant_flows ['password']
|
|
265
|
-
|
|
387
|
+
end
|
|
266
388
|
end
|
|
267
389
|
|
|
268
390
|
it "includes 'password' in token_grant_types" do
|
|
@@ -272,10 +394,10 @@ describe Doorkeeper, 'configuration' do
|
|
|
272
394
|
|
|
273
395
|
context "when including 'client_credentials'" do
|
|
274
396
|
before do
|
|
275
|
-
Doorkeeper.configure
|
|
397
|
+
Doorkeeper.configure do
|
|
276
398
|
orm DOORKEEPER_ORM
|
|
277
399
|
grant_flows ['client_credentials']
|
|
278
|
-
|
|
400
|
+
end
|
|
279
401
|
end
|
|
280
402
|
|
|
281
403
|
it "includes 'client_credentials' in token_grant_types" do
|
|
@@ -331,4 +453,59 @@ describe Doorkeeper, 'configuration' do
|
|
|
331
453
|
it { expect(Doorkeeper.configuration.base_controller).to eq('ApplicationController') }
|
|
332
454
|
end
|
|
333
455
|
end
|
|
456
|
+
|
|
457
|
+
if DOORKEEPER_ORM == :active_record
|
|
458
|
+
describe 'active_record_options' do
|
|
459
|
+
let(:models) { [Doorkeeper::AccessGrant, Doorkeeper::AccessToken, Doorkeeper::Application] }
|
|
460
|
+
|
|
461
|
+
before do
|
|
462
|
+
models.each do |model|
|
|
463
|
+
allow(model).to receive(:establish_connection).and_return(true)
|
|
464
|
+
end
|
|
465
|
+
end
|
|
466
|
+
|
|
467
|
+
it 'establishes connection for Doorkeeper models based on options' do
|
|
468
|
+
models.each do |model|
|
|
469
|
+
expect(model).to receive(:establish_connection)
|
|
470
|
+
end
|
|
471
|
+
|
|
472
|
+
Doorkeeper.configure do
|
|
473
|
+
orm DOORKEEPER_ORM
|
|
474
|
+
active_record_options(
|
|
475
|
+
establish_connection: Rails.configuration.database_configuration[Rails.env]
|
|
476
|
+
)
|
|
477
|
+
end
|
|
478
|
+
end
|
|
479
|
+
end
|
|
480
|
+
end
|
|
481
|
+
|
|
482
|
+
describe "api_only" do
|
|
483
|
+
it "is false by default" do
|
|
484
|
+
expect(subject.api_only).to eq(false)
|
|
485
|
+
end
|
|
486
|
+
|
|
487
|
+
it "can change the value" do
|
|
488
|
+
Doorkeeper.configure do
|
|
489
|
+
orm DOORKEEPER_ORM
|
|
490
|
+
api_only
|
|
491
|
+
end
|
|
492
|
+
|
|
493
|
+
expect(subject.api_only).to eq(true)
|
|
494
|
+
end
|
|
495
|
+
end
|
|
496
|
+
|
|
497
|
+
describe 'strict_content_type' do
|
|
498
|
+
it 'is false by default' do
|
|
499
|
+
expect(subject.enforce_content_type).to eq(false)
|
|
500
|
+
end
|
|
501
|
+
|
|
502
|
+
it "can change the value" do
|
|
503
|
+
Doorkeeper.configure do
|
|
504
|
+
orm DOORKEEPER_ORM
|
|
505
|
+
enforce_content_type
|
|
506
|
+
end
|
|
507
|
+
|
|
508
|
+
expect(subject.enforce_content_type).to eq(true)
|
|
509
|
+
end
|
|
510
|
+
end
|
|
334
511
|
end
|
data/spec/lib/doorkeeper_spec.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Doorkeeper do
|
|
4
4
|
describe "#authenticate" do
|
|
@@ -22,129 +22,4 @@ describe Doorkeeper do
|
|
|
22
22
|
Doorkeeper.authenticate(request, token_strategies)
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
|
-
|
|
26
|
-
describe "#configured?" do
|
|
27
|
-
after do
|
|
28
|
-
Doorkeeper.remove_instance_variable(:@config)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
context "@config is set" do
|
|
32
|
-
it "returns true" do
|
|
33
|
-
Doorkeeper.instance_variable_set(:@config, "hi")
|
|
34
|
-
|
|
35
|
-
expect(Doorkeeper.configured?).to eq(true)
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
context "@config is not set" do
|
|
40
|
-
it "returns false" do
|
|
41
|
-
Doorkeeper.instance_variable_set(:@config, nil)
|
|
42
|
-
|
|
43
|
-
expect(Doorkeeper.configured?).to eq(false)
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
it "is deprecated" do
|
|
48
|
-
expect(ActiveSupport::Deprecation).to receive(:warn).
|
|
49
|
-
with("Method `Doorkeeper#configured?` has been deprecated without replacement.")
|
|
50
|
-
|
|
51
|
-
Doorkeeper.configured?
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
describe "#database_installed?" do
|
|
56
|
-
before do
|
|
57
|
-
["AccessToken", "AccessGrant", "Application"].each do |klass|
|
|
58
|
-
@original_classes ||= {}
|
|
59
|
-
@original_classes[klass] = Doorkeeper.const_get(klass)
|
|
60
|
-
Doorkeeper.send(:remove_const, klass)
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
after do
|
|
65
|
-
["AccessToken", "AccessGrant", "Application"].each do |klass|
|
|
66
|
-
Doorkeeper.send(:remove_const, klass)
|
|
67
|
-
Doorkeeper.const_set(klass, @original_classes[klass])
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
context "all tables exist" do
|
|
72
|
-
before do
|
|
73
|
-
klass = double table_exists?: true
|
|
74
|
-
|
|
75
|
-
Doorkeeper.const_set(:AccessToken, klass)
|
|
76
|
-
Doorkeeper.const_set(:AccessGrant, klass)
|
|
77
|
-
Doorkeeper.const_set(:Application, klass)
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
it "returns true" do
|
|
81
|
-
expect(Doorkeeper.database_installed?).to eq(true)
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
it "is deprecated" do
|
|
85
|
-
expect(ActiveSupport::Deprecation).to receive(:warn).
|
|
86
|
-
with("Method `Doorkeeper#database_installed?` has been deprecated without replacement.")
|
|
87
|
-
|
|
88
|
-
Doorkeeper.database_installed?
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
context "all tables do not exist" do
|
|
93
|
-
before do
|
|
94
|
-
klass = double table_exists?: false
|
|
95
|
-
|
|
96
|
-
Doorkeeper.const_set(:AccessToken, klass)
|
|
97
|
-
Doorkeeper.const_set(:AccessGrant, klass)
|
|
98
|
-
Doorkeeper.const_set(:Application, klass)
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
it "returns false" do
|
|
102
|
-
expect(Doorkeeper.database_installed?).to eq(false)
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
it "is deprecated" do
|
|
106
|
-
expect(ActiveSupport::Deprecation).to receive(:warn).
|
|
107
|
-
with("Method `Doorkeeper#database_installed?` has been deprecated without replacement.")
|
|
108
|
-
|
|
109
|
-
Doorkeeper.database_installed?
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
describe "#installed?" do
|
|
115
|
-
context "methods return true" do
|
|
116
|
-
before do
|
|
117
|
-
allow(Doorkeeper).to receive(:configured?).and_return(true).once
|
|
118
|
-
allow(Doorkeeper).to receive(:database_installed?).and_return(true).once
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
it "returns true" do
|
|
122
|
-
expect(Doorkeeper.installed?).to eq(true)
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
context "methods return false" do
|
|
127
|
-
before do
|
|
128
|
-
allow(Doorkeeper).to receive(:configured?).and_return(false).once
|
|
129
|
-
allow(Doorkeeper).to receive(:database_installed?).and_return(false).once
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
it "returns false" do
|
|
133
|
-
expect(Doorkeeper.installed?).to eq(false)
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
it "is deprecated" do
|
|
138
|
-
expect(ActiveSupport::Deprecation).to receive(:warn).
|
|
139
|
-
with("Method `Doorkeeper#configured?` has been deprecated without replacement.")
|
|
140
|
-
|
|
141
|
-
expect(ActiveSupport::Deprecation).to receive(:warn).
|
|
142
|
-
with("Method `Doorkeeper#database_installed?` has been deprecated without replacement.")
|
|
143
|
-
|
|
144
|
-
expect(ActiveSupport::Deprecation).to receive(:warn).
|
|
145
|
-
with("Method `Doorkeeper#installed?` has been deprecated without replacement.")
|
|
146
|
-
|
|
147
|
-
Doorkeeper.installed?
|
|
148
|
-
end
|
|
149
|
-
end
|
|
150
25
|
end
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
|
-
require 'timecop'
|
|
3
|
-
require 'active_support/time'
|
|
4
|
-
require 'doorkeeper/models/concerns/expirable'
|
|
5
2
|
|
|
6
3
|
describe 'Expirable' do
|
|
7
4
|
subject do
|
|
@@ -46,6 +43,5 @@ describe 'Expirable' do
|
|
|
46
43
|
allow(subject).to receive(:expires_in).and_return(nil)
|
|
47
44
|
expect(subject.expires_in_seconds).to be_nil
|
|
48
45
|
end
|
|
49
|
-
|
|
50
46
|
end
|
|
51
47
|
end
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
|
-
require 'active_support/core_ext/object/blank'
|
|
3
|
-
require 'doorkeeper/models/concerns/revocable'
|
|
4
2
|
|
|
5
3
|
describe 'Revocable' do
|
|
6
4
|
subject do
|
|
@@ -38,11 +36,11 @@ describe 'Revocable' do
|
|
|
38
36
|
describe :revoke_previous_refresh_token! do
|
|
39
37
|
it "revokes the previous token if existing, and resets the
|
|
40
38
|
`previous_refresh_token` attribute" do
|
|
41
|
-
previous_token =
|
|
39
|
+
previous_token = FactoryBot.create(
|
|
42
40
|
:access_token,
|
|
43
41
|
refresh_token: "refresh_token"
|
|
44
42
|
)
|
|
45
|
-
current_token =
|
|
43
|
+
current_token = FactoryBot.create(
|
|
46
44
|
:access_token,
|
|
47
45
|
previous_refresh_token: previous_token.refresh_token
|
|
48
46
|
)
|