doorkeeper 5.1.0 → 5.5.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.
- checksums.yaml +4 -4
- data/{NEWS.md → CHANGELOG.md} +234 -25
- data/README.md +21 -11
- data/app/controllers/doorkeeper/application_controller.rb +2 -2
- data/app/controllers/doorkeeper/application_metal_controller.rb +3 -2
- data/app/controllers/doorkeeper/applications_controller.rb +8 -7
- data/app/controllers/doorkeeper/authorizations_controller.rb +56 -19
- data/app/controllers/doorkeeper/authorized_applications_controller.rb +5 -5
- data/app/controllers/doorkeeper/token_info_controller.rb +12 -2
- data/app/controllers/doorkeeper/tokens_controller.rb +93 -25
- data/app/views/doorkeeper/applications/_form.html.erb +1 -7
- data/app/views/doorkeeper/applications/show.html.erb +35 -14
- data/app/views/doorkeeper/authorizations/form_post.html.erb +11 -0
- data/config/locales/en.yml +13 -3
- data/lib/doorkeeper/config/abstract_builder.rb +28 -0
- data/lib/doorkeeper/config/option.rb +20 -2
- data/lib/doorkeeper/config/validations.rb +53 -0
- data/lib/doorkeeper/config.rb +291 -121
- data/lib/doorkeeper/engine.rb +1 -1
- data/lib/doorkeeper/errors.rb +13 -18
- data/lib/doorkeeper/grant_flow/fallback_flow.rb +15 -0
- data/lib/doorkeeper/grant_flow/flow.rb +44 -0
- data/lib/doorkeeper/grant_flow/registry.rb +50 -0
- data/lib/doorkeeper/grant_flow.rb +45 -0
- data/lib/doorkeeper/grape/helpers.rb +7 -3
- data/lib/doorkeeper/helpers/controller.rb +36 -11
- data/lib/doorkeeper/models/access_grant_mixin.rb +22 -18
- data/lib/doorkeeper/models/access_token_mixin.rb +194 -51
- data/lib/doorkeeper/models/application_mixin.rb +8 -7
- data/lib/doorkeeper/models/concerns/ownership.rb +1 -1
- data/lib/doorkeeper/models/concerns/resource_ownerable.rb +47 -0
- data/lib/doorkeeper/models/concerns/reusable.rb +1 -1
- data/lib/doorkeeper/models/concerns/revocable.rb +1 -28
- data/lib/doorkeeper/models/concerns/scopes.rb +5 -1
- data/lib/doorkeeper/models/concerns/secret_storable.rb +1 -3
- data/lib/doorkeeper/oauth/authorization/code.rb +25 -14
- data/lib/doorkeeper/oauth/authorization/context.rb +5 -5
- data/lib/doorkeeper/oauth/authorization/token.rb +24 -19
- data/lib/doorkeeper/oauth/authorization/uri_builder.rb +4 -4
- data/lib/doorkeeper/oauth/authorization_code_request.rb +40 -21
- data/lib/doorkeeper/oauth/base_request.rb +21 -23
- data/lib/doorkeeper/oauth/client/credentials.rb +2 -4
- data/lib/doorkeeper/oauth/client.rb +8 -9
- data/lib/doorkeeper/oauth/client_credentials/creator.rb +45 -5
- data/lib/doorkeeper/oauth/client_credentials/issuer.rb +10 -8
- data/lib/doorkeeper/oauth/client_credentials/{validation.rb → validator.rb} +13 -3
- data/lib/doorkeeper/oauth/client_credentials_request.rb +8 -7
- data/lib/doorkeeper/oauth/code_request.rb +6 -12
- data/lib/doorkeeper/oauth/code_response.rb +24 -14
- data/lib/doorkeeper/oauth/error.rb +1 -1
- data/lib/doorkeeper/oauth/error_response.rb +10 -11
- data/lib/doorkeeper/oauth/helpers/scope_checker.rb +8 -12
- data/lib/doorkeeper/oauth/helpers/unique_token.rb +8 -5
- data/lib/doorkeeper/oauth/helpers/uri_checker.rb +19 -5
- data/lib/doorkeeper/oauth/hooks/context.rb +21 -0
- data/lib/doorkeeper/oauth/invalid_request_response.rb +43 -0
- data/lib/doorkeeper/oauth/invalid_token_response.rb +7 -4
- data/lib/doorkeeper/oauth/nonstandard.rb +39 -0
- data/lib/doorkeeper/oauth/password_access_token_request.rb +32 -10
- data/lib/doorkeeper/oauth/pre_authorization.rb +111 -42
- data/lib/doorkeeper/oauth/refresh_token_request.rb +45 -33
- data/lib/doorkeeper/oauth/token.rb +6 -7
- data/lib/doorkeeper/oauth/token_introspection.rb +24 -18
- data/lib/doorkeeper/oauth/token_request.rb +6 -20
- data/lib/doorkeeper/oauth/token_response.rb +1 -1
- data/lib/doorkeeper/orm/active_record/access_grant.rb +4 -43
- data/lib/doorkeeper/orm/active_record/access_token.rb +4 -35
- data/lib/doorkeeper/orm/active_record/application.rb +5 -83
- data/lib/doorkeeper/orm/active_record/mixins/access_grant.rb +68 -0
- data/lib/doorkeeper/orm/active_record/mixins/access_token.rb +59 -0
- data/lib/doorkeeper/orm/active_record/mixins/application.rb +198 -0
- data/lib/doorkeeper/orm/active_record/redirect_uri_validator.rb +66 -0
- data/lib/doorkeeper/orm/active_record.rb +20 -6
- data/lib/doorkeeper/rails/helpers.rb +4 -4
- data/lib/doorkeeper/rails/routes/abstract_router.rb +35 -0
- data/lib/doorkeeper/rails/routes/mapper.rb +2 -2
- data/lib/doorkeeper/rails/routes/registry.rb +45 -0
- data/lib/doorkeeper/rails/routes.rb +17 -25
- data/lib/doorkeeper/rake/db.rake +6 -6
- data/lib/doorkeeper/rake/setup.rake +5 -0
- data/lib/doorkeeper/request/authorization_code.rb +5 -3
- data/lib/doorkeeper/request/client_credentials.rb +2 -2
- data/lib/doorkeeper/request/password.rb +2 -2
- data/lib/doorkeeper/request/refresh_token.rb +5 -4
- data/lib/doorkeeper/request/strategy.rb +2 -2
- data/lib/doorkeeper/request.rb +49 -17
- data/lib/doorkeeper/server.rb +7 -11
- data/lib/doorkeeper/stale_records_cleaner.rb +6 -2
- data/lib/doorkeeper/version.rb +1 -5
- data/lib/doorkeeper.rb +114 -79
- data/lib/generators/doorkeeper/application_owner_generator.rb +1 -1
- data/lib/generators/doorkeeper/confidential_applications_generator.rb +2 -2
- data/lib/generators/doorkeeper/enable_polymorphic_resource_owner_generator.rb +39 -0
- data/lib/generators/doorkeeper/migration_generator.rb +1 -1
- data/lib/generators/doorkeeper/pkce_generator.rb +1 -1
- data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +7 -7
- data/lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb.erb +3 -1
- data/lib/generators/doorkeeper/templates/add_previous_refresh_token_to_access_tokens.rb.erb +2 -0
- data/lib/generators/doorkeeper/templates/enable_pkce_migration.rb.erb +2 -0
- data/lib/generators/doorkeeper/templates/enable_polymorphic_resource_owner_migration.rb.erb +17 -0
- data/lib/generators/doorkeeper/templates/initializer.rb +205 -43
- data/lib/generators/doorkeeper/templates/migration.rb.erb +18 -6
- metadata +43 -310
- data/.coveralls.yml +0 -1
- data/.github/ISSUE_TEMPLATE.md +0 -25
- data/.github/PULL_REQUEST_TEMPLATE.md +0 -17
- data/.gitignore +0 -20
- data/.gitlab-ci.yml +0 -16
- data/.hound.yml +0 -3
- data/.rspec +0 -1
- data/.rubocop.yml +0 -50
- data/.travis.yml +0 -35
- data/Appraisals +0 -40
- data/CODE_OF_CONDUCT.md +0 -46
- data/CONTRIBUTING.md +0 -47
- data/Dangerfile +0 -67
- data/Gemfile +0 -24
- data/RELEASING.md +0 -10
- data/Rakefile +0 -28
- data/SECURITY.md +0 -15
- data/UPGRADE.md +0 -2
- data/app/validators/redirect_uri_validator.rb +0 -50
- data/bin/console +0 -16
- data/doorkeeper.gemspec +0 -34
- data/gemfiles/rails_5_0.gemfile +0 -17
- data/gemfiles/rails_5_1.gemfile +0 -17
- data/gemfiles/rails_5_2.gemfile +0 -17
- data/gemfiles/rails_6_0.gemfile +0 -17
- data/gemfiles/rails_master.gemfile +0 -17
- data/spec/controllers/application_metal_controller_spec.rb +0 -64
- data/spec/controllers/applications_controller_spec.rb +0 -180
- data/spec/controllers/authorizations_controller_spec.rb +0 -527
- data/spec/controllers/protected_resources_controller_spec.rb +0 -353
- data/spec/controllers/token_info_controller_spec.rb +0 -50
- data/spec/controllers/tokens_controller_spec.rb +0 -330
- data/spec/dummy/Rakefile +0 -9
- data/spec/dummy/app/assets/config/manifest.js +0 -2
- data/spec/dummy/app/controllers/application_controller.rb +0 -5
- data/spec/dummy/app/controllers/custom_authorizations_controller.rb +0 -9
- data/spec/dummy/app/controllers/full_protected_resources_controller.rb +0 -14
- data/spec/dummy/app/controllers/home_controller.rb +0 -18
- data/spec/dummy/app/controllers/metal_controller.rb +0 -13
- data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +0 -13
- data/spec/dummy/app/helpers/application_helper.rb +0 -7
- data/spec/dummy/app/models/user.rb +0 -7
- data/spec/dummy/app/views/home/index.html.erb +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/config/application.rb +0 -47
- data/spec/dummy/config/boot.rb +0 -7
- data/spec/dummy/config/database.yml +0 -15
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -31
- data/spec/dummy/config/environments/production.rb +0 -64
- data/spec/dummy/config/environments/test.rb +0 -45
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -9
- data/spec/dummy/config/initializers/doorkeeper.rb +0 -121
- data/spec/dummy/config/initializers/secret_token.rb +0 -10
- data/spec/dummy/config/initializers/session_store.rb +0 -10
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -16
- data/spec/dummy/config/locales/doorkeeper.en.yml +0 -5
- data/spec/dummy/config/routes.rb +0 -13
- data/spec/dummy/config.ru +0 -6
- data/spec/dummy/db/migrate/20111122132257_create_users.rb +0 -11
- data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +0 -7
- data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +0 -69
- data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +0 -9
- data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +0 -13
- data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +0 -8
- data/spec/dummy/db/migrate/20180210183654_add_confidential_to_applications.rb +0 -13
- data/spec/dummy/db/schema.rb +0 -68
- data/spec/dummy/public/404.html +0 -26
- data/spec/dummy/public/422.html +0 -26
- data/spec/dummy/public/500.html +0 -26
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +0 -9
- data/spec/factories.rb +0 -30
- data/spec/generators/application_owner_generator_spec.rb +0 -28
- data/spec/generators/confidential_applications_generator_spec.rb +0 -29
- data/spec/generators/install_generator_spec.rb +0 -36
- data/spec/generators/migration_generator_spec.rb +0 -28
- data/spec/generators/pkce_generator_spec.rb +0 -28
- data/spec/generators/previous_refresh_token_generator_spec.rb +0 -44
- data/spec/generators/templates/routes.rb +0 -4
- data/spec/generators/views_generator_spec.rb +0 -29
- data/spec/grape/grape_integration_spec.rb +0 -137
- data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +0 -26
- data/spec/lib/config_spec.rb +0 -697
- data/spec/lib/doorkeeper_spec.rb +0 -27
- data/spec/lib/models/expirable_spec.rb +0 -61
- data/spec/lib/models/reusable_spec.rb +0 -40
- data/spec/lib/models/revocable_spec.rb +0 -59
- data/spec/lib/models/scopes_spec.rb +0 -53
- data/spec/lib/models/secret_storable_spec.rb +0 -135
- data/spec/lib/oauth/authorization/uri_builder_spec.rb +0 -39
- data/spec/lib/oauth/authorization_code_request_spec.rb +0 -156
- data/spec/lib/oauth/base_request_spec.rb +0 -205
- data/spec/lib/oauth/base_response_spec.rb +0 -47
- data/spec/lib/oauth/client/credentials_spec.rb +0 -90
- data/spec/lib/oauth/client_credentials/creator_spec.rb +0 -94
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +0 -112
- data/spec/lib/oauth/client_credentials/validation_spec.rb +0 -59
- data/spec/lib/oauth/client_credentials_integration_spec.rb +0 -29
- data/spec/lib/oauth/client_credentials_request_spec.rb +0 -109
- data/spec/lib/oauth/client_spec.rb +0 -38
- data/spec/lib/oauth/code_request_spec.rb +0 -47
- data/spec/lib/oauth/code_response_spec.rb +0 -36
- data/spec/lib/oauth/error_response_spec.rb +0 -66
- data/spec/lib/oauth/error_spec.rb +0 -23
- data/spec/lib/oauth/forbidden_token_response_spec.rb +0 -22
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +0 -98
- data/spec/lib/oauth/helpers/unique_token_spec.rb +0 -21
- data/spec/lib/oauth/helpers/uri_checker_spec.rb +0 -247
- data/spec/lib/oauth/invalid_token_response_spec.rb +0 -55
- data/spec/lib/oauth/password_access_token_request_spec.rb +0 -192
- data/spec/lib/oauth/pre_authorization_spec.rb +0 -215
- data/spec/lib/oauth/refresh_token_request_spec.rb +0 -177
- data/spec/lib/oauth/scopes_spec.rb +0 -148
- data/spec/lib/oauth/token_request_spec.rb +0 -150
- data/spec/lib/oauth/token_response_spec.rb +0 -86
- data/spec/lib/oauth/token_spec.rb +0 -158
- data/spec/lib/request/strategy_spec.rb +0 -54
- data/spec/lib/secret_storing/base_spec.rb +0 -60
- data/spec/lib/secret_storing/bcrypt_spec.rb +0 -49
- data/spec/lib/secret_storing/plain_spec.rb +0 -44
- data/spec/lib/secret_storing/sha256_hash_spec.rb +0 -48
- data/spec/lib/server_spec.rb +0 -61
- data/spec/lib/stale_records_cleaner_spec.rb +0 -89
- data/spec/models/doorkeeper/access_grant_spec.rb +0 -144
- data/spec/models/doorkeeper/access_token_spec.rb +0 -591
- data/spec/models/doorkeeper/application_spec.rb +0 -367
- data/spec/requests/applications/applications_request_spec.rb +0 -259
- data/spec/requests/applications/authorized_applications_spec.rb +0 -32
- data/spec/requests/endpoints/authorization_spec.rb +0 -73
- data/spec/requests/endpoints/token_spec.rb +0 -75
- data/spec/requests/flows/authorization_code_errors_spec.rb +0 -78
- data/spec/requests/flows/authorization_code_spec.rb +0 -447
- data/spec/requests/flows/client_credentials_spec.rb +0 -128
- data/spec/requests/flows/implicit_grant_errors_spec.rb +0 -34
- data/spec/requests/flows/implicit_grant_spec.rb +0 -90
- data/spec/requests/flows/password_spec.rb +0 -259
- data/spec/requests/flows/refresh_token_spec.rb +0 -233
- data/spec/requests/flows/revoke_token_spec.rb +0 -143
- data/spec/requests/flows/skip_authorization_spec.rb +0 -66
- data/spec/requests/protected_resources/metal_spec.rb +0 -16
- data/spec/requests/protected_resources/private_api_spec.rb +0 -83
- data/spec/routing/custom_controller_routes_spec.rb +0 -133
- data/spec/routing/default_routes_spec.rb +0 -41
- data/spec/routing/scoped_routes_spec.rb +0 -47
- data/spec/spec_helper.rb +0 -57
- data/spec/spec_helper_integration.rb +0 -4
- data/spec/support/dependencies/factory_bot.rb +0 -4
- data/spec/support/doorkeeper_rspec.rb +0 -22
- data/spec/support/helpers/access_token_request_helper.rb +0 -13
- data/spec/support/helpers/authorization_request_helper.rb +0 -43
- data/spec/support/helpers/config_helper.rb +0 -11
- data/spec/support/helpers/model_helper.rb +0 -78
- data/spec/support/helpers/request_spec_helper.rb +0 -98
- data/spec/support/helpers/url_helper.rb +0 -62
- data/spec/support/http_method_shim.rb +0 -29
- data/spec/support/orm/active_record.rb +0 -5
- data/spec/support/shared/controllers_shared_context.rb +0 -123
- data/spec/support/shared/hashing_shared_context.rb +0 -36
- data/spec/support/shared/models_shared_examples.rb +0 -54
- data/spec/validators/redirect_uri_validator_spec.rb +0 -158
- data/spec/version/version_spec.rb +0 -17
@@ -1,205 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
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
|
17
|
-
|
18
|
-
let(:client) { double :client, id: "1" }
|
19
|
-
|
20
|
-
let(:scopes_array) { %w[public write] }
|
21
|
-
|
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
|
28
|
-
|
29
|
-
before do
|
30
|
-
allow(server).to receive(:option_defined?).with(:custom_access_token_expires_in).and_return(true)
|
31
|
-
end
|
32
|
-
|
33
|
-
subject do
|
34
|
-
BaseRequest.new
|
35
|
-
end
|
36
|
-
|
37
|
-
describe "#authorize" do
|
38
|
-
before do
|
39
|
-
allow(subject).to receive(:access_token).and_return(access_token)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "validates itself" do
|
43
|
-
expect(subject).to receive(:validate).once
|
44
|
-
subject.authorize
|
45
|
-
end
|
46
|
-
|
47
|
-
context "valid" do
|
48
|
-
before do
|
49
|
-
allow(subject).to receive(:valid?).and_return(true)
|
50
|
-
end
|
51
|
-
|
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
|
56
|
-
end
|
57
|
-
|
58
|
-
it "returns a TokenResponse object" do
|
59
|
-
result = subject.authorize
|
60
|
-
|
61
|
-
expect(result).to be_an_instance_of(TokenResponse)
|
62
|
-
expect(result.body).to eq(
|
63
|
-
TokenResponse.new(access_token).body
|
64
|
-
)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
context "invalid" 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")
|
73
|
-
end
|
74
|
-
|
75
|
-
it "returns an ErrorResponse object" do
|
76
|
-
error_description = I18n.translate(
|
77
|
-
"server_error",
|
78
|
-
scope: %i[doorkeeper errors messages]
|
79
|
-
)
|
80
|
-
|
81
|
-
result = subject.authorize
|
82
|
-
|
83
|
-
expect(result).to be_an_instance_of(ErrorResponse)
|
84
|
-
|
85
|
-
expect(result.body).to eq(
|
86
|
-
error: "server_error",
|
87
|
-
error_description: error_description,
|
88
|
-
state: "hello"
|
89
|
-
)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
describe "#default_scopes" do
|
95
|
-
it "delegates to the server" do
|
96
|
-
expect(subject).to receive(:server).and_return(server).once
|
97
|
-
expect(server).to receive(:default_scopes).once
|
98
|
-
|
99
|
-
subject.default_scopes
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
describe "#find_or_create_access_token" do
|
104
|
-
it "returns an instance of AccessToken" do
|
105
|
-
result = subject.find_or_create_access_token(
|
106
|
-
client,
|
107
|
-
"1",
|
108
|
-
"public",
|
109
|
-
server
|
110
|
-
)
|
111
|
-
|
112
|
-
expect(result).to be_an_instance_of(Doorkeeper::AccessToken)
|
113
|
-
end
|
114
|
-
|
115
|
-
it "respects custom_access_token_expires_in" do
|
116
|
-
server = double(:server,
|
117
|
-
access_token_expires_in: 100,
|
118
|
-
custom_access_token_expires_in: ->(context) { context.scopes == "public" ? 500 : nil },
|
119
|
-
refresh_token_enabled?: false)
|
120
|
-
|
121
|
-
allow(server).to receive(:option_defined?).with(:custom_access_token_expires_in).and_return(true)
|
122
|
-
|
123
|
-
result = subject.find_or_create_access_token(
|
124
|
-
client,
|
125
|
-
"1",
|
126
|
-
"public",
|
127
|
-
server
|
128
|
-
)
|
129
|
-
expect(result.expires_in).to eql(500)
|
130
|
-
end
|
131
|
-
|
132
|
-
it "respects use_refresh_token with a block" do
|
133
|
-
server = double(:server,
|
134
|
-
access_token_expires_in: 100,
|
135
|
-
custom_access_token_expires_in: ->(_context) { nil },
|
136
|
-
refresh_token_enabled?: lambda { |context|
|
137
|
-
context.scopes == "public"
|
138
|
-
})
|
139
|
-
|
140
|
-
allow(server).to receive(:option_defined?).with(:custom_access_token_expires_in).and_return(true)
|
141
|
-
|
142
|
-
result = subject.find_or_create_access_token(
|
143
|
-
client,
|
144
|
-
"1",
|
145
|
-
"public",
|
146
|
-
server
|
147
|
-
)
|
148
|
-
expect(result.refresh_token).to_not be_nil
|
149
|
-
|
150
|
-
result = subject.find_or_create_access_token(
|
151
|
-
client,
|
152
|
-
"1",
|
153
|
-
"private",
|
154
|
-
server
|
155
|
-
)
|
156
|
-
expect(result.refresh_token).to be_nil
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
describe "#scopes" do
|
161
|
-
context "@original_scopes is present" do
|
162
|
-
before do
|
163
|
-
subject.instance_variable_set(:@original_scopes, "public write")
|
164
|
-
end
|
165
|
-
|
166
|
-
it "returns array of @original_scopes" do
|
167
|
-
result = subject.scopes
|
168
|
-
|
169
|
-
expect(result).to eq(scopes_array)
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
context "@original_scopes is not present" do
|
174
|
-
before do
|
175
|
-
subject.instance_variable_set(:@original_scopes, "")
|
176
|
-
end
|
177
|
-
|
178
|
-
it "calls #default_scopes" do
|
179
|
-
allow(subject).to receive(:server).and_return(server).once
|
180
|
-
allow(server).to receive(:default_scopes).and_return(scopes_array).once
|
181
|
-
|
182
|
-
result = subject.scopes
|
183
|
-
|
184
|
-
expect(result).to eq(scopes_array)
|
185
|
-
end
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
describe "#valid?" do
|
190
|
-
context "error is nil" do
|
191
|
-
it "returns true" do
|
192
|
-
allow(subject).to receive(:error).and_return(nil).once
|
193
|
-
expect(subject.valid?).to eq(true)
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
context "error is not nil" do
|
198
|
-
it "returns false" do
|
199
|
-
allow(subject).to receive(:error).and_return(Object.new).once
|
200
|
-
expect(subject.valid?).to eq(false)
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|
204
|
-
end
|
205
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
module Doorkeeper::OAuth
|
6
|
-
describe BaseResponse do
|
7
|
-
subject do
|
8
|
-
BaseResponse.new
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "#body" do
|
12
|
-
it "returns an empty Hash" do
|
13
|
-
expect(subject.body).to eq({})
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "#description" do
|
18
|
-
it "returns an empty String" do
|
19
|
-
expect(subject.description).to eq("")
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "#headers" do
|
24
|
-
it "returns an empty Hash" do
|
25
|
-
expect(subject.headers).to eq({})
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "#redirectable?" do
|
30
|
-
it "returns false" do
|
31
|
-
expect(subject.redirectable?).to eq(false)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "#redirect_uri" do
|
36
|
-
it "returns an empty String" do
|
37
|
-
expect(subject.redirect_uri).to eq("")
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "#status" do
|
42
|
-
it "returns :ok" do
|
43
|
-
expect(subject.status).to eq(:ok)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,90 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
class Doorkeeper::OAuth::Client
|
6
|
-
describe Credentials do
|
7
|
-
let(:client_id) { "some-uid" }
|
8
|
-
let(:client_secret) { "some-secret" }
|
9
|
-
|
10
|
-
it "is blank when the uid in credentials is blank" do
|
11
|
-
expect(Credentials.new(nil, nil)).to be_blank
|
12
|
-
expect(Credentials.new(nil, "something")).to be_blank
|
13
|
-
expect(Credentials.new("something", nil)).to be_present
|
14
|
-
expect(Credentials.new("something", "something")).to be_present
|
15
|
-
end
|
16
|
-
|
17
|
-
describe :from_request do
|
18
|
-
let(:request) { double.as_null_object }
|
19
|
-
|
20
|
-
let(:method) do
|
21
|
-
->(_request) { %w[uid secret] }
|
22
|
-
end
|
23
|
-
|
24
|
-
it "accepts anything that responds to #call" do
|
25
|
-
expect(method).to receive(:call).with(request)
|
26
|
-
Credentials.from_request request, method
|
27
|
-
end
|
28
|
-
|
29
|
-
it "delegates methods received as symbols to Credentials class" do
|
30
|
-
expect(Credentials).to receive(:from_params).with(request)
|
31
|
-
Credentials.from_request request, :from_params
|
32
|
-
end
|
33
|
-
|
34
|
-
it "stops at the first credentials found" do
|
35
|
-
not_called_method = double
|
36
|
-
expect(not_called_method).not_to receive(:call)
|
37
|
-
Credentials.from_request request, ->(_) {}, method, not_called_method
|
38
|
-
end
|
39
|
-
|
40
|
-
it "returns new Credentials" do
|
41
|
-
credentials = Credentials.from_request request, method
|
42
|
-
expect(credentials).to be_a(Credentials)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "returns uid and secret from extractor method" do
|
46
|
-
credentials = Credentials.from_request request, method
|
47
|
-
expect(credentials.uid).to eq("uid")
|
48
|
-
expect(credentials.secret).to eq("secret")
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe :from_params do
|
53
|
-
it "returns credentials from parameters when Authorization header is not available" do
|
54
|
-
request = double parameters: { client_id: client_id, client_secret: client_secret }
|
55
|
-
uid, secret = Credentials.from_params(request)
|
56
|
-
|
57
|
-
expect(uid).to eq("some-uid")
|
58
|
-
expect(secret).to eq("some-secret")
|
59
|
-
end
|
60
|
-
|
61
|
-
it "is blank when there are no credentials" do
|
62
|
-
request = double parameters: {}
|
63
|
-
uid, secret = Credentials.from_params(request)
|
64
|
-
|
65
|
-
expect(uid).to be_blank
|
66
|
-
expect(secret).to be_blank
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe :from_basic do
|
71
|
-
let(:credentials) { Base64.encode64("#{client_id}:#{client_secret}") }
|
72
|
-
|
73
|
-
it "decodes the credentials" do
|
74
|
-
request = double authorization: "Basic #{credentials}"
|
75
|
-
uid, secret = Credentials.from_basic(request)
|
76
|
-
|
77
|
-
expect(uid).to eq("some-uid")
|
78
|
-
expect(secret).to eq("some-secret")
|
79
|
-
end
|
80
|
-
|
81
|
-
it "is blank if Authorization is not Basic" do
|
82
|
-
request = double authorization: credentials.to_s
|
83
|
-
uid, secret = Credentials.from_basic(request)
|
84
|
-
|
85
|
-
expect(uid).to be_blank
|
86
|
-
expect(secret).to be_blank
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
@@ -1,94 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
class Doorkeeper::OAuth::ClientCredentialsRequest
|
6
|
-
describe Creator do
|
7
|
-
let(:client) { FactoryBot.create :application }
|
8
|
-
let(:scopes) { Doorkeeper::OAuth::Scopes.from_string("public") }
|
9
|
-
|
10
|
-
before do
|
11
|
-
default_scopes_exist :public
|
12
|
-
end
|
13
|
-
|
14
|
-
it "creates a new token" do
|
15
|
-
expect do
|
16
|
-
subject.call(client, scopes)
|
17
|
-
end.to change { Doorkeeper::AccessToken.count }.by(1)
|
18
|
-
end
|
19
|
-
|
20
|
-
context "when reuse_access_token is true" do
|
21
|
-
context "when expiration is disabled" do
|
22
|
-
it "returns the existing valid token" do
|
23
|
-
allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(true)
|
24
|
-
existing_token = subject.call(client, scopes)
|
25
|
-
|
26
|
-
result = subject.call(client, scopes)
|
27
|
-
|
28
|
-
expect(Doorkeeper::AccessToken.count).to eq(1)
|
29
|
-
expect(result).to eq(existing_token)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context "when existing token has not crossed token_reuse_limit" do
|
34
|
-
it "returns the existing valid token" do
|
35
|
-
allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(true)
|
36
|
-
allow(Doorkeeper.configuration).to receive(:token_reuse_limit).and_return(50)
|
37
|
-
existing_token = subject.call(client, scopes, expires_in: 1000)
|
38
|
-
|
39
|
-
allow_any_instance_of(Doorkeeper::AccessToken).to receive(:expires_in_seconds).and_return(600)
|
40
|
-
result = subject.call(client, scopes, expires_in: 1000)
|
41
|
-
|
42
|
-
expect(Doorkeeper::AccessToken.count).to eq(1)
|
43
|
-
expect(result).to eq(existing_token)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context "when existing token has crossed token_reuse_limit" do
|
48
|
-
it "returns a new token" do
|
49
|
-
allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(true)
|
50
|
-
allow(Doorkeeper.configuration).to receive(:token_reuse_limit).and_return(50)
|
51
|
-
existing_token = subject.call(client, scopes, expires_in: 1000)
|
52
|
-
|
53
|
-
allow_any_instance_of(Doorkeeper::AccessToken).to receive(:expires_in_seconds).and_return(400)
|
54
|
-
result = subject.call(client, scopes, expires_in: 1000)
|
55
|
-
|
56
|
-
expect(Doorkeeper::AccessToken.count).to eq(2)
|
57
|
-
expect(result).not_to eq(existing_token)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context "when existing token has been expired" do
|
62
|
-
it "returns a new token" do
|
63
|
-
allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(true)
|
64
|
-
allow(Doorkeeper.configuration).to receive(:token_reuse_limit).and_return(50)
|
65
|
-
existing_token = subject.call(client, scopes, expires_in: 1000)
|
66
|
-
|
67
|
-
allow_any_instance_of(Doorkeeper::AccessToken).to receive(:expired?).and_return(true)
|
68
|
-
result = subject.call(client, scopes, expires_in: 1000)
|
69
|
-
|
70
|
-
expect(Doorkeeper::AccessToken.count).to eq(2)
|
71
|
-
expect(result).not_to eq(existing_token)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
context "when reuse_access_token is false" do
|
77
|
-
it "returns a new token" do
|
78
|
-
allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(false)
|
79
|
-
existing_token = subject.call(client, scopes)
|
80
|
-
|
81
|
-
result = subject.call(client, scopes)
|
82
|
-
|
83
|
-
expect(Doorkeeper::AccessToken.count).to eq(2)
|
84
|
-
expect(result).not_to eq(existing_token)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
it "returns false if creation fails" do
|
89
|
-
expect(Doorkeeper::AccessToken).to receive(:find_or_create_for).and_return(false)
|
90
|
-
created = subject.call(client, scopes)
|
91
|
-
expect(created).to be_falsey
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
@@ -1,112 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
class Doorkeeper::OAuth::ClientCredentialsRequest
|
6
|
-
describe Issuer do
|
7
|
-
let(:creator) { double :access_token_creator }
|
8
|
-
let(:server) do
|
9
|
-
double(
|
10
|
-
:server,
|
11
|
-
access_token_expires_in: 100
|
12
|
-
)
|
13
|
-
end
|
14
|
-
let(:validation) { double :validation, valid?: true }
|
15
|
-
|
16
|
-
before do
|
17
|
-
allow(server).to receive(:option_defined?).with(:custom_access_token_expires_in).and_return(false)
|
18
|
-
end
|
19
|
-
|
20
|
-
subject { Issuer.new(server, validation) }
|
21
|
-
|
22
|
-
describe :create do
|
23
|
-
let(:client) { double :client, id: "some-id" }
|
24
|
-
let(:scopes) { "some scope" }
|
25
|
-
|
26
|
-
it "creates and sets the token" do
|
27
|
-
expect(creator).to receive(:call).and_return("token")
|
28
|
-
subject.create client, scopes, creator
|
29
|
-
|
30
|
-
expect(subject.token).to eq("token")
|
31
|
-
end
|
32
|
-
|
33
|
-
it "creates with correct token parameters" do
|
34
|
-
expect(creator).to receive(:call).with(
|
35
|
-
client,
|
36
|
-
scopes,
|
37
|
-
expires_in: 100,
|
38
|
-
use_refresh_token: false
|
39
|
-
)
|
40
|
-
|
41
|
-
subject.create client, scopes, creator
|
42
|
-
end
|
43
|
-
|
44
|
-
it "has error set to :server_error if creator fails" do
|
45
|
-
expect(creator).to receive(:call).and_return(false)
|
46
|
-
subject.create client, scopes, creator
|
47
|
-
|
48
|
-
expect(subject.error).to eq(:server_error)
|
49
|
-
end
|
50
|
-
|
51
|
-
context "when validation fails" do
|
52
|
-
before do
|
53
|
-
allow(validation).to receive(:valid?).and_return(false)
|
54
|
-
allow(validation).to receive(:error).and_return(:validation_error)
|
55
|
-
expect(creator).not_to receive(:create)
|
56
|
-
end
|
57
|
-
|
58
|
-
it "has error set from validation" do
|
59
|
-
subject.create client, scopes, creator
|
60
|
-
expect(subject.error).to eq(:validation_error)
|
61
|
-
end
|
62
|
-
|
63
|
-
it "returns false" do
|
64
|
-
expect(subject.create(client, scopes, creator)).to be_falsey
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
context "with custom expirations" do
|
69
|
-
let(:custom_ttl_grant) { 1234 }
|
70
|
-
let(:custom_ttl_scope) { 1235 }
|
71
|
-
let(:custom_scope) { "special" }
|
72
|
-
let(:server) do
|
73
|
-
double(
|
74
|
-
:server,
|
75
|
-
custom_access_token_expires_in: lambda { |context|
|
76
|
-
# scopes is normally an object but is a string in this test
|
77
|
-
if context.scopes == custom_scope
|
78
|
-
custom_ttl_scope
|
79
|
-
elsif context.grant_type == Doorkeeper::OAuth::CLIENT_CREDENTIALS
|
80
|
-
custom_ttl_grant
|
81
|
-
end
|
82
|
-
}
|
83
|
-
)
|
84
|
-
end
|
85
|
-
|
86
|
-
before do
|
87
|
-
allow(server).to receive(:option_defined?).with(:custom_access_token_expires_in).and_return(true)
|
88
|
-
end
|
89
|
-
|
90
|
-
it "respects grant based rules" do
|
91
|
-
expect(creator).to receive(:call).with(
|
92
|
-
client,
|
93
|
-
scopes,
|
94
|
-
expires_in: custom_ttl_grant,
|
95
|
-
use_refresh_token: false
|
96
|
-
)
|
97
|
-
subject.create client, scopes, creator
|
98
|
-
end
|
99
|
-
|
100
|
-
it "respects scope based rules" do
|
101
|
-
expect(creator).to receive(:call).with(
|
102
|
-
client,
|
103
|
-
custom_scope,
|
104
|
-
expires_in: custom_ttl_scope,
|
105
|
-
use_refresh_token: false
|
106
|
-
)
|
107
|
-
subject.create client, custom_scope, creator
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
class Doorkeeper::OAuth::ClientCredentialsRequest
|
6
|
-
describe Validation do
|
7
|
-
let(:server) { double :server, scopes: nil }
|
8
|
-
let(:application) { double scopes: nil }
|
9
|
-
let(:client) { double application: application }
|
10
|
-
let(:request) { double :request, client: client, scopes: nil }
|
11
|
-
|
12
|
-
subject { Validation.new(server, request) }
|
13
|
-
|
14
|
-
it "is valid with valid request" do
|
15
|
-
expect(subject).to be_valid
|
16
|
-
end
|
17
|
-
|
18
|
-
it "is invalid when client is not present" do
|
19
|
-
allow(request).to receive(:client).and_return(nil)
|
20
|
-
expect(subject).not_to be_valid
|
21
|
-
end
|
22
|
-
|
23
|
-
context "with scopes" do
|
24
|
-
it "is invalid when scopes are not included in the server" do
|
25
|
-
server_scopes = Doorkeeper::OAuth::Scopes.from_string "email"
|
26
|
-
allow(request).to receive(:grant_type).and_return(Doorkeeper::OAuth::CLIENT_CREDENTIALS)
|
27
|
-
allow(server).to receive(:scopes).and_return(server_scopes)
|
28
|
-
allow(request).to receive(:scopes).and_return(
|
29
|
-
Doorkeeper::OAuth::Scopes.from_string("invalid")
|
30
|
-
)
|
31
|
-
expect(subject).not_to be_valid
|
32
|
-
end
|
33
|
-
|
34
|
-
context "with application scopes" do
|
35
|
-
it "is valid when scopes are included in the application" do
|
36
|
-
application_scopes = Doorkeeper::OAuth::Scopes.from_string "app"
|
37
|
-
server_scopes = Doorkeeper::OAuth::Scopes.from_string "email app"
|
38
|
-
allow(application).to receive(:scopes).and_return(application_scopes)
|
39
|
-
allow(server).to receive(:scopes).and_return(server_scopes)
|
40
|
-
allow(request).to receive(:grant_type).and_return(Doorkeeper::OAuth::CLIENT_CREDENTIALS)
|
41
|
-
allow(request).to receive(:scopes).and_return(application_scopes)
|
42
|
-
expect(subject).to be_valid
|
43
|
-
end
|
44
|
-
|
45
|
-
it "is invalid when scopes are not included in the application" do
|
46
|
-
application_scopes = Doorkeeper::OAuth::Scopes.from_string "app"
|
47
|
-
server_scopes = Doorkeeper::OAuth::Scopes.from_string "email app"
|
48
|
-
allow(application).to receive(:scopes).and_return(application_scopes)
|
49
|
-
allow(request).to receive(:grant_type).and_return(Doorkeeper::OAuth::CLIENT_CREDENTIALS)
|
50
|
-
allow(server).to receive(:scopes).and_return(server_scopes)
|
51
|
-
allow(request).to receive(:scopes).and_return(
|
52
|
-
Doorkeeper::OAuth::Scopes.from_string("email")
|
53
|
-
)
|
54
|
-
expect(subject).not_to be_valid
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
module Doorkeeper::OAuth
|
6
|
-
describe ClientCredentialsRequest do
|
7
|
-
let(:server) { Doorkeeper.configuration }
|
8
|
-
|
9
|
-
context "with a valid request" do
|
10
|
-
let(:client) { FactoryBot.create :application }
|
11
|
-
|
12
|
-
it "issues an access token" do
|
13
|
-
request = ClientCredentialsRequest.new(server, client, {})
|
14
|
-
expect do
|
15
|
-
request.authorize
|
16
|
-
end.to change { Doorkeeper::AccessToken.count }.by(1)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "with an invalid request" do
|
21
|
-
it "does not issue an access token" do
|
22
|
-
request = ClientCredentialsRequest.new(server, nil, {})
|
23
|
-
expect do
|
24
|
-
request.authorize
|
25
|
-
end.to_not(change { Doorkeeper::AccessToken.count })
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|