doorkeeper 4.4.3 → 5.0.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of doorkeeper might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.gitlab-ci.yml +16 -0
- data/.travis.yml +7 -0
- data/Appraisals +2 -2
- data/Dangerfile +64 -0
- data/Gemfile +1 -1
- data/NEWS.md +98 -8
- data/README.md +110 -12
- data/Rakefile +6 -0
- data/UPGRADE.md +2 -0
- data/app/assets/stylesheets/doorkeeper/admin/application.css +2 -2
- data/app/controllers/doorkeeper/application_controller.rb +6 -3
- data/app/controllers/doorkeeper/application_metal_controller.rb +6 -0
- data/app/controllers/doorkeeper/applications_controller.rb +46 -24
- data/app/controllers/doorkeeper/authorizations_controller.rb +55 -12
- data/app/controllers/doorkeeper/authorized_applications_controller.rb +21 -2
- data/app/controllers/doorkeeper/token_info_controller.rb +2 -0
- data/app/controllers/doorkeeper/tokens_controller.rb +4 -6
- data/app/helpers/doorkeeper/dashboard_helper.rb +9 -7
- data/app/validators/redirect_uri_validator.rb +5 -2
- data/app/views/doorkeeper/applications/_delete_form.html.erb +3 -1
- data/app/views/doorkeeper/applications/_form.html.erb +25 -24
- data/app/views/doorkeeper/applications/edit.html.erb +1 -1
- data/app/views/doorkeeper/applications/index.html.erb +17 -7
- data/app/views/doorkeeper/applications/new.html.erb +1 -1
- data/app/views/doorkeeper/applications/show.html.erb +6 -6
- data/app/views/doorkeeper/authorizations/error.html.erb +1 -1
- data/app/views/doorkeeper/authorizations/new.html.erb +4 -0
- data/app/views/layouts/doorkeeper/admin.html.erb +15 -15
- data/config/locales/en.yml +10 -1
- data/doorkeeper.gemspec +25 -26
- data/gemfiles/rails_5_2.gemfile +1 -1
- data/gemfiles/rails_master.gemfile +4 -1
- data/lib/doorkeeper/config.rb +81 -40
- data/lib/doorkeeper/engine.rb +6 -0
- data/lib/doorkeeper/errors.rb +17 -3
- data/lib/doorkeeper/grape/authorization_decorator.rb +2 -0
- data/lib/doorkeeper/grape/helpers.rb +3 -1
- data/lib/doorkeeper/helpers/controller.rb +9 -2
- data/lib/doorkeeper/models/access_grant_mixin.rb +73 -0
- data/lib/doorkeeper/models/access_token_mixin.rb +44 -25
- data/lib/doorkeeper/models/application_mixin.rb +2 -0
- data/lib/doorkeeper/models/concerns/accessible.rb +2 -0
- data/lib/doorkeeper/models/concerns/expirable.rb +2 -0
- data/lib/doorkeeper/models/concerns/orderable.rb +2 -0
- data/lib/doorkeeper/models/concerns/ownership.rb +2 -0
- data/lib/doorkeeper/models/concerns/revocable.rb +2 -0
- data/lib/doorkeeper/models/concerns/scopes.rb +3 -1
- data/lib/doorkeeper/oauth/authorization/code.rb +33 -8
- data/lib/doorkeeper/oauth/authorization/context.rb +17 -0
- data/lib/doorkeeper/oauth/authorization/token.rb +38 -14
- data/lib/doorkeeper/oauth/authorization/uri_builder.rb +2 -0
- data/lib/doorkeeper/oauth/authorization_code_request.rb +29 -2
- data/lib/doorkeeper/oauth/base_request.rb +22 -9
- data/lib/doorkeeper/oauth/base_response.rb +2 -0
- data/lib/doorkeeper/oauth/client/credentials.rb +3 -1
- data/lib/doorkeeper/oauth/client.rb +1 -1
- data/lib/doorkeeper/oauth/client_credentials/creator.rb +4 -1
- data/lib/doorkeeper/oauth/client_credentials/issuer.rb +7 -2
- data/lib/doorkeeper/oauth/client_credentials/validation.rb +5 -5
- data/lib/doorkeeper/oauth/client_credentials_request.rb +1 -3
- data/lib/doorkeeper/oauth/code_request.rb +2 -0
- data/lib/doorkeeper/oauth/code_response.rb +2 -0
- data/lib/doorkeeper/oauth/error.rb +2 -0
- data/lib/doorkeeper/oauth/error_response.rb +21 -3
- data/lib/doorkeeper/oauth/forbidden_token_response.rb +9 -2
- data/lib/doorkeeper/oauth/helpers/scope_checker.rb +2 -8
- data/lib/doorkeeper/oauth/helpers/unique_token.rb +2 -0
- data/lib/doorkeeper/oauth/helpers/uri_checker.rb +5 -2
- data/lib/doorkeeper/oauth/invalid_token_response.rb +18 -0
- data/lib/doorkeeper/oauth/password_access_token_request.rb +9 -4
- data/lib/doorkeeper/oauth/pre_authorization.rb +43 -11
- data/lib/doorkeeper/oauth/refresh_token_request.rb +16 -3
- data/lib/doorkeeper/oauth/scopes.rb +3 -1
- data/lib/doorkeeper/oauth/token.rb +7 -2
- data/lib/doorkeeper/oauth/token_introspection.rb +4 -2
- data/lib/doorkeeper/oauth/token_request.rb +2 -0
- data/lib/doorkeeper/oauth/token_response.rb +6 -2
- data/lib/doorkeeper/oauth.rb +13 -0
- data/lib/doorkeeper/orm/active_record/application.rb +75 -12
- data/lib/doorkeeper/orm/active_record/stale_records_cleaner.rb +26 -0
- data/lib/doorkeeper/orm/active_record.rb +4 -0
- data/lib/doorkeeper/rails/helpers.rb +6 -4
- data/lib/doorkeeper/rails/routes/mapper.rb +2 -0
- data/lib/doorkeeper/rails/routes/mapping.rb +2 -0
- data/lib/doorkeeper/rails/routes.rb +23 -8
- 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 +1 -1
- data/lib/doorkeeper/request/client_credentials.rb +1 -1
- data/lib/doorkeeper/request/code.rb +1 -1
- data/lib/doorkeeper/request/password.rb +1 -1
- data/lib/doorkeeper/request/refresh_token.rb +1 -1
- data/lib/doorkeeper/request/strategy.rb +2 -0
- data/lib/doorkeeper/request/token.rb +1 -1
- data/lib/doorkeeper/request.rb +29 -34
- data/lib/doorkeeper/server.rb +2 -0
- data/lib/doorkeeper/stale_records_cleaner.rb +20 -0
- data/lib/doorkeeper/validations.rb +2 -0
- data/lib/doorkeeper/version.rb +6 -24
- data/lib/doorkeeper.rb +20 -17
- data/lib/generators/doorkeeper/application_owner_generator.rb +23 -18
- 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 +23 -18
- data/lib/generators/doorkeeper/pkce_generator.rb +32 -0
- data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +29 -24
- data/lib/generators/doorkeeper/templates/add_confidential_to_applications.rb.erb +13 -0
- data/lib/generators/doorkeeper/templates/enable_pkce_migration.rb.erb +6 -0
- data/lib/generators/doorkeeper/templates/initializer.rb +96 -13
- data/lib/generators/doorkeeper/templates/migration.rb.erb +2 -3
- 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 +123 -14
- data/spec/controllers/authorizations_controller_spec.rb +334 -51
- data/spec/controllers/protected_resources_controller_spec.rb +60 -18
- data/spec/controllers/token_info_controller_spec.rb +4 -12
- data/spec/controllers/tokens_controller_spec.rb +17 -20
- data/spec/dummy/Rakefile +1 -1
- data/spec/dummy/app/assets/config/manifest.js +2 -0
- data/spec/dummy/app/controllers/custom_authorizations_controller.rb +1 -1
- data/spec/dummy/app/controllers/home_controller.rb +1 -2
- data/spec/dummy/config/application.rb +1 -1
- data/spec/dummy/config/boot.rb +2 -4
- data/spec/dummy/config/environment.rb +1 -1
- data/spec/dummy/config/environments/test.rb +5 -6
- data/spec/dummy/config/initializers/doorkeeper.rb +12 -6
- data/spec/dummy/config/initializers/new_framework_defaults.rb +2 -0
- data/spec/dummy/config/initializers/secret_token.rb +1 -1
- data/spec/dummy/config/routes.rb +3 -42
- data/spec/dummy/config.ru +1 -1
- data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +4 -4
- data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +1 -1
- data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +6 -0
- data/spec/dummy/db/migrate/{20180210183654_add_confidential_to_application.rb → 20180210183654_add_confidential_to_applications.rb} +1 -1
- data/spec/dummy/db/schema.rb +36 -36
- data/spec/dummy/script/rails +4 -3
- data/spec/factories.rb +6 -6
- data/spec/generators/application_owner_generator_spec.rb +1 -1
- data/spec/generators/confidential_applications_generator_spec.rb +45 -0
- data/spec/generators/install_generator_spec.rb +5 -2
- data/spec/generators/migration_generator_spec.rb +1 -1
- data/spec/generators/pkce_generator_spec.rb +43 -0
- data/spec/generators/previous_refresh_token_generator_spec.rb +1 -1
- data/spec/generators/templates/routes.rb +0 -1
- data/spec/generators/views_generator_spec.rb +2 -2
- data/spec/grape/grape_integration_spec.rb +2 -2
- data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +1 -1
- data/spec/lib/config_spec.rb +105 -39
- data/spec/lib/doorkeeper_spec.rb +6 -131
- data/spec/lib/models/expirable_spec.rb +0 -3
- data/spec/lib/models/revocable_spec.rb +0 -2
- 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 +17 -7
- data/spec/lib/oauth/base_request_spec.rb +49 -11
- data/spec/lib/oauth/base_response_spec.rb +1 -1
- data/spec/lib/oauth/client/credentials_spec.rb +2 -4
- data/spec/lib/oauth/client_credentials/creator_spec.rb +5 -1
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +24 -7
- data/spec/lib/oauth/client_credentials/validation_spec.rb +4 -4
- data/spec/lib/oauth/client_credentials_integration_spec.rb +2 -2
- data/spec/lib/oauth/client_credentials_request_spec.rb +3 -5
- data/spec/lib/oauth/client_spec.rb +0 -3
- data/spec/lib/oauth/code_request_spec.rb +5 -3
- data/spec/lib/oauth/code_response_spec.rb +1 -1
- data/spec/lib/oauth/error_response_spec.rb +0 -3
- data/spec/lib/oauth/error_spec.rb +0 -2
- data/spec/lib/oauth/forbidden_token_response_spec.rb +1 -4
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +8 -11
- data/spec/lib/oauth/helpers/unique_token_spec.rb +0 -1
- data/spec/lib/oauth/helpers/uri_checker_spec.rb +22 -13
- data/spec/lib/oauth/invalid_token_response_spec.rb +1 -4
- data/spec/lib/oauth/password_access_token_request_spec.rb +53 -6
- data/spec/lib/oauth/pre_authorization_spec.rb +33 -4
- data/spec/lib/oauth/refresh_token_request_spec.rb +22 -14
- data/spec/lib/oauth/scopes_spec.rb +0 -3
- data/spec/lib/oauth/token_request_spec.rb +8 -9
- data/spec/lib/oauth/token_response_spec.rb +0 -1
- data/spec/lib/oauth/token_spec.rb +40 -14
- data/spec/lib/request/strategy_spec.rb +0 -1
- data/spec/lib/server_spec.rb +7 -7
- data/spec/lib/stale_records_cleaner_spec.rb +89 -0
- data/spec/models/doorkeeper/access_grant_spec.rb +44 -1
- data/spec/models/doorkeeper/access_token_spec.rb +80 -32
- data/spec/models/doorkeeper/application_spec.rb +293 -221
- data/spec/requests/applications/applications_request_spec.rb +134 -1
- data/spec/requests/applications/authorized_applications_spec.rb +1 -1
- data/spec/requests/endpoints/authorization_spec.rb +3 -3
- data/spec/requests/endpoints/token_spec.rb +7 -5
- data/spec/requests/flows/authorization_code_errors_spec.rb +2 -2
- data/spec/requests/flows/authorization_code_spec.rb +258 -2
- data/spec/requests/flows/client_credentials_spec.rb +46 -6
- 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 +61 -3
- data/spec/requests/flows/refresh_token_spec.rb +59 -2
- data/spec/requests/flows/revoke_token_spec.rb +20 -20
- data/spec/requests/flows/skip_authorization_spec.rb +16 -11
- data/spec/requests/protected_resources/metal_spec.rb +1 -1
- data/spec/requests/protected_resources/private_api_spec.rb +3 -3
- data/spec/routing/custom_controller_routes_spec.rb +59 -7
- data/spec/routing/default_routes_spec.rb +2 -2
- data/spec/routing/scoped_routes_spec.rb +16 -2
- data/spec/spec_helper.rb +54 -3
- data/spec/spec_helper_integration.rb +2 -74
- data/spec/support/dependencies/{factory_girl.rb → factory_bot.rb} +0 -0
- data/spec/support/doorkeeper_rspec.rb +20 -0
- data/spec/support/helpers/authorization_request_helper.rb +4 -4
- data/spec/support/helpers/model_helper.rb +8 -4
- data/spec/support/helpers/request_spec_helper.rb +10 -2
- data/spec/support/helpers/url_helper.rb +18 -14
- data/spec/support/http_method_shim.rb +12 -16
- data/spec/support/shared/controllers_shared_context.rb +56 -0
- data/spec/validators/redirect_uri_validator_spec.rb +9 -3
- data/spec/version/version_spec.rb +3 -3
- data/vendor/assets/stylesheets/doorkeeper/bootstrap.min.css +4 -5
- metadata +54 -35
- data/lib/generators/doorkeeper/add_client_confidentiality_generator.rb +0 -31
- data/lib/generators/doorkeeper/templates/add_confidential_to_application_migration.rb.erb +0 -11
- data/spec/controllers/application_metal_controller.rb +0 -10
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'generators/doorkeeper/pkce_generator'
|
5
|
+
|
6
|
+
describe 'Doorkeeper::PkceGenerator' do
|
7
|
+
include GeneratorSpec::TestCase
|
8
|
+
|
9
|
+
tests Doorkeeper::PkceGenerator
|
10
|
+
destination ::File.expand_path('../tmp/dummy', __FILE__)
|
11
|
+
|
12
|
+
describe 'after running the generator' do
|
13
|
+
before :each do
|
14
|
+
prepare_destination
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'pre Rails 5.0.0' do
|
18
|
+
it 'creates a migration with no version specifier' do
|
19
|
+
stub_const("ActiveRecord::VERSION::MAJOR", 4)
|
20
|
+
stub_const("ActiveRecord::VERSION::MINOR", 2)
|
21
|
+
|
22
|
+
run_generator
|
23
|
+
|
24
|
+
assert_migration 'db/migrate/enable_pkce.rb' do |migration|
|
25
|
+
assert migration.include?("ActiveRecord::Migration\n")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'post Rails 5.0.0' do
|
31
|
+
it 'creates a migration with a version specifier' do
|
32
|
+
stub_const("ActiveRecord::VERSION::MAJOR", 5)
|
33
|
+
stub_const("ActiveRecord::VERSION::MINOR", 0)
|
34
|
+
|
35
|
+
run_generator
|
36
|
+
|
37
|
+
assert_migration 'db/migrate/enable_pkce.rb' do |migration|
|
38
|
+
assert migration.include?("ActiveRecord::Migration[5.0]\n")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
require 'generators/doorkeeper/views_generator'
|
3
3
|
|
4
4
|
describe Doorkeeper::Generators::ViewsGenerator do
|
5
5
|
include GeneratorSpec::TestCase
|
6
6
|
|
7
7
|
tests Doorkeeper::Generators::ViewsGenerator
|
8
|
-
destination File.expand_path('
|
8
|
+
destination File.expand_path('tmp/dummy', __dir__)
|
9
9
|
|
10
10
|
before :each do
|
11
11
|
prepare_destination
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
require 'grape'
|
3
3
|
require 'rack/test'
|
4
4
|
require 'doorkeeper/grape/helpers'
|
@@ -68,7 +68,7 @@ describe 'Grape integration' do
|
|
68
68
|
def json_body
|
69
69
|
JSON.parse(last_response.body)
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
let(:client) { FactoryBot.create(:application) }
|
73
73
|
let(:resource) { FactoryBot.create(:doorkeeper_testing_user, name: 'Joe', password: 'sekret') }
|
74
74
|
let(:access_token) { client_is_authorized(client, resource) }
|
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 }
|
@@ -66,6 +66,17 @@ describe Doorkeeper, 'configuration' do
|
|
66
66
|
end
|
67
67
|
|
68
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
|
+
|
69
80
|
it 'sets the block that is accessible via authenticate_admin' do
|
70
81
|
block = proc {}
|
71
82
|
Doorkeeper.configure do
|
@@ -122,7 +133,7 @@ describe Doorkeeper, 'configuration' do
|
|
122
133
|
it 'has all scopes' do
|
123
134
|
Doorkeeper.configure do
|
124
135
|
orm DOORKEEPER_ORM
|
125
|
-
default_scopes
|
136
|
+
default_scopes :normal
|
126
137
|
optional_scopes :admin
|
127
138
|
end
|
128
139
|
|
@@ -132,7 +143,7 @@ describe Doorkeeper, 'configuration' do
|
|
132
143
|
|
133
144
|
describe 'use_refresh_token' do
|
134
145
|
it 'is false by default' do
|
135
|
-
expect(subject.refresh_token_enabled?).to
|
146
|
+
expect(subject.refresh_token_enabled?).to eq(false)
|
136
147
|
end
|
137
148
|
|
138
149
|
it 'can change the value' do
|
@@ -141,7 +152,25 @@ describe Doorkeeper, 'configuration' do
|
|
141
152
|
use_refresh_token
|
142
153
|
end
|
143
154
|
|
144
|
-
expect(subject.refresh_token_enabled?).to
|
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)
|
145
174
|
end
|
146
175
|
|
147
176
|
it "does not includes 'refresh_token' in authorization_response_types" do
|
@@ -150,10 +179,10 @@ describe Doorkeeper, 'configuration' do
|
|
150
179
|
|
151
180
|
context "is enabled" do
|
152
181
|
before do
|
153
|
-
Doorkeeper.configure
|
182
|
+
Doorkeeper.configure do
|
154
183
|
orm DOORKEEPER_ORM
|
155
184
|
use_refresh_token
|
156
|
-
|
185
|
+
end
|
157
186
|
end
|
158
187
|
|
159
188
|
it "includes 'refresh_token' in authorization_response_types" do
|
@@ -162,34 +191,25 @@ describe Doorkeeper, 'configuration' do
|
|
162
191
|
end
|
163
192
|
end
|
164
193
|
|
165
|
-
describe '
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
opt_out_native_route_change
|
170
|
-
end
|
171
|
-
|
172
|
-
Rails.application.reload_routes!
|
173
|
-
|
174
|
-
subject { Doorkeeper.configuration }
|
175
|
-
|
176
|
-
example.run
|
194
|
+
describe 'enforce_configured_scopes' do
|
195
|
+
it 'is false by default' do
|
196
|
+
expect(subject.enforce_configured_scopes?).to eq(false)
|
197
|
+
end
|
177
198
|
|
199
|
+
it 'can change the value' do
|
178
200
|
Doorkeeper.configure do
|
179
201
|
orm DOORKEEPER_ORM
|
202
|
+
enforce_configured_scopes
|
180
203
|
end
|
181
204
|
|
182
|
-
|
183
|
-
end
|
184
|
-
|
185
|
-
it 'sets the native authorization code route /:code' do
|
186
|
-
expect(subject.native_authorization_code_route).to eq('/:code')
|
205
|
+
expect(subject.enforce_configured_scopes?).to eq(true)
|
187
206
|
end
|
188
207
|
end
|
189
208
|
|
190
209
|
describe 'client_credentials' do
|
191
210
|
it 'has defaults order' do
|
192
|
-
expect(subject.client_credentials_methods)
|
211
|
+
expect(subject.client_credentials_methods)
|
212
|
+
.to eq(%i[from_basic from_params])
|
193
213
|
end
|
194
214
|
|
195
215
|
it 'can change the value' do
|
@@ -198,13 +218,14 @@ describe Doorkeeper, 'configuration' do
|
|
198
218
|
client_credentials :from_digest, :from_params
|
199
219
|
end
|
200
220
|
|
201
|
-
expect(subject.client_credentials_methods)
|
221
|
+
expect(subject.client_credentials_methods)
|
222
|
+
.to eq(%i[from_digest from_params])
|
202
223
|
end
|
203
224
|
end
|
204
225
|
|
205
226
|
describe 'force_ssl_in_redirect_uri' do
|
206
227
|
it 'is true by default in non-development environments' do
|
207
|
-
expect(subject.force_ssl_in_redirect_uri).to
|
228
|
+
expect(subject.force_ssl_in_redirect_uri).to eq(true)
|
208
229
|
end
|
209
230
|
|
210
231
|
it 'can change the value' do
|
@@ -213,7 +234,7 @@ describe Doorkeeper, 'configuration' do
|
|
213
234
|
force_ssl_in_redirect_uri(false)
|
214
235
|
end
|
215
236
|
|
216
|
-
expect(subject.force_ssl_in_redirect_uri).to
|
237
|
+
expect(subject.force_ssl_in_redirect_uri).to eq(false)
|
217
238
|
end
|
218
239
|
|
219
240
|
it 'can be a callable object' do
|
@@ -224,13 +245,14 @@ describe Doorkeeper, 'configuration' do
|
|
224
245
|
end
|
225
246
|
|
226
247
|
expect(subject.force_ssl_in_redirect_uri).to eq(block)
|
227
|
-
expect(subject.force_ssl_in_redirect_uri.call).to
|
248
|
+
expect(subject.force_ssl_in_redirect_uri.call).to eq(false)
|
228
249
|
end
|
229
250
|
end
|
230
251
|
|
231
252
|
describe 'access_token_methods' do
|
232
253
|
it 'has defaults order' do
|
233
|
-
expect(subject.access_token_methods)
|
254
|
+
expect(subject.access_token_methods)
|
255
|
+
.to eq(%i[from_bearer_authorization from_access_token_param from_bearer_param])
|
234
256
|
end
|
235
257
|
|
236
258
|
it 'can change the value' do
|
@@ -239,13 +261,14 @@ describe Doorkeeper, 'configuration' do
|
|
239
261
|
access_token_methods :from_access_token_param, :from_bearer_param
|
240
262
|
end
|
241
263
|
|
242
|
-
expect(subject.access_token_methods)
|
264
|
+
expect(subject.access_token_methods)
|
265
|
+
.to eq(%i[from_access_token_param from_bearer_param])
|
243
266
|
end
|
244
267
|
end
|
245
268
|
|
246
269
|
describe 'forbid_redirect_uri' do
|
247
270
|
it 'is false by default' do
|
248
|
-
expect(subject.forbid_redirect_uri.call(URI.parse('https://localhost'))).to
|
271
|
+
expect(subject.forbid_redirect_uri.call(URI.parse('https://localhost'))).to eq(false)
|
249
272
|
end
|
250
273
|
|
251
274
|
it 'can be a callable object' do
|
@@ -256,13 +279,13 @@ describe Doorkeeper, 'configuration' do
|
|
256
279
|
end
|
257
280
|
|
258
281
|
expect(subject.forbid_redirect_uri).to eq(block)
|
259
|
-
expect(subject.forbid_redirect_uri.call).to
|
282
|
+
expect(subject.forbid_redirect_uri.call).to eq(true)
|
260
283
|
end
|
261
284
|
end
|
262
285
|
|
263
286
|
describe 'enable_application_owner' do
|
264
287
|
it 'is disabled by default' do
|
265
|
-
expect(Doorkeeper.configuration.enable_application_owner?).not_to
|
288
|
+
expect(Doorkeeper.configuration.enable_application_owner?).not_to eq(true)
|
266
289
|
end
|
267
290
|
|
268
291
|
context 'when enabled without confirmation' do
|
@@ -278,7 +301,7 @@ describe Doorkeeper, 'configuration' do
|
|
278
301
|
end
|
279
302
|
|
280
303
|
it 'Doorkeeper.configuration.confirm_application_owner? returns false' do
|
281
|
-
expect(Doorkeeper.configuration.confirm_application_owner?).not_to
|
304
|
+
expect(Doorkeeper.configuration.confirm_application_owner?).not_to eq(true)
|
282
305
|
end
|
283
306
|
end
|
284
307
|
|
@@ -295,7 +318,7 @@ describe Doorkeeper, 'configuration' do
|
|
295
318
|
end
|
296
319
|
|
297
320
|
it 'Doorkeeper.configuration.confirm_application_owner? returns true' do
|
298
|
-
expect(Doorkeeper.configuration.confirm_application_owner?).to
|
321
|
+
expect(Doorkeeper.configuration.confirm_application_owner?).to eq(true)
|
299
322
|
end
|
300
323
|
end
|
301
324
|
end
|
@@ -317,17 +340,17 @@ describe Doorkeeper, 'configuration' do
|
|
317
340
|
|
318
341
|
describe "grant_flows" do
|
319
342
|
it "is set to all grant flows by default" do
|
320
|
-
expect(Doorkeeper.configuration.grant_flows)
|
321
|
-
to eq(%w[authorization_code client_credentials])
|
343
|
+
expect(Doorkeeper.configuration.grant_flows)
|
344
|
+
.to eq(%w[authorization_code client_credentials])
|
322
345
|
end
|
323
346
|
|
324
347
|
it "can change the value" do
|
325
348
|
Doorkeeper.configure do
|
326
349
|
orm DOORKEEPER_ORM
|
327
|
-
grant_flows [
|
350
|
+
grant_flows %w[authorization_code implicit]
|
328
351
|
end
|
329
352
|
|
330
|
-
expect(subject.grant_flows).to eq [
|
353
|
+
expect(subject.grant_flows).to eq %w[authorization_code implicit]
|
331
354
|
end
|
332
355
|
|
333
356
|
context "when including 'authorization_code'" do
|
@@ -459,4 +482,47 @@ describe Doorkeeper, 'configuration' do
|
|
459
482
|
end
|
460
483
|
end
|
461
484
|
end
|
485
|
+
|
486
|
+
describe "api_only" do
|
487
|
+
it "is false by default" do
|
488
|
+
expect(subject.api_only).to eq(false)
|
489
|
+
end
|
490
|
+
|
491
|
+
it "can change the value" do
|
492
|
+
Doorkeeper.configure do
|
493
|
+
orm DOORKEEPER_ORM
|
494
|
+
api_only
|
495
|
+
end
|
496
|
+
|
497
|
+
expect(subject.api_only).to eq(true)
|
498
|
+
end
|
499
|
+
end
|
500
|
+
|
501
|
+
describe 'strict_content_type' do
|
502
|
+
it 'is false by default' do
|
503
|
+
expect(subject.enforce_content_type).to eq(false)
|
504
|
+
end
|
505
|
+
|
506
|
+
it "can change the value" do
|
507
|
+
Doorkeeper.configure do
|
508
|
+
orm DOORKEEPER_ORM
|
509
|
+
enforce_content_type
|
510
|
+
end
|
511
|
+
|
512
|
+
expect(subject.enforce_content_type).to eq(true)
|
513
|
+
end
|
514
|
+
end
|
515
|
+
|
516
|
+
describe 'handle_auth_errors' do
|
517
|
+
it 'is set to render by default' do
|
518
|
+
expect(Doorkeeper.configuration.handle_auth_errors).to eq(:render)
|
519
|
+
end
|
520
|
+
it 'can change the value' do
|
521
|
+
Doorkeeper.configure do
|
522
|
+
orm DOORKEEPER_ORM
|
523
|
+
handle_auth_errors :raise
|
524
|
+
end
|
525
|
+
expect(subject.handle_auth_errors).to eq(:raise)
|
526
|
+
end
|
527
|
+
end
|
462
528
|
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
|
@@ -7,144 +7,19 @@ describe Doorkeeper do
|
|
7
7
|
it "calls OAuth::Token#authenticate" do
|
8
8
|
token_strategies = Doorkeeper.configuration.access_token_methods
|
9
9
|
|
10
|
-
expect(Doorkeeper::OAuth::Token).to receive(:authenticate)
|
11
|
-
with(request, *token_strategies)
|
10
|
+
expect(Doorkeeper::OAuth::Token).to receive(:authenticate)
|
11
|
+
.with(request, *token_strategies)
|
12
12
|
|
13
13
|
Doorkeeper.authenticate(request)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "accepts custom token strategies" do
|
17
|
-
token_strategies = [
|
17
|
+
token_strategies = %i[first_way second_way]
|
18
18
|
|
19
|
-
expect(Doorkeeper::OAuth::Token).to receive(:authenticate)
|
20
|
-
with(request, *token_strategies)
|
19
|
+
expect(Doorkeeper::OAuth::Token).to receive(:authenticate)
|
20
|
+
.with(request, *token_strategies)
|
21
21
|
|
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,6 +1,4 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'active_support/time'
|
3
|
-
require 'doorkeeper/models/concerns/expirable'
|
4
2
|
|
5
3
|
describe 'Expirable' do
|
6
4
|
subject do
|
@@ -45,6 +43,5 @@ describe 'Expirable' do
|
|
45
43
|
allow(subject).to receive(:expires_in).and_return(nil)
|
46
44
|
expect(subject.expires_in_seconds).to be_nil
|
47
45
|
end
|
48
|
-
|
49
46
|
end
|
50
47
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
module Doorkeeper::OAuth
|
4
4
|
describe AuthorizationCodeRequest do
|
@@ -6,7 +6,9 @@ module Doorkeeper::OAuth
|
|
6
6
|
double :server,
|
7
7
|
access_token_expires_in: 2.days,
|
8
8
|
refresh_token_enabled?: false,
|
9
|
-
custom_access_token_expires_in:
|
9
|
+
custom_access_token_expires_in: lambda { |context|
|
10
|
+
context.grant_type == Doorkeeper::OAuth::AUTHORIZATION_CODE ? 1234 : nil
|
11
|
+
}
|
10
12
|
end
|
11
13
|
|
12
14
|
let(:grant) { FactoryBot.create :access_grant }
|
@@ -22,6 +24,8 @@ module Doorkeeper::OAuth
|
|
22
24
|
expect do
|
23
25
|
subject.authorize
|
24
26
|
end.to change { client.reload.access_tokens.count }.by(1)
|
27
|
+
|
28
|
+
expect(client.reload.access_tokens.max_by(&:created_at).expires_in).to eq(1234)
|
25
29
|
end
|
26
30
|
|
27
31
|
it "issues the token with same grant's scopes" do
|
@@ -30,7 +34,7 @@ module Doorkeeper::OAuth
|
|
30
34
|
end
|
31
35
|
|
32
36
|
it 'revokes the grant' do
|
33
|
-
expect { subject.authorize }.to
|
37
|
+
expect { subject.authorize }.to(change { grant.reload.accessible? })
|
34
38
|
end
|
35
39
|
|
36
40
|
it 'requires the grant to be accessible' do
|
@@ -70,20 +74,26 @@ module Doorkeeper::OAuth
|
|
70
74
|
end
|
71
75
|
|
72
76
|
it 'skips token creation if there is a matching one' do
|
77
|
+
scopes = grant.scopes
|
78
|
+
|
73
79
|
Doorkeeper.configure do
|
74
80
|
orm DOORKEEPER_ORM
|
75
81
|
reuse_access_token
|
82
|
+
default_scopes(*scopes)
|
76
83
|
end
|
77
84
|
|
78
85
|
FactoryBot.create(:access_token, application_id: client.id,
|
79
|
-
|
86
|
+
resource_owner_id: grant.resource_owner_id, scopes: grant.scopes.to_s)
|
80
87
|
|
81
|
-
expect { subject.authorize }.to_not
|
88
|
+
expect { subject.authorize }.to_not(change { Doorkeeper::AccessToken.count })
|
82
89
|
end
|
83
90
|
|
84
91
|
it "calls configured request callback methods" do
|
85
|
-
expect(Doorkeeper.configuration.before_successful_strategy_response)
|
86
|
-
|
92
|
+
expect(Doorkeeper.configuration.before_successful_strategy_response)
|
93
|
+
.to receive(:call).with(subject).once
|
94
|
+
expect(Doorkeeper.configuration.after_successful_strategy_response)
|
95
|
+
.to receive(:call).with(subject, instance_of(Doorkeeper::OAuth::TokenResponse)).once
|
96
|
+
|
87
97
|
subject.authorize
|
88
98
|
end
|
89
99
|
|