doorkeeper 4.2.6 → 4.3.0

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.

Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE.md +19 -0
  3. data/.github/PULL_REQUEST_TEMPLATE.md +17 -0
  4. data/.gitignore +1 -1
  5. data/.hound.yml +2 -13
  6. data/.rubocop.yml +13 -0
  7. data/.travis.yml +13 -5
  8. data/Appraisals +6 -2
  9. data/CODE_OF_CONDUCT.md +46 -0
  10. data/Gemfile +1 -1
  11. data/NEWS.md +24 -0
  12. data/README.md +39 -9
  13. data/SECURITY.md +13 -0
  14. data/app/controllers/doorkeeper/application_controller.rb +1 -5
  15. data/app/controllers/doorkeeper/applications_controller.rb +14 -1
  16. data/app/controllers/doorkeeper/tokens_controller.rb +13 -1
  17. data/app/helpers/doorkeeper/dashboard_helper.rb +4 -2
  18. data/app/validators/redirect_uri_validator.rb +12 -2
  19. data/app/views/doorkeeper/applications/_form.html.erb +1 -1
  20. data/app/views/doorkeeper/authorized_applications/index.html.erb +0 -1
  21. data/config/locales/en.yml +3 -5
  22. data/doorkeeper.gemspec +4 -3
  23. data/gemfiles/rails_4_2.gemfile +6 -4
  24. data/gemfiles/rails_5_0.gemfile +4 -4
  25. data/gemfiles/rails_5_1.gemfile +6 -7
  26. data/gemfiles/rails_5_2.gemfile +12 -0
  27. data/gemfiles/rails_master.gemfile +14 -0
  28. data/lib/doorkeeper.rb +1 -0
  29. data/lib/doorkeeper/config.rb +55 -55
  30. data/lib/doorkeeper/engine.rb +3 -3
  31. data/lib/doorkeeper/grape/helpers.rb +13 -8
  32. data/lib/doorkeeper/helpers/controller.rb +8 -4
  33. data/lib/doorkeeper/models/access_token_mixin.rb +14 -7
  34. data/lib/doorkeeper/models/application_mixin.rb +11 -6
  35. data/lib/doorkeeper/models/concerns/expirable.rb +7 -5
  36. data/lib/doorkeeper/oauth/authorization/token.rb +22 -18
  37. data/lib/doorkeeper/oauth/authorization_code_request.rb +6 -1
  38. data/lib/doorkeeper/oauth/base_request.rb +5 -5
  39. data/lib/doorkeeper/oauth/client.rb +2 -2
  40. data/lib/doorkeeper/oauth/client/credentials.rb +2 -2
  41. data/lib/doorkeeper/oauth/error.rb +2 -2
  42. data/lib/doorkeeper/oauth/error_response.rb +1 -2
  43. data/lib/doorkeeper/oauth/forbidden_token_response.rb +1 -1
  44. data/lib/doorkeeper/oauth/invalid_token_response.rb +2 -3
  45. data/lib/doorkeeper/oauth/password_access_token_request.rb +1 -0
  46. data/lib/doorkeeper/oauth/refresh_token_request.rb +1 -0
  47. data/lib/doorkeeper/oauth/scopes.rb +18 -8
  48. data/lib/doorkeeper/oauth/token.rb +1 -1
  49. data/lib/doorkeeper/oauth/token_introspection.rb +128 -0
  50. data/lib/doorkeeper/orm/active_record.rb +20 -8
  51. data/lib/doorkeeper/orm/active_record/access_grant.rb +1 -1
  52. data/lib/doorkeeper/orm/active_record/access_token.rb +1 -23
  53. data/lib/doorkeeper/orm/active_record/application.rb +1 -1
  54. data/lib/doorkeeper/orm/active_record/base_record.rb +11 -0
  55. data/lib/doorkeeper/rails/helpers.rb +5 -6
  56. data/lib/doorkeeper/rails/routes.rb +9 -7
  57. data/lib/doorkeeper/request.rb +7 -1
  58. data/lib/doorkeeper/validations.rb +3 -2
  59. data/lib/doorkeeper/version.rb +13 -1
  60. data/lib/generators/doorkeeper/application_owner_generator.rb +11 -2
  61. data/lib/generators/doorkeeper/migration_generator.rb +13 -1
  62. data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +7 -1
  63. data/lib/generators/doorkeeper/templates/{add_owner_to_application_migration.rb → add_owner_to_application_migration.rb.erb} +1 -1
  64. data/lib/generators/doorkeeper/templates/{add_previous_refresh_token_to_access_tokens.rb → add_previous_refresh_token_to_access_tokens.rb.erb} +1 -1
  65. data/lib/generators/doorkeeper/templates/initializer.rb +19 -3
  66. data/lib/generators/doorkeeper/templates/{migration.rb → migration.rb.erb} +1 -1
  67. data/spec/controllers/applications_controller_spec.rb +15 -4
  68. data/spec/controllers/authorizations_controller_spec.rb +5 -5
  69. data/spec/controllers/protected_resources_controller_spec.rb +28 -19
  70. data/spec/controllers/token_info_controller_spec.rb +17 -13
  71. data/spec/controllers/tokens_controller_spec.rb +138 -4
  72. data/spec/dummy/config/initializers/doorkeeper.rb +1 -1
  73. data/spec/dummy/config/initializers/{active_record_belongs_to_required_by_default.rb → new_framework_defaults.rb} +1 -1
  74. data/spec/dummy/config/initializers/secret_token.rb +0 -1
  75. data/spec/factories.rb +1 -1
  76. data/spec/generators/application_owner_generator_spec.rb +24 -5
  77. data/spec/generators/migration_generator_spec.rb +24 -3
  78. data/spec/generators/previous_refresh_token_generator_spec.rb +57 -0
  79. data/spec/grape/grape_integration_spec.rb +135 -0
  80. data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +1 -1
  81. data/spec/lib/config_spec.rb +115 -12
  82. data/spec/lib/models/revocable_spec.rb +2 -2
  83. data/spec/lib/oauth/authorization_code_request_spec.rb +39 -11
  84. data/spec/lib/oauth/base_request_spec.rb +2 -7
  85. data/spec/lib/oauth/client_credentials/creator_spec.rb +1 -1
  86. data/spec/lib/oauth/client_credentials_integration_spec.rb +1 -1
  87. data/spec/lib/oauth/client_credentials_request_spec.rb +1 -0
  88. data/spec/lib/oauth/code_request_spec.rb +1 -3
  89. data/spec/lib/oauth/helpers/uri_checker_spec.rb +5 -0
  90. data/spec/lib/oauth/invalid_token_response_spec.rb +1 -1
  91. data/spec/lib/oauth/password_access_token_request_spec.rb +9 -3
  92. data/spec/lib/oauth/refresh_token_request_spec.rb +19 -7
  93. data/spec/lib/oauth/scopes_spec.rb +28 -1
  94. data/spec/lib/oauth/token_request_spec.rb +6 -8
  95. data/spec/lib/server_spec.rb +10 -0
  96. data/spec/models/doorkeeper/access_grant_spec.rb +1 -1
  97. data/spec/models/doorkeeper/access_token_spec.rb +72 -48
  98. data/spec/models/doorkeeper/application_spec.rb +51 -18
  99. data/spec/requests/applications/applications_request_spec.rb +5 -5
  100. data/spec/requests/endpoints/token_spec.rb +8 -1
  101. data/spec/requests/flows/authorization_code_spec.rb +1 -0
  102. data/spec/requests/flows/client_credentials_spec.rb +1 -1
  103. data/spec/requests/flows/implicit_grant_errors_spec.rb +2 -2
  104. data/spec/requests/flows/refresh_token_spec.rb +4 -4
  105. data/spec/requests/flows/revoke_token_spec.rb +15 -15
  106. data/spec/requests/protected_resources/metal_spec.rb +1 -1
  107. data/spec/requests/protected_resources/private_api_spec.rb +1 -1
  108. data/spec/routing/custom_controller_routes_spec.rb +4 -0
  109. data/spec/routing/default_routes_spec.rb +5 -1
  110. data/spec/spec_helper_integration.rb +15 -4
  111. data/spec/support/dependencies/factory_girl.rb +2 -2
  112. data/spec/support/helpers/access_token_request_helper.rb +1 -1
  113. data/spec/support/helpers/model_helper.rb +9 -4
  114. data/spec/support/helpers/request_spec_helper.rb +7 -3
  115. data/spec/support/helpers/url_helper.rb +8 -8
  116. data/spec/support/shared/controllers_shared_context.rb +2 -6
  117. data/spec/support/shared/models_shared_examples.rb +4 -4
  118. data/spec/validators/redirect_uri_validator_spec.rb +51 -6
  119. data/spec/version/version_spec.rb +15 -0
  120. metadata +42 -13
@@ -10,13 +10,32 @@ describe 'Doorkeeper::ApplicationOwnerGenerator' do
10
10
  describe 'after running the generator' do
11
11
  before :each do
12
12
  prepare_destination
13
- FileUtils.mkdir(::File.expand_path('config', Pathname(destination_root)))
14
- FileUtils.copy_file(::File.expand_path('../templates/routes.rb', __FILE__), ::File.expand_path('config/routes.rb', Pathname.new(destination_root)))
15
- run_generator
16
13
  end
17
14
 
18
- it 'creates a migration' do
19
- assert_migration 'db/migrate/add_owner_to_application.rb'
15
+ context 'pre Rails 5.0.0' do
16
+ it 'creates a migration with no version specifier' do
17
+ stub_const("ActiveRecord::VERSION::MAJOR", 4)
18
+ stub_const("ActiveRecord::VERSION::MINOR", 2)
19
+
20
+ run_generator
21
+
22
+ assert_migration 'db/migrate/add_owner_to_application.rb' do |migration|
23
+ assert migration.include?("ActiveRecord::Migration\n")
24
+ end
25
+ end
26
+ end
27
+
28
+ context 'post Rails 5.0.0' do
29
+ it 'creates a migration with a version specifier' do
30
+ stub_const("ActiveRecord::VERSION::MAJOR", 5)
31
+ stub_const("ActiveRecord::VERSION::MINOR", 0)
32
+
33
+ run_generator
34
+
35
+ assert_migration 'db/migrate/add_owner_to_application.rb' do |migration|
36
+ assert migration.include?("ActiveRecord::Migration[5.0]\n")
37
+ end
38
+ end
20
39
  end
21
40
  end
22
41
  end
@@ -10,11 +10,32 @@ describe 'Doorkeeper::MigrationGenerator' do
10
10
  describe 'after running the generator' do
11
11
  before :each do
12
12
  prepare_destination
13
- run_generator
14
13
  end
15
14
 
16
- it 'creates a migration' do
17
- assert_migration 'db/migrate/create_doorkeeper_tables.rb'
15
+ context 'pre Rails 5.0.0' do
16
+ it 'creates a migration with no version specifier' do
17
+ stub_const('ActiveRecord::VERSION::MAJOR', 4)
18
+ stub_const('ActiveRecord::VERSION::MINOR', 2)
19
+
20
+ run_generator
21
+
22
+ assert_migration 'db/migrate/create_doorkeeper_tables.rb' do |migration|
23
+ assert migration.include?("ActiveRecord::Migration\n")
24
+ end
25
+ end
26
+ end
27
+
28
+ context 'post Rails 5.0.0' do
29
+ it 'creates a migration with a version specifier' do
30
+ stub_const('ActiveRecord::VERSION::MAJOR', 5)
31
+ stub_const('ActiveRecord::VERSION::MINOR', 0)
32
+
33
+ run_generator
34
+
35
+ assert_migration 'db/migrate/create_doorkeeper_tables.rb' do |migration|
36
+ assert migration.include?("ActiveRecord::Migration[5.0]\n")
37
+ end
38
+ end
18
39
  end
19
40
  end
20
41
  end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper_integration'
2
+ require 'generators/doorkeeper/previous_refresh_token_generator'
3
+
4
+ describe 'Doorkeeper::PreviousRefreshTokenGenerator' do
5
+ include GeneratorSpec::TestCase
6
+
7
+ tests Doorkeeper::PreviousRefreshTokenGenerator
8
+ destination ::File.expand_path('../tmp/dummy', __FILE__)
9
+
10
+ describe 'after running the generator' do
11
+ before :each do
12
+ prepare_destination
13
+
14
+ allow_any_instance_of(Doorkeeper::PreviousRefreshTokenGenerator).to(
15
+ receive(:no_previous_refresh_token_column?).and_return(true)
16
+ )
17
+ end
18
+
19
+ context 'pre Rails 5.0.0' do
20
+ it 'creates a migration with no version specifier' do
21
+ stub_const('ActiveRecord::VERSION::MAJOR', 4)
22
+ stub_const('ActiveRecord::VERSION::MINOR', 2)
23
+
24
+ run_generator
25
+
26
+ assert_migration 'db/migrate/add_previous_refresh_token_to_access_tokens.rb' do |migration|
27
+ assert migration.include?("ActiveRecord::Migration\n")
28
+ end
29
+ end
30
+ end
31
+
32
+ context 'post Rails 5.0.0' do
33
+ it 'creates a migration with a version specifier' do
34
+ stub_const('ActiveRecord::VERSION::MAJOR', 5)
35
+ stub_const('ActiveRecord::VERSION::MINOR', 0)
36
+
37
+ run_generator
38
+
39
+ assert_migration 'db/migrate/add_previous_refresh_token_to_access_tokens.rb' do |migration|
40
+ assert migration.include?("ActiveRecord::Migration[5.0]\n")
41
+ end
42
+ end
43
+ end
44
+
45
+ context 'already exist' do
46
+ it 'does not create a migration' do
47
+ allow_any_instance_of(Doorkeeper::PreviousRefreshTokenGenerator).to(
48
+ receive(:no_previous_refresh_token_column?).and_call_original
49
+ )
50
+
51
+ run_generator
52
+
53
+ assert_no_migration 'db/migrate/add_previous_refresh_token_to_access_tokens.rb'
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,135 @@
1
+ require 'spec_helper_integration'
2
+ require 'grape'
3
+ require 'rack/test'
4
+ require 'doorkeeper/grape/helpers'
5
+
6
+ # Test Grape API application
7
+ module GrapeApp
8
+ class API < Grape::API
9
+ version 'v1', using: :path
10
+ format :json
11
+ prefix :api
12
+
13
+ helpers Doorkeeper::Grape::Helpers
14
+
15
+ resource :protected do
16
+ before do
17
+ doorkeeper_authorize!
18
+ end
19
+
20
+ desc 'Protected resource, requires token.'
21
+
22
+ get :status do
23
+ { token: doorkeeper_token.token }
24
+ end
25
+ end
26
+
27
+ resource :protected_with_endpoint_scopes do
28
+ before do
29
+ doorkeeper_authorize!
30
+ end
31
+
32
+ desc 'Protected resource, requires token with scopes (defined in endpoint).'
33
+
34
+ get :status, scopes: [:admin] do
35
+ { response: 'OK' }
36
+ end
37
+ end
38
+
39
+ resource :protected_with_helper_scopes do
40
+ before do
41
+ doorkeeper_authorize! :admin
42
+ end
43
+
44
+ desc 'Protected resource, requires token with scopes (defined in helper).'
45
+
46
+ get :status do
47
+ { response: 'OK' }
48
+ end
49
+ end
50
+
51
+ resource :public do
52
+ desc "Public resource, no token required."
53
+
54
+ get :status do
55
+ { response: 'OK' }
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ describe 'Grape integration' do
62
+ include Rack::Test::Methods
63
+
64
+ def app
65
+ GrapeApp::API
66
+ end
67
+
68
+ def json_body
69
+ JSON.parse(last_response.body)
70
+ end
71
+
72
+ let(:client) { FactoryBot.create(:application) }
73
+ let(:resource) { FactoryBot.create(:doorkeeper_testing_user, name: 'Joe', password: 'sekret') }
74
+ let(:access_token) { client_is_authorized(client, resource) }
75
+
76
+ context 'with valid Access Token' do
77
+ it 'successfully requests protected resource' do
78
+ get "api/v1/protected/status.json?access_token=#{access_token.token}"
79
+
80
+ expect(last_response).to be_successful
81
+
82
+ expect(json_body['token']).to eq(access_token.token)
83
+ end
84
+
85
+ it 'successfully requests protected resource with token that has required scopes (Grape endpoint)' do
86
+ access_token = client_is_authorized(client, resource, scopes: 'admin')
87
+
88
+ get "api/v1/protected_with_endpoint_scopes/status.json?access_token=#{access_token.token}"
89
+
90
+ expect(last_response).to be_successful
91
+ expect(json_body).to have_key('response')
92
+ end
93
+
94
+ it 'successfully requests protected resource with token that has required scopes (Doorkeeper helper)' do
95
+ access_token = client_is_authorized(client, resource, scopes: 'admin')
96
+
97
+ get "api/v1/protected_with_helper_scopes/status.json?access_token=#{access_token.token}"
98
+
99
+ expect(last_response).to be_successful
100
+ expect(json_body).to have_key('response')
101
+ end
102
+
103
+ it 'successfully requests public resource' do
104
+ get "api/v1/public/status.json"
105
+
106
+ expect(last_response).to be_successful
107
+ expect(json_body).to have_key('response')
108
+ end
109
+ end
110
+
111
+ context 'with invalid Access Token' do
112
+ it 'fails without access token' do
113
+ get "api/v1/protected/status.json"
114
+
115
+ expect(last_response).not_to be_successful
116
+ expect(json_body).to have_key('error')
117
+ end
118
+
119
+ it 'fails for access token without scopes' do
120
+ get "api/v1/protected_with_endpoint_scopes/status.json?access_token=#{access_token.token}"
121
+
122
+ expect(last_response).not_to be_successful
123
+ expect(json_body).to have_key('error')
124
+ end
125
+
126
+ it 'fails for access token with invalid scopes' do
127
+ access_token = client_is_authorized(client, resource, scopes: 'read write')
128
+
129
+ get "api/v1/protected_with_endpoint_scopes/status.json?access_token=#{access_token.token}"
130
+
131
+ expect(last_response).not_to be_successful
132
+ expect(json_body).to have_key('error')
133
+ end
134
+ end
135
+ end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper_integration'
2
2
 
3
3
  describe Doorkeeper::DashboardHelper do
4
- describe '.doorkeeper_errors_for' do
4
+ describe '#doorkeeper_errors_for' do
5
5
  let(:object) { double errors: { method: messages } }
6
6
  let(:messages) { ['first message', 'second message'] }
7
7
 
@@ -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
@@ -37,6 +72,7 @@ describe Doorkeeper, 'configuration' do
37
72
  orm DOORKEEPER_ORM
38
73
  admin_authenticator(&block)
39
74
  end
75
+
40
76
  expect(subject.authenticate_admin).to eq(block)
41
77
  end
42
78
  end
@@ -59,6 +95,7 @@ describe Doorkeeper, 'configuration' do
59
95
  orm DOORKEEPER_ORM
60
96
  access_token_expires_in nil
61
97
  end
98
+
62
99
  expect(subject.access_token_expires_in).to be_nil
63
100
  end
64
101
  end
@@ -69,6 +106,7 @@ describe Doorkeeper, 'configuration' do
69
106
  orm DOORKEEPER_ORM
70
107
  default_scopes :public
71
108
  end
109
+
72
110
  expect(subject.default_scopes).to include('public')
73
111
  end
74
112
 
@@ -77,6 +115,7 @@ describe Doorkeeper, 'configuration' do
77
115
  orm DOORKEEPER_ORM
78
116
  optional_scopes :write, :update
79
117
  end
118
+
80
119
  expect(subject.optional_scopes).to include('write', 'update')
81
120
  end
82
121
 
@@ -86,6 +125,7 @@ describe Doorkeeper, 'configuration' do
86
125
  default_scopes :normal
87
126
  optional_scopes :admin
88
127
  end
128
+
89
129
  expect(subject.scopes).to include('normal', 'admin')
90
130
  end
91
131
  end
@@ -100,6 +140,7 @@ describe Doorkeeper, 'configuration' do
100
140
  orm DOORKEEPER_ORM
101
141
  use_refresh_token
102
142
  end
143
+
103
144
  expect(subject.refresh_token_enabled?).to be_truthy
104
145
  end
105
146
 
@@ -131,6 +172,7 @@ describe Doorkeeper, 'configuration' do
131
172
  orm DOORKEEPER_ORM
132
173
  client_credentials :from_digest, :from_params
133
174
  end
175
+
134
176
  expect(subject.client_credentials_methods).to eq([:from_digest, :from_params])
135
177
  end
136
178
  end
@@ -145,8 +187,20 @@ describe Doorkeeper, 'configuration' do
145
187
  orm DOORKEEPER_ORM
146
188
  force_ssl_in_redirect_uri(false)
147
189
  end
190
+
148
191
  expect(subject.force_ssl_in_redirect_uri).to be_falsey
149
192
  end
193
+
194
+ it 'can be a callable object' do
195
+ block = proc { false }
196
+ Doorkeeper.configure do
197
+ orm DOORKEEPER_ORM
198
+ force_ssl_in_redirect_uri(&block)
199
+ end
200
+
201
+ expect(subject.force_ssl_in_redirect_uri).to eq(block)
202
+ expect(subject.force_ssl_in_redirect_uri.call).to be_falsey
203
+ end
150
204
  end
151
205
 
152
206
  describe 'access_token_methods' do
@@ -159,10 +213,28 @@ describe Doorkeeper, 'configuration' do
159
213
  orm DOORKEEPER_ORM
160
214
  access_token_methods :from_access_token_param, :from_bearer_param
161
215
  end
216
+
162
217
  expect(subject.access_token_methods).to eq([:from_access_token_param, :from_bearer_param])
163
218
  end
164
219
  end
165
220
 
221
+ describe 'forbid_redirect_uri' do
222
+ it 'is false by default' do
223
+ expect(subject.forbid_redirect_uri.call(URI.parse('https://localhost'))).to be_falsey
224
+ end
225
+
226
+ it 'can be a callable object' do
227
+ block = proc { true }
228
+ Doorkeeper.configure do
229
+ orm DOORKEEPER_ORM
230
+ forbid_redirect_uri(&block)
231
+ end
232
+
233
+ expect(subject.forbid_redirect_uri).to eq(block)
234
+ expect(subject.forbid_redirect_uri.call).to be_truthy
235
+ end
236
+ end
237
+
166
238
  describe 'enable_application_owner' do
167
239
  it 'is disabled by default' do
168
240
  expect(Doorkeeper.configuration.enable_application_owner?).not_to be_truthy
@@ -175,9 +247,11 @@ describe Doorkeeper, 'configuration' do
175
247
  enable_application_owner
176
248
  end
177
249
  end
250
+
178
251
  it 'adds support for application owner' do
179
252
  expect(Doorkeeper::Application.new).to respond_to :owner
180
253
  end
254
+
181
255
  it 'Doorkeeper.configuration.confirm_application_owner? returns false' do
182
256
  expect(Doorkeeper.configuration.confirm_application_owner?).not_to be_truthy
183
257
  end
@@ -190,9 +264,11 @@ describe Doorkeeper, 'configuration' do
190
264
  enable_application_owner confirmation: true
191
265
  end
192
266
  end
267
+
193
268
  it 'adds support for application owner' do
194
269
  expect(Doorkeeper::Application.new).to respond_to :owner
195
270
  end
271
+
196
272
  it 'Doorkeeper.configuration.confirm_application_owner? returns true' do
197
273
  expect(Doorkeeper.configuration.confirm_application_owner?).to be_truthy
198
274
  end
@@ -209,6 +285,7 @@ describe Doorkeeper, 'configuration' do
209
285
  orm DOORKEEPER_ORM
210
286
  realm 'Example'
211
287
  end
288
+
212
289
  expect(subject.realm).to eq('Example')
213
290
  end
214
291
  end
@@ -216,23 +293,24 @@ describe Doorkeeper, 'configuration' do
216
293
  describe "grant_flows" do
217
294
  it "is set to all grant flows by default" do
218
295
  expect(Doorkeeper.configuration.grant_flows).
219
- to eq(%w(authorization_code client_credentials))
296
+ to eq(%w[authorization_code client_credentials])
220
297
  end
221
298
 
222
299
  it "can change the value" do
223
- Doorkeeper.configure {
300
+ Doorkeeper.configure do
224
301
  orm DOORKEEPER_ORM
225
- grant_flows [ 'authorization_code', 'implicit' ]
226
- }
302
+ grant_flows ['authorization_code', 'implicit']
303
+ end
304
+
227
305
  expect(subject.grant_flows).to eq ['authorization_code', 'implicit']
228
306
  end
229
307
 
230
308
  context "when including 'authorization_code'" do
231
309
  before do
232
- Doorkeeper.configure {
310
+ Doorkeeper.configure do
233
311
  orm DOORKEEPER_ORM
234
312
  grant_flows ['authorization_code']
235
- }
313
+ end
236
314
  end
237
315
 
238
316
  it "includes 'code' in authorization_response_types" do
@@ -246,10 +324,10 @@ describe Doorkeeper, 'configuration' do
246
324
 
247
325
  context "when including 'implicit'" do
248
326
  before do
249
- Doorkeeper.configure {
327
+ Doorkeeper.configure do
250
328
  orm DOORKEEPER_ORM
251
329
  grant_flows ['implicit']
252
- }
330
+ end
253
331
  end
254
332
 
255
333
  it "includes 'token' in authorization_response_types" do
@@ -259,10 +337,10 @@ describe Doorkeeper, 'configuration' do
259
337
 
260
338
  context "when including 'password'" do
261
339
  before do
262
- Doorkeeper.configure {
340
+ Doorkeeper.configure do
263
341
  orm DOORKEEPER_ORM
264
342
  grant_flows ['password']
265
- }
343
+ end
266
344
  end
267
345
 
268
346
  it "includes 'password' in token_grant_types" do
@@ -272,10 +350,10 @@ describe Doorkeeper, 'configuration' do
272
350
 
273
351
  context "when including 'client_credentials'" do
274
352
  before do
275
- Doorkeeper.configure {
353
+ Doorkeeper.configure do
276
354
  orm DOORKEEPER_ORM
277
355
  grant_flows ['client_credentials']
278
- }
356
+ end
279
357
  end
280
358
 
281
359
  it "includes 'client_credentials' in token_grant_types" do
@@ -331,4 +409,29 @@ describe Doorkeeper, 'configuration' do
331
409
  it { expect(Doorkeeper.configuration.base_controller).to eq('ApplicationController') }
332
410
  end
333
411
  end
412
+
413
+ if DOORKEEPER_ORM == :active_record
414
+ describe 'active_record_options' do
415
+ let(:models) { [Doorkeeper::AccessGrant, Doorkeeper::AccessToken, Doorkeeper::Application] }
416
+
417
+ before do
418
+ models.each do |model|
419
+ allow(model).to receive(:establish_connection).and_return(true)
420
+ end
421
+ end
422
+
423
+ it 'establishes connection for Doorkeeper models based on options' do
424
+ models.each do |model|
425
+ expect(model).to receive(:establish_connection)
426
+ end
427
+
428
+ Doorkeeper.configure do
429
+ orm DOORKEEPER_ORM
430
+ active_record_options(
431
+ establish_connection: Rails.configuration.database_configuration[Rails.env]
432
+ )
433
+ end
434
+ end
435
+ end
436
+ end
334
437
  end