doorkeeper 5.0.3 → 5.1.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/.hound.yml +2 -1
- data/.rubocop.yml +37 -4
- data/.travis.yml +11 -21
- data/Appraisals +29 -7
- data/Dangerfile +5 -2
- data/Gemfile +19 -5
- data/NEWS.md +81 -21
- data/README.md +75 -485
- data/Rakefile +10 -8
- data/app/controllers/doorkeeper/application_controller.rb +1 -2
- data/app/controllers/doorkeeper/application_metal_controller.rb +2 -13
- data/app/controllers/doorkeeper/applications_controller.rb +20 -8
- data/app/controllers/doorkeeper/authorized_applications_controller.rb +1 -1
- data/app/controllers/doorkeeper/token_info_controller.rb +2 -2
- data/app/controllers/doorkeeper/tokens_controller.rb +11 -11
- data/app/helpers/doorkeeper/dashboard_helper.rb +1 -1
- data/app/validators/redirect_uri_validator.rb +5 -2
- data/app/views/doorkeeper/applications/_form.html.erb +6 -0
- data/app/views/doorkeeper/applications/show.html.erb +1 -1
- data/app/views/layouts/doorkeeper/admin.html.erb +5 -3
- data/bin/console +16 -0
- data/config/locales/en.yml +1 -0
- data/doorkeeper.gemspec +24 -21
- data/gemfiles/rails_5_0.gemfile +9 -4
- data/gemfiles/rails_5_1.gemfile +9 -4
- data/gemfiles/rails_5_2.gemfile +10 -5
- data/gemfiles/rails_6_0.gemfile +17 -0
- data/gemfiles/rails_master.gemfile +9 -9
- data/lib/doorkeeper/config/option.rb +64 -0
- data/lib/doorkeeper/config.rb +191 -75
- data/lib/doorkeeper/engine.rb +1 -1
- data/lib/doorkeeper/grape/authorization_decorator.rb +4 -4
- data/lib/doorkeeper/grape/helpers.rb +3 -3
- data/lib/doorkeeper/helpers/controller.rb +3 -2
- data/lib/doorkeeper/models/access_grant_mixin.rb +20 -3
- data/lib/doorkeeper/models/access_token_mixin.rb +63 -19
- data/lib/doorkeeper/models/application_mixin.rb +43 -1
- data/lib/doorkeeper/models/concerns/expirable.rb +4 -2
- data/lib/doorkeeper/models/concerns/ownership.rb +1 -6
- data/lib/doorkeeper/models/concerns/reusable.rb +19 -0
- data/lib/doorkeeper/models/concerns/revocable.rb +2 -1
- data/lib/doorkeeper/models/concerns/scopes.rb +5 -1
- data/lib/doorkeeper/models/concerns/secret_storable.rb +108 -0
- data/lib/doorkeeper/oauth/authorization/code.rb +2 -2
- data/lib/doorkeeper/oauth/authorization/token.rb +12 -7
- data/lib/doorkeeper/oauth/authorization/uri_builder.rb +1 -1
- data/lib/doorkeeper/oauth/authorization_code_request.rb +6 -4
- data/lib/doorkeeper/oauth/client.rb +1 -1
- data/lib/doorkeeper/oauth/client_credentials/validation.rb +5 -4
- data/lib/doorkeeper/oauth/client_credentials_request.rb +1 -1
- data/lib/doorkeeper/oauth/code_response.rb +2 -2
- data/lib/doorkeeper/oauth/error_response.rb +10 -6
- data/lib/doorkeeper/oauth/forbidden_token_response.rb +1 -1
- data/lib/doorkeeper/oauth/helpers/scope_checker.rb +23 -8
- data/lib/doorkeeper/oauth/helpers/unique_token.rb +13 -1
- data/lib/doorkeeper/oauth/helpers/uri_checker.rb +37 -1
- data/lib/doorkeeper/oauth/invalid_token_response.rb +5 -1
- data/lib/doorkeeper/oauth/password_access_token_request.rb +7 -2
- data/lib/doorkeeper/oauth/pre_authorization.rb +11 -5
- data/lib/doorkeeper/oauth/refresh_token_request.rb +5 -2
- data/lib/doorkeeper/oauth/scopes.rb +5 -3
- data/lib/doorkeeper/oauth/token.rb +2 -2
- data/lib/doorkeeper/oauth/token_introspection.rb +74 -8
- data/lib/doorkeeper/oauth/token_response.rb +9 -9
- data/lib/doorkeeper/oauth.rb +5 -5
- data/lib/doorkeeper/orm/active_record/access_grant.rb +27 -13
- data/lib/doorkeeper/orm/active_record/access_token.rb +6 -13
- data/lib/doorkeeper/orm/active_record/application.rb +21 -57
- data/lib/doorkeeper/orm/active_record/stale_records_cleaner.rb +10 -3
- data/lib/doorkeeper/orm/active_record.rb +6 -6
- data/lib/doorkeeper/rails/helpers.rb +1 -1
- data/lib/doorkeeper/rails/routes/mapping.rb +7 -7
- data/lib/doorkeeper/rails/routes.rb +11 -11
- data/lib/doorkeeper/rake/db.rake +13 -13
- data/lib/doorkeeper/rake.rb +1 -1
- data/lib/doorkeeper/request.rb +1 -1
- data/lib/doorkeeper/secret_storing/base.rb +64 -0
- data/lib/doorkeeper/secret_storing/bcrypt.rb +60 -0
- data/lib/doorkeeper/secret_storing/plain.rb +33 -0
- data/lib/doorkeeper/secret_storing/sha256_hash.rb +26 -0
- data/lib/doorkeeper/stale_records_cleaner.rb +1 -1
- data/lib/doorkeeper/version.rb +3 -3
- data/lib/doorkeeper.rb +69 -60
- data/lib/generators/doorkeeper/application_owner_generator.rb +10 -9
- data/lib/generators/doorkeeper/confidential_applications_generator.rb +10 -9
- data/lib/generators/doorkeeper/install_generator.rb +11 -9
- data/lib/generators/doorkeeper/migration_generator.rb +9 -9
- data/lib/generators/doorkeeper/pkce_generator.rb +10 -9
- data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +10 -9
- data/lib/generators/doorkeeper/templates/initializer.rb +120 -13
- data/lib/generators/doorkeeper/templates/migration.rb.erb +15 -7
- data/lib/generators/doorkeeper/views_generator.rb +6 -4
- data/spec/controllers/application_metal_controller_spec.rb +24 -10
- data/spec/controllers/applications_controller_spec.rb +54 -52
- data/spec/controllers/authorizations_controller_spec.rb +139 -145
- data/spec/controllers/protected_resources_controller_spec.rb +78 -76
- data/spec/controllers/token_info_controller_spec.rb +14 -12
- data/spec/controllers/tokens_controller_spec.rb +167 -108
- data/spec/dummy/Rakefile +3 -1
- data/spec/dummy/app/controllers/application_controller.rb +3 -1
- data/spec/dummy/app/controllers/custom_authorizations_controller.rb +2 -0
- data/spec/dummy/app/controllers/full_protected_resources_controller.rb +4 -2
- data/spec/dummy/app/controllers/home_controller.rb +5 -3
- data/spec/dummy/app/controllers/metal_controller.rb +2 -0
- data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +4 -2
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/models/user.rb +2 -0
- data/spec/dummy/config/application.rb +25 -1
- data/spec/dummy/config/environments/development.rb +2 -0
- data/spec/dummy/config/environments/production.rb +2 -0
- data/spec/dummy/config/environments/test.rb +3 -1
- data/spec/dummy/config/initializers/backtrace_silencers.rb +2 -0
- data/spec/dummy/config/initializers/doorkeeper.rb +5 -2
- data/spec/dummy/config/initializers/secret_token.rb +3 -1
- data/spec/dummy/config/initializers/session_store.rb +3 -1
- data/spec/dummy/config/initializers/wrap_parameters.rb +2 -0
- data/spec/dummy/config.ru +3 -1
- data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +17 -10
- data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +2 -0
- data/spec/dummy/db/schema.rb +1 -1
- data/spec/dummy/script/rails +5 -3
- data/spec/factories.rb +8 -6
- data/spec/generators/application_owner_generator_spec.rb +13 -26
- data/spec/generators/confidential_applications_generator_spec.rb +12 -28
- data/spec/generators/install_generator_spec.rb +17 -15
- data/spec/generators/migration_generator_spec.rb +13 -26
- data/spec/generators/pkce_generator_spec.rb +11 -26
- data/spec/generators/previous_refresh_token_generator_spec.rb +16 -29
- data/spec/generators/templates/routes.rb +2 -0
- data/spec/generators/views_generator_spec.rb +14 -12
- data/spec/grape/grape_integration_spec.rb +34 -32
- data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +9 -7
- data/spec/lib/config_spec.rb +268 -99
- data/spec/lib/doorkeeper_spec.rb +3 -1
- data/spec/lib/models/expirable_spec.rb +22 -8
- data/spec/lib/models/reusable_spec.rb +40 -0
- data/spec/lib/models/revocable_spec.rb +8 -6
- data/spec/lib/models/scopes_spec.rb +27 -13
- data/spec/lib/models/secret_storable_spec.rb +135 -0
- data/spec/lib/oauth/authorization/uri_builder_spec.rb +17 -15
- data/spec/lib/oauth/authorization_code_request_spec.rb +34 -11
- data/spec/lib/oauth/base_request_spec.rb +20 -8
- data/spec/lib/oauth/base_response_spec.rb +3 -1
- data/spec/lib/oauth/client/credentials_spec.rb +24 -22
- data/spec/lib/oauth/client_credentials/creator_spec.rb +56 -10
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +27 -18
- data/spec/lib/oauth/client_credentials/validation_spec.rb +20 -15
- data/spec/lib/oauth/client_credentials_integration_spec.rb +7 -5
- data/spec/lib/oauth/client_credentials_request_spec.rb +27 -21
- data/spec/lib/oauth/client_spec.rb +15 -13
- data/spec/lib/oauth/code_request_spec.rb +8 -6
- data/spec/lib/oauth/code_response_spec.rb +9 -7
- data/spec/lib/oauth/error_response_spec.rb +19 -11
- data/spec/lib/oauth/error_spec.rb +4 -2
- data/spec/lib/oauth/forbidden_token_response_spec.rb +7 -5
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +68 -31
- data/spec/lib/oauth/helpers/unique_token_spec.rb +8 -6
- data/spec/lib/oauth/helpers/uri_checker_spec.rb +115 -95
- data/spec/lib/oauth/invalid_token_response_spec.rb +3 -1
- data/spec/lib/oauth/password_access_token_request_spec.rb +79 -30
- data/spec/lib/oauth/pre_authorization_spec.rb +80 -54
- data/spec/lib/oauth/refresh_token_request_spec.rb +36 -33
- data/spec/lib/oauth/scopes_spec.rb +63 -61
- data/spec/lib/oauth/token_request_spec.rb +79 -24
- data/spec/lib/oauth/token_response_spec.rb +40 -38
- data/spec/lib/oauth/token_spec.rb +60 -44
- data/spec/lib/request/strategy_spec.rb +3 -1
- data/spec/lib/secret_storing/base_spec.rb +60 -0
- data/spec/lib/secret_storing/bcrypt_spec.rb +49 -0
- data/spec/lib/secret_storing/plain_spec.rb +44 -0
- data/spec/lib/secret_storing/sha256_hash_spec.rb +48 -0
- data/spec/lib/server_spec.rb +16 -14
- data/spec/lib/stale_records_cleaner_spec.rb +17 -17
- data/spec/models/doorkeeper/access_grant_spec.rb +80 -15
- data/spec/models/doorkeeper/access_token_spec.rb +198 -73
- data/spec/models/doorkeeper/application_spec.rb +280 -288
- data/spec/requests/applications/applications_request_spec.rb +98 -66
- data/spec/requests/applications/authorized_applications_spec.rb +20 -18
- data/spec/requests/endpoints/authorization_spec.rb +25 -23
- data/spec/requests/endpoints/token_spec.rb +38 -36
- data/spec/requests/flows/authorization_code_errors_spec.rb +26 -24
- data/spec/requests/flows/authorization_code_spec.rb +193 -151
- data/spec/requests/flows/client_credentials_spec.rb +54 -52
- data/spec/requests/flows/implicit_grant_errors_spec.rb +10 -8
- data/spec/requests/flows/implicit_grant_spec.rb +27 -25
- data/spec/requests/flows/password_spec.rb +59 -55
- data/spec/requests/flows/refresh_token_spec.rb +45 -43
- data/spec/requests/flows/revoke_token_spec.rb +40 -54
- data/spec/requests/flows/skip_authorization_spec.rb +23 -21
- data/spec/requests/protected_resources/metal_spec.rb +7 -5
- data/spec/requests/protected_resources/private_api_spec.rb +35 -33
- data/spec/routing/custom_controller_routes_spec.rb +71 -65
- data/spec/routing/default_routes_spec.rb +22 -20
- data/spec/routing/scoped_routes_spec.rb +20 -18
- data/spec/spec_helper.rb +15 -13
- data/spec/spec_helper_integration.rb +3 -1
- data/spec/support/dependencies/factory_bot.rb +3 -1
- data/spec/support/doorkeeper_rspec.rb +3 -1
- data/spec/support/helpers/access_token_request_helper.rb +3 -1
- data/spec/support/helpers/authorization_request_helper.rb +4 -2
- data/spec/support/helpers/config_helper.rb +2 -0
- data/spec/support/helpers/model_helper.rb +3 -1
- data/spec/support/helpers/request_spec_helper.rb +5 -3
- data/spec/support/helpers/url_helper.rb +9 -7
- data/spec/support/http_method_shim.rb +4 -9
- data/spec/support/orm/active_record.rb +3 -1
- data/spec/support/shared/controllers_shared_context.rb +18 -16
- data/spec/support/shared/hashing_shared_context.rb +36 -0
- data/spec/support/shared/models_shared_examples.rb +12 -10
- data/spec/validators/redirect_uri_validator_spec.rb +74 -45
- data/spec/version/version_spec.rb +7 -5
- metadata +60 -26
- data/gemfiles/rails_4_2.gemfile +0 -13
- data/spec/dummy/config/initializers/new_framework_defaults.rb +0 -8
data/spec/lib/config_spec.rb
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe Doorkeeper, "configuration" do
|
|
4
6
|
subject { Doorkeeper.configuration }
|
|
5
7
|
|
|
6
|
-
describe
|
|
7
|
-
it
|
|
8
|
+
describe "resource_owner_authenticator" do
|
|
9
|
+
it "sets the block that is accessible via authenticate_resource_owner" do
|
|
8
10
|
block = proc {}
|
|
9
11
|
Doorkeeper.configure do
|
|
10
12
|
orm DOORKEEPER_ORM
|
|
@@ -14,20 +16,20 @@ describe Doorkeeper, 'configuration' do
|
|
|
14
16
|
expect(subject.authenticate_resource_owner).to eq(block)
|
|
15
17
|
end
|
|
16
18
|
|
|
17
|
-
it
|
|
19
|
+
it "prints warning message by default" do
|
|
18
20
|
Doorkeeper.configure do
|
|
19
21
|
orm DOORKEEPER_ORM
|
|
20
22
|
end
|
|
21
23
|
|
|
22
24
|
expect(Rails.logger).to receive(:warn).with(
|
|
23
|
-
I18n.t(
|
|
25
|
+
I18n.t("doorkeeper.errors.messages.resource_owner_authenticator_not_configured")
|
|
24
26
|
)
|
|
25
27
|
subject.authenticate_resource_owner.call(nil)
|
|
26
28
|
end
|
|
27
29
|
end
|
|
28
30
|
|
|
29
|
-
describe
|
|
30
|
-
it
|
|
31
|
+
describe "resource_owner_from_credentials" do
|
|
32
|
+
it "sets the block that is accessible via authenticate_resource_owner" do
|
|
31
33
|
block = proc {}
|
|
32
34
|
Doorkeeper.configure do
|
|
33
35
|
orm DOORKEEPER_ORM
|
|
@@ -37,37 +39,37 @@ describe Doorkeeper, 'configuration' do
|
|
|
37
39
|
expect(subject.resource_owner_from_credentials).to eq(block)
|
|
38
40
|
end
|
|
39
41
|
|
|
40
|
-
it
|
|
42
|
+
it "prints warning message by default" do
|
|
41
43
|
Doorkeeper.configure do
|
|
42
44
|
orm DOORKEEPER_ORM
|
|
43
45
|
end
|
|
44
46
|
|
|
45
47
|
expect(Rails.logger).to receive(:warn).with(
|
|
46
|
-
I18n.t(
|
|
48
|
+
I18n.t("doorkeeper.errors.messages.credential_flow_not_configured")
|
|
47
49
|
)
|
|
48
50
|
subject.resource_owner_from_credentials.call(nil)
|
|
49
51
|
end
|
|
50
52
|
end
|
|
51
53
|
|
|
52
|
-
describe
|
|
53
|
-
it
|
|
54
|
+
describe "setup_orm_adapter" do
|
|
55
|
+
it "adds specific error message to NameError exception" do
|
|
54
56
|
expect do
|
|
55
|
-
Doorkeeper.configure { orm
|
|
57
|
+
Doorkeeper.configure { orm "hibernate" }
|
|
56
58
|
end.to raise_error(NameError, /ORM adapter not found \(hibernate\)/)
|
|
57
59
|
end
|
|
58
60
|
|
|
59
|
-
it
|
|
60
|
-
|
|
61
|
+
it "does not change other exceptions" do
|
|
62
|
+
allow(Doorkeeper).to receive(:setup_orm_adapter) { raise NoMethodError }
|
|
61
63
|
|
|
62
64
|
expect do
|
|
63
|
-
Doorkeeper.configure { orm
|
|
64
|
-
end.to raise_error(NoMethodError
|
|
65
|
+
Doorkeeper.configure { orm "hibernate" }
|
|
66
|
+
end.to raise_error(NoMethodError)
|
|
65
67
|
end
|
|
66
68
|
end
|
|
67
69
|
|
|
68
|
-
describe
|
|
69
|
-
it
|
|
70
|
-
default_behaviour =
|
|
70
|
+
describe "admin_authenticator" do
|
|
71
|
+
it "sets the block that is accessible via authenticate_admin" do
|
|
72
|
+
default_behaviour = "default behaviour"
|
|
71
73
|
allow(Doorkeeper::Config).to receive(:head).and_return(default_behaviour)
|
|
72
74
|
|
|
73
75
|
Doorkeeper.configure do
|
|
@@ -77,7 +79,7 @@ describe Doorkeeper, 'configuration' do
|
|
|
77
79
|
expect(subject.authenticate_admin.call({})).to eq(default_behaviour)
|
|
78
80
|
end
|
|
79
81
|
|
|
80
|
-
it
|
|
82
|
+
it "sets the block that is accessible via authenticate_admin" do
|
|
81
83
|
block = proc {}
|
|
82
84
|
Doorkeeper.configure do
|
|
83
85
|
orm DOORKEEPER_ORM
|
|
@@ -88,12 +90,12 @@ describe Doorkeeper, 'configuration' do
|
|
|
88
90
|
end
|
|
89
91
|
end
|
|
90
92
|
|
|
91
|
-
describe
|
|
92
|
-
it
|
|
93
|
+
describe "access_token_expires_in" do
|
|
94
|
+
it "has 2 hours by default" do
|
|
93
95
|
expect(subject.access_token_expires_in).to eq(2.hours)
|
|
94
96
|
end
|
|
95
97
|
|
|
96
|
-
it
|
|
98
|
+
it "can change the value" do
|
|
97
99
|
Doorkeeper.configure do
|
|
98
100
|
orm DOORKEEPER_ORM
|
|
99
101
|
access_token_expires_in 4.hours
|
|
@@ -101,7 +103,7 @@ describe Doorkeeper, 'configuration' do
|
|
|
101
103
|
expect(subject.access_token_expires_in).to eq(4.hours)
|
|
102
104
|
end
|
|
103
105
|
|
|
104
|
-
it
|
|
106
|
+
it "can be set to nil" do
|
|
105
107
|
Doorkeeper.configure do
|
|
106
108
|
orm DOORKEEPER_ORM
|
|
107
109
|
access_token_expires_in nil
|
|
@@ -111,42 +113,58 @@ describe Doorkeeper, 'configuration' do
|
|
|
111
113
|
end
|
|
112
114
|
end
|
|
113
115
|
|
|
114
|
-
describe
|
|
115
|
-
it
|
|
116
|
+
describe "scopes" do
|
|
117
|
+
it "has default scopes" do
|
|
116
118
|
Doorkeeper.configure do
|
|
117
119
|
orm DOORKEEPER_ORM
|
|
118
120
|
default_scopes :public
|
|
119
121
|
end
|
|
120
122
|
|
|
121
|
-
expect(subject.default_scopes).to include(
|
|
123
|
+
expect(subject.default_scopes).to include("public")
|
|
122
124
|
end
|
|
123
125
|
|
|
124
|
-
it
|
|
126
|
+
it "has optional scopes" do
|
|
125
127
|
Doorkeeper.configure do
|
|
126
128
|
orm DOORKEEPER_ORM
|
|
127
129
|
optional_scopes :write, :update
|
|
128
130
|
end
|
|
129
131
|
|
|
130
|
-
expect(subject.optional_scopes).to include(
|
|
132
|
+
expect(subject.optional_scopes).to include("write", "update")
|
|
131
133
|
end
|
|
132
134
|
|
|
133
|
-
it
|
|
135
|
+
it "has all scopes" do
|
|
134
136
|
Doorkeeper.configure do
|
|
135
137
|
orm DOORKEEPER_ORM
|
|
136
138
|
default_scopes :normal
|
|
137
139
|
optional_scopes :admin
|
|
138
140
|
end
|
|
139
141
|
|
|
140
|
-
expect(subject.scopes).to include(
|
|
142
|
+
expect(subject.scopes).to include("normal", "admin")
|
|
141
143
|
end
|
|
142
144
|
end
|
|
143
145
|
|
|
144
|
-
describe
|
|
145
|
-
it
|
|
146
|
+
describe "scopes_by_grant_type" do
|
|
147
|
+
it "is {} by default" do
|
|
148
|
+
expect(subject.scopes_by_grant_type).to eq({})
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
it "has hash value" do
|
|
152
|
+
hash = {}
|
|
153
|
+
Doorkeeper.configure do
|
|
154
|
+
orm DOORKEEPER_ORM
|
|
155
|
+
scopes_by_grant_type hash
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
expect(subject.scopes_by_grant_type).to eq(hash)
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
describe "use_refresh_token" do
|
|
163
|
+
it "is false by default" do
|
|
146
164
|
expect(subject.refresh_token_enabled?).to eq(false)
|
|
147
165
|
end
|
|
148
166
|
|
|
149
|
-
it
|
|
167
|
+
it "can change the value" do
|
|
150
168
|
Doorkeeper.configure do
|
|
151
169
|
orm DOORKEEPER_ORM
|
|
152
170
|
use_refresh_token
|
|
@@ -155,7 +173,7 @@ describe Doorkeeper, 'configuration' do
|
|
|
155
173
|
expect(subject.refresh_token_enabled?).to eq(true)
|
|
156
174
|
end
|
|
157
175
|
|
|
158
|
-
it
|
|
176
|
+
it "can accept a boolean parameter" do
|
|
159
177
|
Doorkeeper.configure do
|
|
160
178
|
orm DOORKEEPER_ORM
|
|
161
179
|
use_refresh_token false
|
|
@@ -164,7 +182,7 @@ describe Doorkeeper, 'configuration' do
|
|
|
164
182
|
expect(subject.refresh_token_enabled?).to eq(false)
|
|
165
183
|
end
|
|
166
184
|
|
|
167
|
-
it
|
|
185
|
+
it "can accept a block parameter" do
|
|
168
186
|
Doorkeeper.configure do
|
|
169
187
|
orm DOORKEEPER_ORM
|
|
170
188
|
use_refresh_token { |_context| nil }
|
|
@@ -174,7 +192,7 @@ describe Doorkeeper, 'configuration' do
|
|
|
174
192
|
end
|
|
175
193
|
|
|
176
194
|
it "does not includes 'refresh_token' in authorization_response_types" do
|
|
177
|
-
expect(subject.token_grant_types).not_to include
|
|
195
|
+
expect(subject.token_grant_types).not_to include "refresh_token"
|
|
178
196
|
end
|
|
179
197
|
|
|
180
198
|
context "is enabled" do
|
|
@@ -186,17 +204,42 @@ describe Doorkeeper, 'configuration' do
|
|
|
186
204
|
end
|
|
187
205
|
|
|
188
206
|
it "includes 'refresh_token' in authorization_response_types" do
|
|
189
|
-
expect(subject.token_grant_types).to include
|
|
207
|
+
expect(subject.token_grant_types).to include "refresh_token"
|
|
190
208
|
end
|
|
191
209
|
end
|
|
192
210
|
end
|
|
193
211
|
|
|
194
|
-
describe
|
|
195
|
-
it
|
|
212
|
+
describe "token_reuse_limit" do
|
|
213
|
+
it "is 100 by default" do
|
|
214
|
+
expect(subject.token_reuse_limit).to eq(100)
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
it "can change the value" do
|
|
218
|
+
Doorkeeper.configure do
|
|
219
|
+
token_reuse_limit 90
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
expect(subject.token_reuse_limit).to eq(90)
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
it "sets the value to 100 if invalid value is being set" do
|
|
226
|
+
expect(Rails.logger).to receive(:warn).with(/will be set to default 100/)
|
|
227
|
+
|
|
228
|
+
Doorkeeper.configure do
|
|
229
|
+
reuse_access_token
|
|
230
|
+
token_reuse_limit 110
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
expect(subject.token_reuse_limit).to eq(100)
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
describe "enforce_configured_scopes" do
|
|
238
|
+
it "is false by default" do
|
|
196
239
|
expect(subject.enforce_configured_scopes?).to eq(false)
|
|
197
240
|
end
|
|
198
241
|
|
|
199
|
-
it
|
|
242
|
+
it "can change the value" do
|
|
200
243
|
Doorkeeper.configure do
|
|
201
244
|
orm DOORKEEPER_ORM
|
|
202
245
|
enforce_configured_scopes
|
|
@@ -206,13 +249,13 @@ describe Doorkeeper, 'configuration' do
|
|
|
206
249
|
end
|
|
207
250
|
end
|
|
208
251
|
|
|
209
|
-
describe
|
|
210
|
-
it
|
|
252
|
+
describe "client_credentials" do
|
|
253
|
+
it "has defaults order" do
|
|
211
254
|
expect(subject.client_credentials_methods)
|
|
212
255
|
.to eq(%i[from_basic from_params])
|
|
213
256
|
end
|
|
214
257
|
|
|
215
|
-
it
|
|
258
|
+
it "can change the value" do
|
|
216
259
|
Doorkeeper.configure do
|
|
217
260
|
orm DOORKEEPER_ORM
|
|
218
261
|
client_credentials :from_digest, :from_params
|
|
@@ -223,12 +266,12 @@ describe Doorkeeper, 'configuration' do
|
|
|
223
266
|
end
|
|
224
267
|
end
|
|
225
268
|
|
|
226
|
-
describe
|
|
227
|
-
it
|
|
269
|
+
describe "force_ssl_in_redirect_uri" do
|
|
270
|
+
it "is true by default in non-development environments" do
|
|
228
271
|
expect(subject.force_ssl_in_redirect_uri).to eq(true)
|
|
229
272
|
end
|
|
230
273
|
|
|
231
|
-
it
|
|
274
|
+
it "can change the value" do
|
|
232
275
|
Doorkeeper.configure do
|
|
233
276
|
orm DOORKEEPER_ORM
|
|
234
277
|
force_ssl_in_redirect_uri(false)
|
|
@@ -237,7 +280,7 @@ describe Doorkeeper, 'configuration' do
|
|
|
237
280
|
expect(subject.force_ssl_in_redirect_uri).to eq(false)
|
|
238
281
|
end
|
|
239
282
|
|
|
240
|
-
it
|
|
283
|
+
it "can be a callable object" do
|
|
241
284
|
block = proc { false }
|
|
242
285
|
Doorkeeper.configure do
|
|
243
286
|
orm DOORKEEPER_ORM
|
|
@@ -249,13 +292,13 @@ describe Doorkeeper, 'configuration' do
|
|
|
249
292
|
end
|
|
250
293
|
end
|
|
251
294
|
|
|
252
|
-
describe
|
|
253
|
-
it
|
|
295
|
+
describe "access_token_methods" do
|
|
296
|
+
it "has defaults order" do
|
|
254
297
|
expect(subject.access_token_methods)
|
|
255
298
|
.to eq(%i[from_bearer_authorization from_access_token_param from_bearer_param])
|
|
256
299
|
end
|
|
257
300
|
|
|
258
|
-
it
|
|
301
|
+
it "can change the value" do
|
|
259
302
|
Doorkeeper.configure do
|
|
260
303
|
orm DOORKEEPER_ORM
|
|
261
304
|
access_token_methods :from_access_token_param, :from_bearer_param
|
|
@@ -266,12 +309,12 @@ describe Doorkeeper, 'configuration' do
|
|
|
266
309
|
end
|
|
267
310
|
end
|
|
268
311
|
|
|
269
|
-
describe
|
|
270
|
-
it
|
|
271
|
-
expect(subject.forbid_redirect_uri.call(URI.parse(
|
|
312
|
+
describe "forbid_redirect_uri" do
|
|
313
|
+
it "is false by default" do
|
|
314
|
+
expect(subject.forbid_redirect_uri.call(URI.parse("https://localhost"))).to eq(false)
|
|
272
315
|
end
|
|
273
316
|
|
|
274
|
-
it
|
|
317
|
+
it "can be a callable object" do
|
|
275
318
|
block = proc { true }
|
|
276
319
|
Doorkeeper.configure do
|
|
277
320
|
orm DOORKEEPER_ORM
|
|
@@ -283,12 +326,12 @@ describe Doorkeeper, 'configuration' do
|
|
|
283
326
|
end
|
|
284
327
|
end
|
|
285
328
|
|
|
286
|
-
describe
|
|
287
|
-
it
|
|
329
|
+
describe "enable_application_owner" do
|
|
330
|
+
it "is disabled by default" do
|
|
288
331
|
expect(Doorkeeper.configuration.enable_application_owner?).not_to eq(true)
|
|
289
332
|
end
|
|
290
333
|
|
|
291
|
-
context
|
|
334
|
+
context "when enabled without confirmation" do
|
|
292
335
|
before do
|
|
293
336
|
Doorkeeper.configure do
|
|
294
337
|
orm DOORKEEPER_ORM
|
|
@@ -296,16 +339,16 @@ describe Doorkeeper, 'configuration' do
|
|
|
296
339
|
end
|
|
297
340
|
end
|
|
298
341
|
|
|
299
|
-
it
|
|
342
|
+
it "adds support for application owner" do
|
|
300
343
|
expect(Doorkeeper::Application.new).to respond_to :owner
|
|
301
344
|
end
|
|
302
345
|
|
|
303
|
-
it
|
|
346
|
+
it "Doorkeeper.configuration.confirm_application_owner? returns false" do
|
|
304
347
|
expect(Doorkeeper.configuration.confirm_application_owner?).not_to eq(true)
|
|
305
348
|
end
|
|
306
349
|
end
|
|
307
350
|
|
|
308
|
-
context
|
|
351
|
+
context "when enabled with confirmation set to true" do
|
|
309
352
|
before do
|
|
310
353
|
Doorkeeper.configure do
|
|
311
354
|
orm DOORKEEPER_ORM
|
|
@@ -313,28 +356,28 @@ describe Doorkeeper, 'configuration' do
|
|
|
313
356
|
end
|
|
314
357
|
end
|
|
315
358
|
|
|
316
|
-
it
|
|
359
|
+
it "adds support for application owner" do
|
|
317
360
|
expect(Doorkeeper::Application.new).to respond_to :owner
|
|
318
361
|
end
|
|
319
362
|
|
|
320
|
-
it
|
|
363
|
+
it "Doorkeeper.configuration.confirm_application_owner? returns true" do
|
|
321
364
|
expect(Doorkeeper.configuration.confirm_application_owner?).to eq(true)
|
|
322
365
|
end
|
|
323
366
|
end
|
|
324
367
|
end
|
|
325
368
|
|
|
326
|
-
describe
|
|
327
|
-
it
|
|
328
|
-
expect(Doorkeeper.configuration.realm).to eq(
|
|
369
|
+
describe "realm" do
|
|
370
|
+
it "is 'Doorkeeper' by default" do
|
|
371
|
+
expect(Doorkeeper.configuration.realm).to eq("Doorkeeper")
|
|
329
372
|
end
|
|
330
373
|
|
|
331
|
-
it
|
|
374
|
+
it "can change the value" do
|
|
332
375
|
Doorkeeper.configure do
|
|
333
376
|
orm DOORKEEPER_ORM
|
|
334
|
-
realm
|
|
377
|
+
realm "Example"
|
|
335
378
|
end
|
|
336
379
|
|
|
337
|
-
expect(subject.realm).to eq(
|
|
380
|
+
expect(subject.realm).to eq("Example")
|
|
338
381
|
end
|
|
339
382
|
end
|
|
340
383
|
|
|
@@ -357,16 +400,16 @@ describe Doorkeeper, 'configuration' do
|
|
|
357
400
|
before do
|
|
358
401
|
Doorkeeper.configure do
|
|
359
402
|
orm DOORKEEPER_ORM
|
|
360
|
-
grant_flows [
|
|
403
|
+
grant_flows ["authorization_code"]
|
|
361
404
|
end
|
|
362
405
|
end
|
|
363
406
|
|
|
364
407
|
it "includes 'code' in authorization_response_types" do
|
|
365
|
-
expect(subject.authorization_response_types).to include
|
|
408
|
+
expect(subject.authorization_response_types).to include "code"
|
|
366
409
|
end
|
|
367
410
|
|
|
368
411
|
it "includes 'authorization_code' in token_grant_types" do
|
|
369
|
-
expect(subject.token_grant_types).to include
|
|
412
|
+
expect(subject.token_grant_types).to include "authorization_code"
|
|
370
413
|
end
|
|
371
414
|
end
|
|
372
415
|
|
|
@@ -374,12 +417,12 @@ describe Doorkeeper, 'configuration' do
|
|
|
374
417
|
before do
|
|
375
418
|
Doorkeeper.configure do
|
|
376
419
|
orm DOORKEEPER_ORM
|
|
377
|
-
grant_flows [
|
|
420
|
+
grant_flows ["implicit"]
|
|
378
421
|
end
|
|
379
422
|
end
|
|
380
423
|
|
|
381
424
|
it "includes 'token' in authorization_response_types" do
|
|
382
|
-
expect(subject.authorization_response_types).to include
|
|
425
|
+
expect(subject.authorization_response_types).to include "token"
|
|
383
426
|
end
|
|
384
427
|
end
|
|
385
428
|
|
|
@@ -387,12 +430,12 @@ describe Doorkeeper, 'configuration' do
|
|
|
387
430
|
before do
|
|
388
431
|
Doorkeeper.configure do
|
|
389
432
|
orm DOORKEEPER_ORM
|
|
390
|
-
grant_flows [
|
|
433
|
+
grant_flows ["password"]
|
|
391
434
|
end
|
|
392
435
|
end
|
|
393
436
|
|
|
394
437
|
it "includes 'password' in token_grant_types" do
|
|
395
|
-
expect(subject.token_grant_types).to include
|
|
438
|
+
expect(subject.token_grant_types).to include "password"
|
|
396
439
|
end
|
|
397
440
|
end
|
|
398
441
|
|
|
@@ -400,17 +443,17 @@ describe Doorkeeper, 'configuration' do
|
|
|
400
443
|
before do
|
|
401
444
|
Doorkeeper.configure do
|
|
402
445
|
orm DOORKEEPER_ORM
|
|
403
|
-
grant_flows [
|
|
446
|
+
grant_flows ["client_credentials"]
|
|
404
447
|
end
|
|
405
448
|
end
|
|
406
449
|
|
|
407
450
|
it "includes 'client_credentials' in token_grant_types" do
|
|
408
|
-
expect(subject.token_grant_types).to include
|
|
451
|
+
expect(subject.token_grant_types).to include "client_credentials"
|
|
409
452
|
end
|
|
410
453
|
end
|
|
411
454
|
end
|
|
412
455
|
|
|
413
|
-
it
|
|
456
|
+
it "raises an exception when configuration is not set" do
|
|
414
457
|
old_config = Doorkeeper.configuration
|
|
415
458
|
Doorkeeper.module_eval do
|
|
416
459
|
@config = nil
|
|
@@ -425,41 +468,57 @@ describe Doorkeeper, 'configuration' do
|
|
|
425
468
|
end
|
|
426
469
|
end
|
|
427
470
|
|
|
428
|
-
describe
|
|
429
|
-
it
|
|
471
|
+
describe "access_token_generator" do
|
|
472
|
+
it "is 'Doorkeeper::OAuth::Helpers::UniqueToken' by default" do
|
|
430
473
|
expect(Doorkeeper.configuration.access_token_generator).to(
|
|
431
|
-
eq(
|
|
474
|
+
eq("Doorkeeper::OAuth::Helpers::UniqueToken")
|
|
432
475
|
)
|
|
433
476
|
end
|
|
434
477
|
|
|
435
|
-
it
|
|
478
|
+
it "can change the value" do
|
|
436
479
|
Doorkeeper.configure do
|
|
437
480
|
orm DOORKEEPER_ORM
|
|
438
|
-
access_token_generator
|
|
481
|
+
access_token_generator "Example"
|
|
439
482
|
end
|
|
440
|
-
expect(subject.access_token_generator).to eq(
|
|
483
|
+
expect(subject.access_token_generator).to eq("Example")
|
|
441
484
|
end
|
|
442
485
|
end
|
|
443
486
|
|
|
444
|
-
describe
|
|
445
|
-
|
|
446
|
-
|
|
487
|
+
describe "default_generator_method" do
|
|
488
|
+
it "is :urlsafe_base64 by default" do
|
|
489
|
+
expect(Doorkeeper.configuration.default_generator_method)
|
|
490
|
+
.to eq(:urlsafe_base64)
|
|
447
491
|
end
|
|
448
492
|
|
|
449
|
-
|
|
493
|
+
it "can change the value" do
|
|
494
|
+
Doorkeeper.configure do
|
|
495
|
+
orm DOORKEEPER_ORM
|
|
496
|
+
default_generator_method :hex
|
|
497
|
+
end
|
|
498
|
+
|
|
499
|
+
expect(subject.default_generator_method).to eq(:hex)
|
|
500
|
+
end
|
|
501
|
+
end
|
|
502
|
+
|
|
503
|
+
describe "base_controller" do
|
|
504
|
+
context "default" do
|
|
505
|
+
it { expect(Doorkeeper.configuration.base_controller).to eq("ActionController::Base") }
|
|
506
|
+
end
|
|
507
|
+
|
|
508
|
+
context "custom" do
|
|
450
509
|
before do
|
|
451
510
|
Doorkeeper.configure do
|
|
452
511
|
orm DOORKEEPER_ORM
|
|
453
|
-
base_controller
|
|
512
|
+
base_controller "ApplicationController"
|
|
454
513
|
end
|
|
455
514
|
end
|
|
456
515
|
|
|
457
|
-
it { expect(Doorkeeper.configuration.base_controller).to eq(
|
|
516
|
+
it { expect(Doorkeeper.configuration.base_controller).to eq("ApplicationController") }
|
|
458
517
|
end
|
|
459
518
|
end
|
|
460
519
|
|
|
461
520
|
if DOORKEEPER_ORM == :active_record
|
|
462
|
-
describe
|
|
521
|
+
describe "active_record_options" do
|
|
463
522
|
let(:models) { [Doorkeeper::AccessGrant, Doorkeeper::AccessToken, Doorkeeper::Application] }
|
|
464
523
|
|
|
465
524
|
before do
|
|
@@ -468,7 +527,7 @@ describe Doorkeeper, 'configuration' do
|
|
|
468
527
|
end
|
|
469
528
|
end
|
|
470
529
|
|
|
471
|
-
it
|
|
530
|
+
it "establishes connection for Doorkeeper models based on options" do
|
|
472
531
|
models.each do |model|
|
|
473
532
|
expect(model).to receive(:establish_connection)
|
|
474
533
|
end
|
|
@@ -498,8 +557,8 @@ describe Doorkeeper, 'configuration' do
|
|
|
498
557
|
end
|
|
499
558
|
end
|
|
500
559
|
|
|
501
|
-
describe
|
|
502
|
-
it
|
|
560
|
+
describe "strict_content_type" do
|
|
561
|
+
it "is false by default" do
|
|
503
562
|
expect(subject.enforce_content_type).to eq(false)
|
|
504
563
|
end
|
|
505
564
|
|
|
@@ -513,11 +572,11 @@ describe Doorkeeper, 'configuration' do
|
|
|
513
572
|
end
|
|
514
573
|
end
|
|
515
574
|
|
|
516
|
-
describe
|
|
517
|
-
it
|
|
575
|
+
describe "handle_auth_errors" do
|
|
576
|
+
it "is set to render by default" do
|
|
518
577
|
expect(Doorkeeper.configuration.handle_auth_errors).to eq(:render)
|
|
519
578
|
end
|
|
520
|
-
it
|
|
579
|
+
it "can change the value" do
|
|
521
580
|
Doorkeeper.configure do
|
|
522
581
|
orm DOORKEEPER_ORM
|
|
523
582
|
handle_auth_errors :raise
|
|
@@ -525,4 +584,114 @@ describe Doorkeeper, 'configuration' do
|
|
|
525
584
|
expect(subject.handle_auth_errors).to eq(:raise)
|
|
526
585
|
end
|
|
527
586
|
end
|
|
587
|
+
|
|
588
|
+
describe "token_secret_strategy" do
|
|
589
|
+
it "is plain by default" do
|
|
590
|
+
expect(subject.token_secret_strategy).to eq(Doorkeeper::SecretStoring::Plain)
|
|
591
|
+
expect(subject.token_secret_fallback_strategy).to eq(nil)
|
|
592
|
+
end
|
|
593
|
+
|
|
594
|
+
context "when provided" do
|
|
595
|
+
before do
|
|
596
|
+
Doorkeeper.configure do
|
|
597
|
+
hash_token_secrets
|
|
598
|
+
end
|
|
599
|
+
end
|
|
600
|
+
|
|
601
|
+
it "will enable hashing for applications" do
|
|
602
|
+
expect(subject.token_secret_strategy).to eq(Doorkeeper::SecretStoring::Sha256Hash)
|
|
603
|
+
expect(subject.token_secret_fallback_strategy).to eq(nil)
|
|
604
|
+
end
|
|
605
|
+
end
|
|
606
|
+
|
|
607
|
+
context "when manually provided with invalid constant" do
|
|
608
|
+
it "raises an exception" do
|
|
609
|
+
expect do
|
|
610
|
+
Doorkeeper.configure do
|
|
611
|
+
hash_token_secrets using: "does not exist"
|
|
612
|
+
end
|
|
613
|
+
end.to raise_error(NameError)
|
|
614
|
+
end
|
|
615
|
+
end
|
|
616
|
+
|
|
617
|
+
context "when manually provided with invalid option" do
|
|
618
|
+
it "raises an exception" do
|
|
619
|
+
expect do
|
|
620
|
+
Doorkeeper.configure do
|
|
621
|
+
hash_token_secrets using: "Doorkeeper::SecretStoring::BCrypt"
|
|
622
|
+
end
|
|
623
|
+
end.to raise_error(ArgumentError,
|
|
624
|
+
/can only be used for storing application secrets/)
|
|
625
|
+
end
|
|
626
|
+
end
|
|
627
|
+
|
|
628
|
+
context "when provided with fallback" do
|
|
629
|
+
before do
|
|
630
|
+
Doorkeeper.configure do
|
|
631
|
+
hash_token_secrets fallback: :plain
|
|
632
|
+
end
|
|
633
|
+
end
|
|
634
|
+
|
|
635
|
+
it "will enable hashing for applications" do
|
|
636
|
+
expect(subject.token_secret_strategy).to eq(Doorkeeper::SecretStoring::Sha256Hash)
|
|
637
|
+
expect(subject.token_secret_fallback_strategy).to eq(Doorkeeper::SecretStoring::Plain)
|
|
638
|
+
end
|
|
639
|
+
end
|
|
640
|
+
|
|
641
|
+
describe "hash_token_secrets together with reuse_access_token" do
|
|
642
|
+
it "will disable reuse_access_token" do
|
|
643
|
+
expect(Rails.logger).to receive(:warn).with(/reuse_access_token will be disabled/)
|
|
644
|
+
|
|
645
|
+
Doorkeeper.configure do
|
|
646
|
+
reuse_access_token
|
|
647
|
+
hash_token_secrets
|
|
648
|
+
end
|
|
649
|
+
|
|
650
|
+
expect(subject.reuse_access_token).to eq(false)
|
|
651
|
+
end
|
|
652
|
+
end
|
|
653
|
+
end
|
|
654
|
+
|
|
655
|
+
describe "application_secret_strategy" do
|
|
656
|
+
it "is plain by default" do
|
|
657
|
+
expect(subject.application_secret_strategy).to eq(Doorkeeper::SecretStoring::Plain)
|
|
658
|
+
expect(subject.application_secret_fallback_strategy).to eq(nil)
|
|
659
|
+
end
|
|
660
|
+
|
|
661
|
+
context "when provided" do
|
|
662
|
+
before do
|
|
663
|
+
Doorkeeper.configure do
|
|
664
|
+
hash_application_secrets
|
|
665
|
+
end
|
|
666
|
+
end
|
|
667
|
+
|
|
668
|
+
it "will enable hashing for applications" do
|
|
669
|
+
expect(subject.application_secret_strategy).to eq(Doorkeeper::SecretStoring::Sha256Hash)
|
|
670
|
+
expect(subject.application_secret_fallback_strategy).to eq(nil)
|
|
671
|
+
end
|
|
672
|
+
end
|
|
673
|
+
|
|
674
|
+
context "when manually provided with invalid constant" do
|
|
675
|
+
it "raises an exception" do
|
|
676
|
+
expect do
|
|
677
|
+
Doorkeeper.configure do
|
|
678
|
+
hash_application_secrets using: "does not exist"
|
|
679
|
+
end
|
|
680
|
+
end.to raise_error(NameError)
|
|
681
|
+
end
|
|
682
|
+
end
|
|
683
|
+
|
|
684
|
+
context "when provided with fallback" do
|
|
685
|
+
before do
|
|
686
|
+
Doorkeeper.configure do
|
|
687
|
+
hash_application_secrets fallback: :plain
|
|
688
|
+
end
|
|
689
|
+
end
|
|
690
|
+
|
|
691
|
+
it "will enable hashing for applications" do
|
|
692
|
+
expect(subject.application_secret_strategy).to eq(Doorkeeper::SecretStoring::Sha256Hash)
|
|
693
|
+
expect(subject.application_secret_fallback_strategy).to eq(Doorkeeper::SecretStoring::Plain)
|
|
694
|
+
end
|
|
695
|
+
end
|
|
696
|
+
end
|
|
528
697
|
end
|