doorkeeper 5.2.6 → 5.3.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.

Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/Appraisals +2 -2
  3. data/CHANGELOG.md +24 -5
  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/authorizations_controller.rb +2 -2
  8. data/app/controllers/doorkeeper/authorized_applications_controller.rb +2 -2
  9. data/gemfiles/rails_5_0.gemfile +2 -2
  10. data/gemfiles/rails_5_1.gemfile +2 -2
  11. data/gemfiles/rails_5_2.gemfile +2 -2
  12. data/gemfiles/rails_6_0.gemfile +2 -2
  13. data/gemfiles/rails_master.gemfile +2 -2
  14. data/lib/doorkeeper/config.rb +71 -38
  15. data/lib/doorkeeper/grape/helpers.rb +1 -1
  16. data/lib/doorkeeper/helpers/controller.rb +10 -8
  17. data/lib/doorkeeper/models/access_grant_mixin.rb +7 -6
  18. data/lib/doorkeeper/models/access_token_mixin.rb +54 -16
  19. data/lib/doorkeeper/models/application_mixin.rb +3 -3
  20. data/lib/doorkeeper/models/concerns/ownership.rb +1 -1
  21. data/lib/doorkeeper/models/concerns/reusable.rb +1 -1
  22. data/lib/doorkeeper/models/concerns/revocable.rb +0 -27
  23. data/lib/doorkeeper/oauth/authorization/code.rb +4 -4
  24. data/lib/doorkeeper/oauth/authorization/token.rb +9 -6
  25. data/lib/doorkeeper/oauth/authorization_code_request.rb +13 -6
  26. data/lib/doorkeeper/oauth/base_request.rb +8 -4
  27. data/lib/doorkeeper/oauth/client.rb +7 -8
  28. data/lib/doorkeeper/oauth/client_credentials/creator.rb +16 -9
  29. data/lib/doorkeeper/oauth/client_credentials/issuer.rb +7 -7
  30. data/lib/doorkeeper/oauth/client_credentials/{validation.rb → validator.rb} +4 -4
  31. data/lib/doorkeeper/oauth/client_credentials_request.rb +1 -1
  32. data/lib/doorkeeper/oauth/code_response.rb +2 -2
  33. data/lib/doorkeeper/oauth/error.rb +1 -1
  34. data/lib/doorkeeper/oauth/error_response.rb +5 -5
  35. data/lib/doorkeeper/oauth/helpers/scope_checker.rb +7 -5
  36. data/lib/doorkeeper/oauth/helpers/unique_token.rb +8 -5
  37. data/lib/doorkeeper/oauth/helpers/uri_checker.rb +1 -1
  38. data/lib/doorkeeper/oauth/invalid_request_response.rb +3 -3
  39. data/lib/doorkeeper/oauth/invalid_token_response.rb +5 -2
  40. data/lib/doorkeeper/oauth/password_access_token_request.rb +3 -3
  41. data/lib/doorkeeper/oauth/pre_authorization.rb +7 -5
  42. data/lib/doorkeeper/oauth/refresh_token_request.rb +5 -5
  43. data/lib/doorkeeper/oauth/token.rb +2 -2
  44. data/lib/doorkeeper/oauth/token_introspection.rb +6 -6
  45. data/lib/doorkeeper/orm/active_record/access_grant.rb +4 -43
  46. data/lib/doorkeeper/orm/active_record/access_token.rb +4 -35
  47. data/lib/doorkeeper/orm/active_record/application.rb +3 -155
  48. data/lib/doorkeeper/orm/active_record/mixins/access_grant.rb +53 -0
  49. data/lib/doorkeeper/orm/active_record/mixins/access_token.rb +47 -0
  50. data/lib/doorkeeper/orm/active_record/mixins/application.rb +187 -0
  51. data/lib/doorkeeper/orm/active_record/redirect_uri_validator.rb +3 -3
  52. data/lib/doorkeeper/orm/active_record.rb +3 -3
  53. data/lib/doorkeeper/rails/helpers.rb +4 -4
  54. data/lib/doorkeeper/rails/routes.rb +5 -7
  55. data/lib/doorkeeper/rake/db.rake +3 -3
  56. data/lib/doorkeeper/request/authorization_code.rb +3 -3
  57. data/lib/doorkeeper/request/client_credentials.rb +2 -2
  58. data/lib/doorkeeper/request/password.rb +2 -2
  59. data/lib/doorkeeper/request/refresh_token.rb +3 -3
  60. data/lib/doorkeeper/request.rb +1 -1
  61. data/lib/doorkeeper/server.rb +1 -1
  62. data/lib/doorkeeper/stale_records_cleaner.rb +1 -1
  63. data/lib/doorkeeper/version.rb +2 -2
  64. data/lib/doorkeeper.rb +2 -3
  65. data/lib/generators/doorkeeper/application_owner_generator.rb +1 -1
  66. data/lib/generators/doorkeeper/confidential_applications_generator.rb +1 -1
  67. data/lib/generators/doorkeeper/migration_generator.rb +1 -1
  68. data/lib/generators/doorkeeper/pkce_generator.rb +1 -1
  69. data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +2 -2
  70. data/lib/generators/doorkeeper/templates/initializer.rb +39 -0
  71. data/spec/controllers/application_metal_controller_spec.rb +1 -1
  72. data/spec/controllers/applications_controller_spec.rb +3 -2
  73. data/spec/controllers/authorizations_controller_spec.rb +18 -18
  74. data/spec/controllers/protected_resources_controller_spec.rb +25 -17
  75. data/spec/controllers/token_info_controller_spec.rb +1 -1
  76. data/spec/controllers/tokens_controller_spec.rb +1 -1
  77. data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +3 -3
  78. data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +1 -1
  79. data/spec/dummy/db/migrate/20180210183654_add_confidential_to_applications.rb +1 -1
  80. data/spec/generators/install_generator_spec.rb +1 -1
  81. data/spec/generators/previous_refresh_token_generator_spec.rb +2 -2
  82. data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +1 -1
  83. data/spec/lib/config_spec.rb +62 -7
  84. data/spec/lib/doorkeeper_spec.rb +1 -1
  85. data/spec/lib/models/revocable_spec.rb +3 -3
  86. data/spec/lib/oauth/authorization_code_request_spec.rb +127 -125
  87. data/spec/lib/oauth/base_request_spec.rb +160 -158
  88. data/spec/lib/oauth/base_response_spec.rb +27 -29
  89. data/spec/lib/oauth/client/credentials_spec.rb +1 -1
  90. data/spec/lib/oauth/client_credentials/creator_spec.rb +42 -5
  91. data/spec/lib/oauth/client_credentials/issuer_spec.rb +12 -12
  92. data/spec/lib/oauth/client_credentials/validation_spec.rb +4 -4
  93. data/spec/lib/oauth/client_credentials_integration_spec.rb +16 -18
  94. data/spec/lib/oauth/client_credentials_request_spec.rb +78 -80
  95. data/spec/lib/oauth/client_spec.rb +26 -26
  96. data/spec/lib/oauth/code_request_spec.rb +34 -34
  97. data/spec/lib/oauth/code_response_spec.rb +21 -25
  98. data/spec/lib/oauth/error_response_spec.rb +42 -44
  99. data/spec/lib/oauth/error_spec.rb +12 -14
  100. data/spec/lib/oauth/forbidden_token_response_spec.rb +11 -13
  101. data/spec/lib/oauth/helpers/scope_checker_spec.rb +30 -18
  102. data/spec/lib/oauth/invalid_request_response_spec.rb +48 -50
  103. data/spec/lib/oauth/invalid_token_response_spec.rb +32 -34
  104. data/spec/lib/oauth/password_access_token_request_spec.rb +145 -147
  105. data/spec/lib/oauth/pre_authorization_spec.rb +159 -161
  106. data/spec/lib/oauth/refresh_token_request_spec.rb +138 -139
  107. data/spec/lib/oauth/scopes_spec.rb +104 -106
  108. data/spec/lib/oauth/token_request_spec.rb +115 -111
  109. data/spec/lib/oauth/token_response_spec.rb +71 -73
  110. data/spec/lib/oauth/token_spec.rb +121 -123
  111. data/spec/models/doorkeeper/access_grant_spec.rb +3 -5
  112. data/spec/models/doorkeeper/access_token_spec.rb +7 -7
  113. data/spec/models/doorkeeper/application_spec.rb +2 -2
  114. data/spec/requests/applications/applications_request_spec.rb +1 -1
  115. data/spec/requests/endpoints/authorization_spec.rb +5 -3
  116. data/spec/requests/flows/authorization_code_spec.rb +34 -22
  117. data/spec/requests/flows/client_credentials_spec.rb +1 -1
  118. data/spec/requests/flows/password_spec.rb +32 -12
  119. data/spec/requests/flows/refresh_token_spec.rb +19 -19
  120. data/spec/requests/flows/revoke_token_spec.rb +18 -12
  121. data/spec/spec_helper.rb +1 -4
  122. data/spec/support/shared/controllers_shared_context.rb +33 -23
  123. data/spec/validators/redirect_uri_validator_spec.rb +1 -1
  124. metadata +6 -5
  125. 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
@@ -14,7 +14,7 @@ class Doorkeeper::OAuth::Client
14
14
  expect(Credentials.new("something", "something")).to be_present
15
15
  end
16
16
 
17
- describe :from_request do
17
+ describe ".from_request" do
18
18
  let(:request) { double.as_null_object }
19
19
 
20
20
  let(:method) do
@@ -31,17 +31,31 @@ class Doorkeeper::OAuth::ClientCredentialsRequest
31
31
  end
32
32
 
33
33
  context "when existing token has not crossed token_reuse_limit" do
34
- it "returns the existing valid token" do
34
+ let!(:existing_token) { subject.call(client, scopes, expires_in: 1000) }
35
+
36
+ before do
35
37
  allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(true)
36
38
  allow(Doorkeeper.configuration).to receive(:token_reuse_limit).and_return(50)
37
- existing_token = subject.call(client, scopes, expires_in: 1000)
38
-
39
39
  allow_any_instance_of(Doorkeeper::AccessToken).to receive(:expires_in_seconds).and_return(600)
40
+ end
41
+
42
+ it "returns the existing valid token" do
40
43
  result = subject.call(client, scopes, expires_in: 1000)
41
44
 
42
45
  expect(Doorkeeper::AccessToken.count).to eq(1)
43
46
  expect(result).to eq(existing_token)
44
47
  end
48
+
49
+ context "and when revoke_previous_client_credentials_token is true" do
50
+ before do
51
+ allow(Doorkeeper.configuration).to receive(:revoke_previous_client_credentials_token).and_return(false)
52
+ end
53
+
54
+ it "does not revoke the existing valid token" do
55
+ subject.call(client, scopes, expires_in: 1000)
56
+ expect(existing_token.reload).not_to be_revoked
57
+ end
58
+ end
45
59
  end
46
60
 
47
61
  context "when existing token has crossed token_reuse_limit" do
@@ -55,7 +69,6 @@ class Doorkeeper::OAuth::ClientCredentialsRequest
55
69
 
56
70
  expect(Doorkeeper::AccessToken.count).to eq(2)
57
71
  expect(result).not_to eq(existing_token)
58
- expect(existing_token.reload).to be_revoked
59
72
  end
60
73
  end
61
74
 
@@ -70,7 +83,6 @@ class Doorkeeper::OAuth::ClientCredentialsRequest
70
83
 
71
84
  expect(Doorkeeper::AccessToken.count).to eq(2)
72
85
  expect(result).not_to eq(existing_token)
73
- expect(existing_token.reload).to be_revoked
74
86
  end
75
87
  end
76
88
  end
@@ -84,10 +96,35 @@ class Doorkeeper::OAuth::ClientCredentialsRequest
84
96
 
85
97
  expect(Doorkeeper::AccessToken.count).to eq(2)
86
98
  expect(result).not_to eq(existing_token)
99
+ end
100
+ end
101
+
102
+ context "when revoke_previous_client_credentials_token is true" do
103
+ let!(:existing_token) { subject.call(client, scopes, expires_in: 1000) }
104
+
105
+ before do
106
+ allow(Doorkeeper.configuration).to receive(:revoke_previous_client_credentials_token).and_return(true)
107
+ end
108
+
109
+ it "revokes the existing token" do
110
+ subject.call(client, scopes, expires_in: 1000)
87
111
  expect(existing_token.reload).to be_revoked
88
112
  end
89
113
  end
90
114
 
115
+ context "when revoke_previous_client_credentials_token is false" do
116
+ let!(:existing_token) { subject.call(client, scopes, expires_in: 1000) }
117
+
118
+ before do
119
+ allow(Doorkeeper.configuration).to receive(:revoke_previous_client_credentials_token).and_return(false)
120
+ end
121
+
122
+ it "does not revoke the existing token" do
123
+ subject.call(client, scopes, expires_in: 1000)
124
+ expect(existing_token.reload).not_to be_revoked
125
+ end
126
+ end
127
+
91
128
  it "returns false if creation fails" do
92
129
  expect(Doorkeeper::AccessToken).to receive(:find_or_create_for).and_return(false)
93
130
  created = subject.call(client, scopes)
@@ -8,16 +8,16 @@ class Doorkeeper::OAuth::ClientCredentialsRequest
8
8
  let(:server) do
9
9
  double(
10
10
  :server,
11
- access_token_expires_in: 100
11
+ access_token_expires_in: 100,
12
12
  )
13
13
  end
14
- let(:validation) { double :validation, valid?: true }
14
+ let(:validator) { double :validator, valid?: true }
15
15
 
16
16
  before do
17
17
  allow(server).to receive(:option_defined?).with(:custom_access_token_expires_in).and_return(false)
18
18
  end
19
19
 
20
- subject { Issuer.new(server, validation) }
20
+ subject { Issuer.new(server, validator) }
21
21
 
22
22
  describe :create do
23
23
  let(:client) { double :client, id: "some-id" }
@@ -35,7 +35,7 @@ class Doorkeeper::OAuth::ClientCredentialsRequest
35
35
  client,
36
36
  scopes,
37
37
  expires_in: 100,
38
- use_refresh_token: false
38
+ use_refresh_token: false,
39
39
  )
40
40
 
41
41
  subject.create client, scopes, creator
@@ -48,14 +48,14 @@ class Doorkeeper::OAuth::ClientCredentialsRequest
48
48
  expect(subject.error).to eq(:server_error)
49
49
  end
50
50
 
51
- context "when validation fails" do
51
+ context "when validator fails" do
52
52
  before do
53
- allow(validation).to receive(:valid?).and_return(false)
54
- allow(validation).to receive(:error).and_return(:validation_error)
53
+ allow(validator).to receive(:valid?).and_return(false)
54
+ allow(validator).to receive(:error).and_return(:validation_error)
55
55
  expect(creator).not_to receive(:create)
56
56
  end
57
57
 
58
- it "has error set from validation" do
58
+ it "has error set from validator" do
59
59
  subject.create client, scopes, creator
60
60
  expect(subject.error).to eq(:validation_error)
61
61
  end
@@ -65,7 +65,7 @@ class Doorkeeper::OAuth::ClientCredentialsRequest
65
65
  end
66
66
  end
67
67
 
68
- context "with custom expirations" do
68
+ context "with custom expiration" do
69
69
  let(:custom_ttl_grant) { 1234 }
70
70
  let(:custom_ttl_scope) { 1235 }
71
71
  let(:custom_scope) { "special" }
@@ -79,7 +79,7 @@ class Doorkeeper::OAuth::ClientCredentialsRequest
79
79
  elsif context.grant_type == Doorkeeper::OAuth::CLIENT_CREDENTIALS
80
80
  custom_ttl_grant
81
81
  end
82
- }
82
+ },
83
83
  )
84
84
  end
85
85
 
@@ -92,7 +92,7 @@ class Doorkeeper::OAuth::ClientCredentialsRequest
92
92
  client,
93
93
  scopes,
94
94
  expires_in: custom_ttl_grant,
95
- use_refresh_token: false
95
+ use_refresh_token: false,
96
96
  )
97
97
  subject.create client, scopes, creator
98
98
  end
@@ -102,7 +102,7 @@ class Doorkeeper::OAuth::ClientCredentialsRequest
102
102
  client,
103
103
  custom_scope,
104
104
  expires_in: custom_ttl_scope,
105
- use_refresh_token: false
105
+ use_refresh_token: false,
106
106
  )
107
107
  subject.create client, custom_scope, creator
108
108
  end
@@ -3,13 +3,13 @@
3
3
  require "spec_helper"
4
4
 
5
5
  class Doorkeeper::OAuth::ClientCredentialsRequest
6
- describe Validation do
6
+ describe Validator do
7
7
  let(:server) { double :server, scopes: nil }
8
8
  let(:application) { double scopes: nil }
9
9
  let(:client) { double application: application }
10
10
  let(:request) { double :request, client: client, scopes: nil }
11
11
 
12
- subject { Validation.new(server, request) }
12
+ subject { described_class.new(server, request) }
13
13
 
14
14
  it "is valid with valid request" do
15
15
  expect(subject).to be_valid
@@ -26,7 +26,7 @@ class Doorkeeper::OAuth::ClientCredentialsRequest
26
26
  allow(request).to receive(:grant_type).and_return(Doorkeeper::OAuth::CLIENT_CREDENTIALS)
27
27
  allow(server).to receive(:scopes).and_return(server_scopes)
28
28
  allow(request).to receive(:scopes).and_return(
29
- Doorkeeper::OAuth::Scopes.from_string("invalid")
29
+ Doorkeeper::OAuth::Scopes.from_string("invalid"),
30
30
  )
31
31
  expect(subject).not_to be_valid
32
32
  end
@@ -49,7 +49,7 @@ class Doorkeeper::OAuth::ClientCredentialsRequest
49
49
  allow(request).to receive(:grant_type).and_return(Doorkeeper::OAuth::CLIENT_CREDENTIALS)
50
50
  allow(server).to receive(:scopes).and_return(server_scopes)
51
51
  allow(request).to receive(:scopes).and_return(
52
- Doorkeeper::OAuth::Scopes.from_string("email")
52
+ Doorkeeper::OAuth::Scopes.from_string("email"),
53
53
  )
54
54
  expect(subject).not_to be_valid
55
55
  end