doorkeeper 5.2.6 → 5.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 (126) hide show
  1. checksums.yaml +4 -4
  2. data/Appraisals +2 -2
  3. data/CHANGELOG.md +15 -14
  4. data/Gemfile +2 -2
  5. data/app/controllers/doorkeeper/application_controller.rb +2 -2
  6. data/app/controllers/doorkeeper/application_metal_controller.rb +2 -2
  7. data/app/controllers/doorkeeper/applications_controller.rb +3 -3
  8. data/app/controllers/doorkeeper/authorizations_controller.rb +2 -2
  9. data/app/controllers/doorkeeper/authorized_applications_controller.rb +3 -3
  10. data/gemfiles/rails_5_0.gemfile +2 -2
  11. data/gemfiles/rails_5_1.gemfile +2 -2
  12. data/gemfiles/rails_5_2.gemfile +2 -2
  13. data/gemfiles/rails_6_0.gemfile +2 -2
  14. data/gemfiles/rails_master.gemfile +2 -2
  15. data/lib/doorkeeper.rb +2 -3
  16. data/lib/doorkeeper/config.rb +71 -39
  17. data/lib/doorkeeper/grape/helpers.rb +1 -1
  18. data/lib/doorkeeper/helpers/controller.rb +10 -8
  19. data/lib/doorkeeper/models/access_grant_mixin.rb +7 -6
  20. data/lib/doorkeeper/models/access_token_mixin.rb +55 -18
  21. data/lib/doorkeeper/models/application_mixin.rb +3 -3
  22. data/lib/doorkeeper/models/concerns/ownership.rb +1 -1
  23. data/lib/doorkeeper/models/concerns/reusable.rb +1 -1
  24. data/lib/doorkeeper/models/concerns/revocable.rb +0 -27
  25. data/lib/doorkeeper/oauth/authorization/code.rb +4 -4
  26. data/lib/doorkeeper/oauth/authorization/token.rb +9 -6
  27. data/lib/doorkeeper/oauth/authorization_code_request.rb +13 -6
  28. data/lib/doorkeeper/oauth/base_request.rb +8 -4
  29. data/lib/doorkeeper/oauth/client.rb +7 -8
  30. data/lib/doorkeeper/oauth/client_credentials/creator.rb +16 -9
  31. data/lib/doorkeeper/oauth/client_credentials/issuer.rb +7 -7
  32. data/lib/doorkeeper/oauth/client_credentials/{validation.rb → validator.rb} +4 -4
  33. data/lib/doorkeeper/oauth/client_credentials_request.rb +1 -1
  34. data/lib/doorkeeper/oauth/code_response.rb +2 -2
  35. data/lib/doorkeeper/oauth/error.rb +1 -1
  36. data/lib/doorkeeper/oauth/error_response.rb +5 -5
  37. data/lib/doorkeeper/oauth/helpers/scope_checker.rb +7 -5
  38. data/lib/doorkeeper/oauth/helpers/unique_token.rb +8 -5
  39. data/lib/doorkeeper/oauth/helpers/uri_checker.rb +1 -1
  40. data/lib/doorkeeper/oauth/invalid_request_response.rb +3 -3
  41. data/lib/doorkeeper/oauth/invalid_token_response.rb +5 -2
  42. data/lib/doorkeeper/oauth/password_access_token_request.rb +3 -3
  43. data/lib/doorkeeper/oauth/pre_authorization.rb +7 -5
  44. data/lib/doorkeeper/oauth/refresh_token_request.rb +5 -5
  45. data/lib/doorkeeper/oauth/token.rb +2 -2
  46. data/lib/doorkeeper/oauth/token_introspection.rb +6 -6
  47. data/lib/doorkeeper/orm/active_record.rb +3 -3
  48. data/lib/doorkeeper/orm/active_record/access_grant.rb +4 -43
  49. data/lib/doorkeeper/orm/active_record/access_token.rb +4 -35
  50. data/lib/doorkeeper/orm/active_record/application.rb +3 -155
  51. data/lib/doorkeeper/orm/active_record/mixins/access_grant.rb +53 -0
  52. data/lib/doorkeeper/orm/active_record/mixins/access_token.rb +47 -0
  53. data/lib/doorkeeper/orm/active_record/mixins/application.rb +128 -0
  54. data/lib/doorkeeper/orm/active_record/redirect_uri_validator.rb +3 -3
  55. data/lib/doorkeeper/rails/helpers.rb +4 -4
  56. data/lib/doorkeeper/rails/routes.rb +5 -7
  57. data/lib/doorkeeper/rake/db.rake +3 -3
  58. data/lib/doorkeeper/request.rb +1 -1
  59. data/lib/doorkeeper/request/authorization_code.rb +3 -3
  60. data/lib/doorkeeper/request/client_credentials.rb +2 -2
  61. data/lib/doorkeeper/request/password.rb +2 -2
  62. data/lib/doorkeeper/request/refresh_token.rb +3 -3
  63. data/lib/doorkeeper/server.rb +1 -1
  64. data/lib/doorkeeper/stale_records_cleaner.rb +1 -1
  65. data/lib/doorkeeper/version.rb +2 -2
  66. data/lib/generators/doorkeeper/application_owner_generator.rb +1 -1
  67. data/lib/generators/doorkeeper/confidential_applications_generator.rb +1 -1
  68. data/lib/generators/doorkeeper/migration_generator.rb +1 -1
  69. data/lib/generators/doorkeeper/pkce_generator.rb +1 -1
  70. data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +2 -2
  71. data/lib/generators/doorkeeper/templates/initializer.rb +39 -8
  72. data/spec/controllers/application_metal_controller_spec.rb +1 -1
  73. data/spec/controllers/applications_controller_spec.rb +3 -2
  74. data/spec/controllers/authorizations_controller_spec.rb +18 -18
  75. data/spec/controllers/protected_resources_controller_spec.rb +25 -17
  76. data/spec/controllers/token_info_controller_spec.rb +1 -1
  77. data/spec/controllers/tokens_controller_spec.rb +1 -1
  78. data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +3 -3
  79. data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +1 -1
  80. data/spec/dummy/db/migrate/20180210183654_add_confidential_to_applications.rb +1 -1
  81. data/spec/generators/install_generator_spec.rb +1 -1
  82. data/spec/generators/previous_refresh_token_generator_spec.rb +2 -2
  83. data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +1 -1
  84. data/spec/lib/config_spec.rb +61 -21
  85. data/spec/lib/doorkeeper_spec.rb +1 -1
  86. data/spec/lib/models/revocable_spec.rb +3 -3
  87. data/spec/lib/oauth/authorization_code_request_spec.rb +127 -125
  88. data/spec/lib/oauth/base_request_spec.rb +160 -158
  89. data/spec/lib/oauth/base_response_spec.rb +27 -29
  90. data/spec/lib/oauth/client/credentials_spec.rb +1 -1
  91. data/spec/lib/oauth/client_credentials/creator_spec.rb +42 -5
  92. data/spec/lib/oauth/client_credentials/issuer_spec.rb +12 -12
  93. data/spec/lib/oauth/client_credentials/validation_spec.rb +4 -4
  94. data/spec/lib/oauth/client_credentials_integration_spec.rb +16 -18
  95. data/spec/lib/oauth/client_credentials_request_spec.rb +78 -80
  96. data/spec/lib/oauth/client_spec.rb +26 -26
  97. data/spec/lib/oauth/code_request_spec.rb +34 -34
  98. data/spec/lib/oauth/code_response_spec.rb +21 -25
  99. data/spec/lib/oauth/error_response_spec.rb +42 -44
  100. data/spec/lib/oauth/error_spec.rb +12 -14
  101. data/spec/lib/oauth/forbidden_token_response_spec.rb +11 -13
  102. data/spec/lib/oauth/helpers/scope_checker_spec.rb +30 -18
  103. data/spec/lib/oauth/invalid_request_response_spec.rb +48 -50
  104. data/spec/lib/oauth/invalid_token_response_spec.rb +32 -34
  105. data/spec/lib/oauth/password_access_token_request_spec.rb +145 -147
  106. data/spec/lib/oauth/pre_authorization_spec.rb +159 -161
  107. data/spec/lib/oauth/refresh_token_request_spec.rb +138 -139
  108. data/spec/lib/oauth/scopes_spec.rb +104 -106
  109. data/spec/lib/oauth/token_request_spec.rb +115 -111
  110. data/spec/lib/oauth/token_response_spec.rb +71 -73
  111. data/spec/lib/oauth/token_spec.rb +121 -123
  112. data/spec/models/doorkeeper/access_grant_spec.rb +3 -5
  113. data/spec/models/doorkeeper/access_token_spec.rb +7 -7
  114. data/spec/models/doorkeeper/application_spec.rb +295 -373
  115. data/spec/requests/applications/applications_request_spec.rb +1 -1
  116. data/spec/requests/endpoints/authorization_spec.rb +5 -3
  117. data/spec/requests/flows/authorization_code_spec.rb +34 -22
  118. data/spec/requests/flows/client_credentials_spec.rb +1 -1
  119. data/spec/requests/flows/password_spec.rb +32 -12
  120. data/spec/requests/flows/refresh_token_spec.rb +19 -19
  121. data/spec/requests/flows/revoke_token_spec.rb +18 -12
  122. data/spec/spec_helper.rb +1 -4
  123. data/spec/support/shared/controllers_shared_context.rb +33 -23
  124. data/spec/validators/redirect_uri_validator_spec.rb +1 -1
  125. metadata +6 -5
  126. data/spec/support/http_method_shim.rb +0 -29
@@ -2,220 +2,222 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- module Doorkeeper::OAuth
6
- describe BaseRequest do
7
- let(:access_token) do
8
- double :access_token,
9
- plaintext_token: "some-token",
10
- expires_in: "3600",
11
- expires_in_seconds: "300",
12
- scopes_string: "two scopes",
13
- plaintext_refresh_token: "some-refresh-token",
14
- token_type: "bearer",
15
- created_at: 0
16
- end
5
+ describe Doorkeeper::OAuth::BaseRequest do
6
+ let(:access_token) do
7
+ double :access_token,
8
+ plaintext_token: "some-token",
9
+ expires_in: "3600",
10
+ expires_in_seconds: "300",
11
+ scopes_string: "two scopes",
12
+ plaintext_refresh_token: "some-refresh-token",
13
+ token_type: "bearer",
14
+ created_at: 0
15
+ end
17
16
 
18
- let(:client) { double :client, id: "1" }
17
+ let(:client) { double :client, id: "1" }
19
18
 
20
- let(:scopes_array) { %w[public write] }
19
+ let(:scopes_array) { %w[public write] }
21
20
 
22
- let(:server) do
23
- double :server,
24
- access_token_expires_in: 100,
25
- custom_access_token_expires_in: ->(_context) { nil },
26
- refresh_token_enabled?: false
27
- end
21
+ let(:server) do
22
+ double :server,
23
+ access_token_expires_in: 100,
24
+ custom_access_token_expires_in: ->(_context) { nil },
25
+ refresh_token_enabled?: false
26
+ end
27
+
28
+ before do
29
+ allow(server).to receive(:option_defined?).with(:custom_access_token_expires_in).and_return(true)
30
+ end
31
+
32
+ subject do
33
+ described_class.new
34
+ end
28
35
 
36
+ describe "#authorize" do
29
37
  before do
30
- allow(server).to receive(:option_defined?).with(:custom_access_token_expires_in).and_return(true)
38
+ allow(subject).to receive(:access_token).and_return(access_token)
31
39
  end
32
40
 
33
- subject do
34
- BaseRequest.new
41
+ it "validates itself" do
42
+ expect(subject).to receive(:validate).once
43
+ subject.authorize
35
44
  end
36
45
 
37
- describe "#authorize" do
46
+ context "valid" do
38
47
  before do
39
- allow(subject).to receive(:access_token).and_return(access_token)
48
+ allow(subject).to receive(:valid?).and_return(true)
40
49
  end
41
50
 
42
- it "validates itself" do
43
- expect(subject).to receive(:validate).once
51
+ it "calls callback methods" do
52
+ expect(subject).to receive(:before_successful_response).once
53
+ expect(subject).to receive(:after_successful_response).once
44
54
  subject.authorize
45
55
  end
46
56
 
47
- context "valid" do
48
- before do
49
- allow(subject).to receive(:valid?).and_return(true)
50
- end
57
+ it "returns a TokenResponse object" do
58
+ result = subject.authorize
51
59
 
52
- it "calls callback methods" do
53
- expect(subject).to receive(:before_successful_response).once
54
- expect(subject).to receive(:after_successful_response).once
55
- subject.authorize
60
+ expect(result).to be_an_instance_of(Doorkeeper::OAuth::TokenResponse)
61
+ expect(result.body).to eq(
62
+ Doorkeeper::OAuth::TokenResponse.new(access_token).body,
63
+ )
64
+ end
65
+ end
66
+
67
+ context "invalid" do
68
+ context "with error other than invalid_request" do
69
+ before do
70
+ allow(subject).to receive(:valid?).and_return(false)
71
+ allow(subject).to receive(:error).and_return(:server_error)
72
+ allow(subject).to receive(:state).and_return("hello")
56
73
  end
57
74
 
58
- it "returns a TokenResponse object" do
75
+ it "returns an ErrorResponse object" do
59
76
  result = subject.authorize
60
77
 
61
- expect(result).to be_an_instance_of(TokenResponse)
78
+ expect(result).to be_an_instance_of(Doorkeeper::OAuth::ErrorResponse)
79
+
62
80
  expect(result.body).to eq(
63
- TokenResponse.new(access_token).body
81
+ error: :server_error,
82
+ error_description: translated_error_message(:server_error),
83
+ state: "hello",
64
84
  )
65
85
  end
66
86
  end
67
87
 
68
- context "invalid" do
69
- context "with error other than invalid_request" do
70
- before do
71
- allow(subject).to receive(:valid?).and_return(false)
72
- allow(subject).to receive(:error).and_return(:server_error)
73
- allow(subject).to receive(:state).and_return("hello")
74
- end
75
-
76
- it "returns an ErrorResponse object" do
77
- result = subject.authorize
78
-
79
- expect(result).to be_an_instance_of(ErrorResponse)
80
-
81
- expect(result.body).to eq(
82
- error: :server_error,
83
- error_description: translated_error_message(:server_error),
84
- state: "hello"
85
- )
86
- end
88
+ context "with invalid_request error" do
89
+ before do
90
+ allow(subject).to receive(:valid?).and_return(false)
91
+ allow(subject).to receive(:error).and_return(:invalid_request)
92
+ allow(subject).to receive(:state).and_return("hello")
87
93
  end
88
94
 
89
- context "with invalid_request error" do
90
- before do
91
- allow(subject).to receive(:valid?).and_return(false)
92
- allow(subject).to receive(:error).and_return(:invalid_request)
93
- allow(subject).to receive(:state).and_return("hello")
94
- end
95
-
96
- it "returns an InvalidRequestResponse object" do
97
- result = subject.authorize
95
+ it "returns an InvalidRequestResponse object" do
96
+ result = subject.authorize
98
97
 
99
- expect(result).to be_an_instance_of(InvalidRequestResponse)
98
+ expect(result).to be_an_instance_of(Doorkeeper::OAuth::InvalidRequestResponse)
100
99
 
101
- expect(result.body).to eq(
102
- error: :invalid_request,
103
- error_description: translated_invalid_request_error_message(:unknown, :unknown),
104
- state: "hello"
105
- )
106
- end
100
+ expect(result.body).to eq(
101
+ error: :invalid_request,
102
+ error_description: translated_invalid_request_error_message(:unknown, :unknown),
103
+ state: "hello",
104
+ )
107
105
  end
108
106
  end
109
107
  end
108
+ end
110
109
 
111
- describe "#default_scopes" do
112
- it "delegates to the server" do
113
- expect(subject).to receive(:server).and_return(server).once
114
- expect(server).to receive(:default_scopes).once
110
+ describe "#default_scopes" do
111
+ it "delegates to the server" do
112
+ expect(subject).to receive(:server).and_return(server).once
113
+ expect(server).to receive(:default_scopes).once
115
114
 
116
- subject.default_scopes
117
- end
115
+ subject.default_scopes
118
116
  end
117
+ end
119
118
 
120
- describe "#find_or_create_access_token" do
121
- it "returns an instance of AccessToken" do
122
- result = subject.find_or_create_access_token(
123
- client,
124
- "1",
125
- "public",
126
- server
127
- )
119
+ describe "#find_or_create_access_token" do
120
+ it "returns an instance of AccessToken" do
121
+ result = subject.find_or_create_access_token(
122
+ client,
123
+ "1",
124
+ "public",
125
+ server,
126
+ )
128
127
 
129
- expect(result).to be_an_instance_of(Doorkeeper::AccessToken)
130
- end
128
+ expect(result).to be_an_instance_of(Doorkeeper::AccessToken)
129
+ end
131
130
 
132
- it "respects custom_access_token_expires_in" do
133
- server = double(:server,
134
- access_token_expires_in: 100,
135
- custom_access_token_expires_in: ->(context) { context.scopes == "public" ? 500 : nil },
136
- refresh_token_enabled?: false)
131
+ it "respects custom_access_token_expires_in" do
132
+ server = double(
133
+ :server,
134
+ access_token_expires_in: 100,
135
+ custom_access_token_expires_in: ->(context) { context.scopes == "public" ? 500 : nil },
136
+ refresh_token_enabled?: false,
137
+ )
137
138
 
138
- allow(server).to receive(:option_defined?).with(:custom_access_token_expires_in).and_return(true)
139
+ allow(server).to receive(:option_defined?).with(:custom_access_token_expires_in).and_return(true)
139
140
 
140
- result = subject.find_or_create_access_token(
141
- client,
142
- "1",
143
- "public",
144
- server
145
- )
146
- expect(result.expires_in).to eql(500)
147
- end
141
+ result = subject.find_or_create_access_token(
142
+ client,
143
+ "1",
144
+ "public",
145
+ server,
146
+ )
147
+ expect(result.expires_in).to eql(500)
148
+ end
148
149
 
149
- it "respects use_refresh_token with a block" do
150
- server = double(:server,
151
- access_token_expires_in: 100,
152
- custom_access_token_expires_in: ->(_context) { nil },
153
- refresh_token_enabled?: lambda { |context|
154
- context.scopes == "public"
155
- })
156
-
157
- allow(server).to receive(:option_defined?).with(:custom_access_token_expires_in).and_return(true)
158
-
159
- result = subject.find_or_create_access_token(
160
- client,
161
- "1",
162
- "public",
163
- server
164
- )
165
- expect(result.refresh_token).to_not be_nil
150
+ it "respects use_refresh_token with a block" do
151
+ server = double(
152
+ :server,
153
+ access_token_expires_in: 100,
154
+ custom_access_token_expires_in: ->(_context) { nil },
155
+ refresh_token_enabled?: lambda { |context|
156
+ context.scopes == "public"
157
+ },
158
+ )
166
159
 
167
- result = subject.find_or_create_access_token(
168
- client,
169
- "1",
170
- "private",
171
- server
172
- )
173
- expect(result.refresh_token).to be_nil
174
- end
160
+ allow(server).to receive(:option_defined?).with(:custom_access_token_expires_in).and_return(true)
161
+
162
+ result = subject.find_or_create_access_token(
163
+ client,
164
+ "1",
165
+ "public",
166
+ server,
167
+ )
168
+ expect(result.refresh_token).to_not be_nil
169
+
170
+ result = subject.find_or_create_access_token(
171
+ client,
172
+ "1",
173
+ "private",
174
+ server,
175
+ )
176
+ expect(result.refresh_token).to be_nil
175
177
  end
178
+ end
176
179
 
177
- describe "#scopes" do
178
- context "@original_scopes is present" do
179
- before do
180
- subject.instance_variable_set(:@original_scopes, "public write")
181
- end
180
+ describe "#scopes" do
181
+ context "@original_scopes is present" do
182
+ before do
183
+ subject.instance_variable_set(:@original_scopes, "public write")
184
+ end
182
185
 
183
- it "returns array of @original_scopes" do
184
- result = subject.scopes
186
+ it "returns array of @original_scopes" do
187
+ result = subject.scopes
185
188
 
186
- expect(result).to eq(scopes_array)
187
- end
189
+ expect(result).to eq(scopes_array)
188
190
  end
191
+ end
189
192
 
190
- context "@original_scopes is not present" do
191
- before do
192
- subject.instance_variable_set(:@original_scopes, "")
193
- end
193
+ context "@original_scopes is not present" do
194
+ before do
195
+ subject.instance_variable_set(:@original_scopes, "")
196
+ end
194
197
 
195
- it "calls #default_scopes" do
196
- allow(subject).to receive(:server).and_return(server).once
197
- allow(server).to receive(:default_scopes).and_return(scopes_array).once
198
+ it "calls #default_scopes" do
199
+ allow(subject).to receive(:server).and_return(server).once
200
+ allow(server).to receive(:default_scopes).and_return(scopes_array).once
198
201
 
199
- result = subject.scopes
202
+ result = subject.scopes
200
203
 
201
- expect(result).to eq(scopes_array)
202
- end
204
+ expect(result).to eq(scopes_array)
203
205
  end
204
206
  end
207
+ end
205
208
 
206
- describe "#valid?" do
207
- context "error is nil" do
208
- it "returns true" do
209
- allow(subject).to receive(:error).and_return(nil).once
210
- expect(subject.valid?).to eq(true)
211
- end
209
+ describe "#valid?" do
210
+ context "error is nil" do
211
+ it "returns true" do
212
+ allow(subject).to receive(:error).and_return(nil).once
213
+ expect(subject.valid?).to eq(true)
212
214
  end
215
+ end
213
216
 
214
- context "error is not nil" do
215
- it "returns false" do
216
- allow(subject).to receive(:error).and_return(Object.new).once
217
- expect(subject.valid?).to eq(false)
218
- end
217
+ context "error is not nil" do
218
+ it "returns false" do
219
+ allow(subject).to receive(:error).and_return(Object.new).once
220
+ expect(subject.valid?).to eq(false)
219
221
  end
220
222
  end
221
223
  end
@@ -2,46 +2,44 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- module Doorkeeper::OAuth
6
- describe BaseResponse do
7
- subject do
8
- BaseResponse.new
9
- end
5
+ describe Doorkeeper::OAuth::BaseResponse do
6
+ subject do
7
+ Doorkeeper::OAuth::BaseResponse.new
8
+ end
10
9
 
11
- describe "#body" do
12
- it "returns an empty Hash" do
13
- expect(subject.body).to eq({})
14
- end
10
+ describe "#body" do
11
+ it "returns an empty Hash" do
12
+ expect(subject.body).to eq({})
15
13
  end
14
+ end
16
15
 
17
- describe "#description" do
18
- it "returns an empty String" do
19
- expect(subject.description).to eq("")
20
- end
16
+ describe "#description" do
17
+ it "returns an empty String" do
18
+ expect(subject.description).to eq("")
21
19
  end
20
+ end
22
21
 
23
- describe "#headers" do
24
- it "returns an empty Hash" do
25
- expect(subject.headers).to eq({})
26
- end
22
+ describe "#headers" do
23
+ it "returns an empty Hash" do
24
+ expect(subject.headers).to eq({})
27
25
  end
26
+ end
28
27
 
29
- describe "#redirectable?" do
30
- it "returns false" do
31
- expect(subject.redirectable?).to eq(false)
32
- end
28
+ describe "#redirectable?" do
29
+ it "returns false" do
30
+ expect(subject.redirectable?).to eq(false)
33
31
  end
32
+ end
34
33
 
35
- describe "#redirect_uri" do
36
- it "returns an empty String" do
37
- expect(subject.redirect_uri).to eq("")
38
- end
34
+ describe "#redirect_uri" do
35
+ it "returns an empty String" do
36
+ expect(subject.redirect_uri).to eq("")
39
37
  end
38
+ end
40
39
 
41
- describe "#status" do
42
- it "returns :ok" do
43
- expect(subject.status).to eq(:ok)
44
- end
40
+ describe "#status" do
41
+ it "returns :ok" do
42
+ expect(subject.status).to eq(:ok)
45
43
  end
46
44
  end
47
45
  end