doorkeeper 5.1.0.rc2 → 5.1.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/.hound.yml +2 -1
- data/.rubocop.yml +37 -4
- data/.travis.yml +4 -27
- data/Appraisals +8 -12
- data/Gemfile +6 -2
- data/NEWS.md +16 -0
- data/README.md +11 -2
- data/Rakefile +10 -8
- data/app/controllers/doorkeeper/application_controller.rb +1 -2
- data/app/controllers/doorkeeper/application_metal_controller.rb +2 -13
- data/app/controllers/doorkeeper/applications_controller.rb +17 -5
- data/app/controllers/doorkeeper/token_info_controller.rb +1 -1
- data/app/controllers/doorkeeper/tokens_controller.rb +7 -7
- data/app/helpers/doorkeeper/dashboard_helper.rb +1 -1
- data/app/validators/redirect_uri_validator.rb +5 -2
- data/app/views/doorkeeper/applications/_form.html.erb +6 -0
- data/bin/console +5 -4
- data/config/locales/en.yml +1 -0
- data/doorkeeper.gemspec +24 -22
- data/gemfiles/rails_5_0.gemfile +2 -1
- data/gemfiles/rails_5_1.gemfile +2 -1
- data/gemfiles/rails_5_2.gemfile +2 -1
- data/gemfiles/rails_6_0.gemfile +1 -0
- data/gemfiles/rails_master.gemfile +1 -0
- data/lib/doorkeeper.rb +68 -66
- data/lib/doorkeeper/config.rb +53 -90
- data/lib/doorkeeper/config/option.rb +64 -0
- data/lib/doorkeeper/engine.rb +1 -1
- data/lib/doorkeeper/grape/authorization_decorator.rb +4 -4
- data/lib/doorkeeper/grape/helpers.rb +3 -3
- data/lib/doorkeeper/helpers/controller.rb +1 -1
- data/lib/doorkeeper/models/access_grant_mixin.rb +4 -2
- data/lib/doorkeeper/models/access_token_mixin.rb +10 -10
- data/lib/doorkeeper/models/application_mixin.rb +1 -0
- data/lib/doorkeeper/models/concerns/expirable.rb +1 -0
- data/lib/doorkeeper/models/concerns/ownership.rb +1 -6
- data/lib/doorkeeper/models/concerns/revocable.rb +2 -1
- data/lib/doorkeeper/models/concerns/scopes.rb +1 -1
- data/lib/doorkeeper/models/concerns/secret_storable.rb +2 -0
- data/lib/doorkeeper/oauth.rb +5 -5
- data/lib/doorkeeper/oauth/authorization/code.rb +1 -1
- data/lib/doorkeeper/oauth/authorization/token.rb +9 -6
- data/lib/doorkeeper/oauth/authorization/uri_builder.rb +1 -1
- data/lib/doorkeeper/oauth/authorization_code_request.rb +5 -3
- data/lib/doorkeeper/oauth/client_credentials/validation.rb +1 -1
- data/lib/doorkeeper/oauth/client_credentials_request.rb +1 -1
- data/lib/doorkeeper/oauth/error_response.rb +5 -5
- data/lib/doorkeeper/oauth/forbidden_token_response.rb +1 -1
- data/lib/doorkeeper/oauth/helpers/scope_checker.rb +1 -1
- data/lib/doorkeeper/oauth/helpers/unique_token.rb +2 -1
- data/lib/doorkeeper/oauth/helpers/uri_checker.rb +6 -2
- data/lib/doorkeeper/oauth/invalid_token_response.rb +1 -1
- data/lib/doorkeeper/oauth/pre_authorization.rb +4 -3
- data/lib/doorkeeper/oauth/refresh_token_request.rb +1 -1
- data/lib/doorkeeper/oauth/scopes.rb +5 -3
- data/lib/doorkeeper/oauth/token.rb +2 -2
- data/lib/doorkeeper/oauth/token_introspection.rb +4 -4
- data/lib/doorkeeper/oauth/token_response.rb +9 -9
- data/lib/doorkeeper/orm/active_record.rb +6 -6
- data/lib/doorkeeper/orm/active_record/access_grant.rb +5 -12
- data/lib/doorkeeper/orm/active_record/access_token.rb +6 -13
- data/lib/doorkeeper/orm/active_record/application.rb +6 -5
- data/lib/doorkeeper/orm/active_record/stale_records_cleaner.rb +10 -3
- data/lib/doorkeeper/rails/helpers.rb +1 -1
- data/lib/doorkeeper/rails/routes.rb +11 -11
- data/lib/doorkeeper/rails/routes/mapping.rb +7 -7
- data/lib/doorkeeper/rake.rb +1 -1
- data/lib/doorkeeper/rake/db.rake +13 -13
- data/lib/doorkeeper/request.rb +1 -1
- data/lib/doorkeeper/secret_storing/base.rb +7 -6
- data/lib/doorkeeper/secret_storing/bcrypt.rb +4 -3
- data/lib/doorkeeper/secret_storing/plain.rb +4 -4
- data/lib/doorkeeper/secret_storing/sha256_hash.rb +3 -2
- data/lib/doorkeeper/stale_records_cleaner.rb +1 -1
- data/lib/doorkeeper/version.rb +2 -2
- data/lib/generators/doorkeeper/application_owner_generator.rb +10 -9
- data/lib/generators/doorkeeper/confidential_applications_generator.rb +10 -9
- data/lib/generators/doorkeeper/install_generator.rb +11 -9
- data/lib/generators/doorkeeper/migration_generator.rb +9 -9
- data/lib/generators/doorkeeper/pkce_generator.rb +10 -9
- data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +10 -9
- data/lib/generators/doorkeeper/templates/initializer.rb +30 -5
- data/lib/generators/doorkeeper/templates/migration.rb.erb +15 -7
- data/lib/generators/doorkeeper/views_generator.rb +6 -4
- data/spec/controllers/application_metal_controller_spec.rb +10 -10
- data/spec/controllers/applications_controller_spec.rb +54 -52
- data/spec/controllers/authorizations_controller_spec.rb +136 -142
- data/spec/controllers/protected_resources_controller_spec.rb +78 -76
- data/spec/controllers/token_info_controller_spec.rb +13 -11
- data/spec/controllers/tokens_controller_spec.rb +109 -94
- data/spec/dummy/Rakefile +3 -1
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/controllers/custom_authorizations_controller.rb +2 -0
- data/spec/dummy/app/controllers/full_protected_resources_controller.rb +4 -2
- data/spec/dummy/app/controllers/home_controller.rb +5 -3
- data/spec/dummy/app/controllers/metal_controller.rb +2 -0
- data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +4 -2
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/models/user.rb +2 -0
- data/spec/dummy/config.ru +3 -1
- data/spec/dummy/config/application.rb +13 -0
- data/spec/dummy/config/environments/development.rb +2 -0
- data/spec/dummy/config/environments/production.rb +2 -0
- data/spec/dummy/config/environments/test.rb +3 -1
- data/spec/dummy/config/initializers/backtrace_silencers.rb +2 -0
- data/spec/dummy/config/initializers/doorkeeper.rb +5 -2
- data/spec/dummy/config/initializers/secret_token.rb +3 -1
- data/spec/dummy/config/initializers/session_store.rb +3 -1
- data/spec/dummy/config/initializers/wrap_parameters.rb +2 -0
- data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +17 -10
- data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +2 -0
- data/spec/dummy/db/schema.rb +1 -1
- data/spec/dummy/script/rails +5 -3
- data/spec/factories.rb +5 -3
- data/spec/generators/application_owner_generator_spec.rb +13 -26
- data/spec/generators/confidential_applications_generator_spec.rb +12 -28
- data/spec/generators/install_generator_spec.rb +17 -15
- data/spec/generators/migration_generator_spec.rb +13 -26
- data/spec/generators/pkce_generator_spec.rb +11 -26
- data/spec/generators/previous_refresh_token_generator_spec.rb +16 -29
- data/spec/generators/templates/routes.rb +2 -0
- data/spec/generators/views_generator_spec.rb +14 -12
- data/spec/grape/grape_integration_spec.rb +34 -32
- data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +9 -7
- data/spec/lib/config_spec.rb +137 -136
- data/spec/lib/doorkeeper_spec.rb +3 -1
- data/spec/lib/models/expirable_spec.rb +12 -10
- data/spec/lib/models/reusable_spec.rb +6 -6
- data/spec/lib/models/revocable_spec.rb +8 -6
- data/spec/lib/models/scopes_spec.rb +19 -17
- data/spec/lib/models/secret_storable_spec.rb +71 -49
- data/spec/lib/oauth/authorization/uri_builder_spec.rb +17 -15
- data/spec/lib/oauth/authorization_code_request_spec.rb +18 -12
- data/spec/lib/oauth/base_request_spec.rb +20 -8
- data/spec/lib/oauth/base_response_spec.rb +3 -1
- data/spec/lib/oauth/client/credentials_spec.rb +24 -22
- data/spec/lib/oauth/client_credentials/creator_spec.rb +13 -11
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +27 -18
- data/spec/lib/oauth/client_credentials/validation_spec.rb +17 -15
- data/spec/lib/oauth/client_credentials_integration_spec.rb +7 -5
- data/spec/lib/oauth/client_credentials_request_spec.rb +27 -21
- data/spec/lib/oauth/client_spec.rb +15 -13
- data/spec/lib/oauth/code_request_spec.rb +8 -6
- data/spec/lib/oauth/code_response_spec.rb +9 -7
- data/spec/lib/oauth/error_response_spec.rb +14 -12
- data/spec/lib/oauth/error_spec.rb +4 -2
- data/spec/lib/oauth/forbidden_token_response_spec.rb +7 -5
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +35 -33
- data/spec/lib/oauth/helpers/unique_token_spec.rb +8 -6
- data/spec/lib/oauth/helpers/uri_checker_spec.rb +103 -101
- data/spec/lib/oauth/invalid_token_response_spec.rb +3 -1
- data/spec/lib/oauth/password_access_token_request_spec.rb +52 -34
- data/spec/lib/oauth/pre_authorization_spec.rb +64 -62
- data/spec/lib/oauth/refresh_token_request_spec.rb +36 -33
- data/spec/lib/oauth/scopes_spec.rb +63 -61
- data/spec/lib/oauth/token_request_spec.rb +66 -26
- data/spec/lib/oauth/token_response_spec.rb +39 -37
- data/spec/lib/oauth/token_spec.rb +51 -49
- data/spec/lib/request/strategy_spec.rb +3 -1
- data/spec/lib/secret_storing/base_spec.rb +23 -23
- data/spec/lib/secret_storing/bcrypt_spec.rb +18 -18
- data/spec/lib/secret_storing/plain_spec.rb +17 -17
- data/spec/lib/secret_storing/sha256_hash_spec.rb +16 -16
- data/spec/lib/server_spec.rb +16 -14
- data/spec/lib/stale_records_cleaner_spec.rb +17 -17
- data/spec/models/doorkeeper/access_grant_spec.rb +30 -26
- data/spec/models/doorkeeper/access_token_spec.rb +97 -95
- data/spec/models/doorkeeper/application_spec.rb +98 -57
- data/spec/requests/applications/applications_request_spec.rb +98 -66
- data/spec/requests/applications/authorized_applications_spec.rb +20 -18
- data/spec/requests/endpoints/authorization_spec.rb +25 -23
- data/spec/requests/endpoints/token_spec.rb +38 -36
- data/spec/requests/flows/authorization_code_errors_spec.rb +26 -24
- data/spec/requests/flows/authorization_code_spec.rb +161 -159
- data/spec/requests/flows/client_credentials_spec.rb +53 -51
- data/spec/requests/flows/implicit_grant_errors_spec.rb +10 -8
- data/spec/requests/flows/implicit_grant_spec.rb +27 -25
- data/spec/requests/flows/password_spec.rb +56 -54
- data/spec/requests/flows/refresh_token_spec.rb +45 -43
- data/spec/requests/flows/revoke_token_spec.rb +29 -27
- data/spec/requests/flows/skip_authorization_spec.rb +23 -21
- data/spec/requests/protected_resources/metal_spec.rb +7 -5
- data/spec/requests/protected_resources/private_api_spec.rb +35 -33
- data/spec/routing/custom_controller_routes_spec.rb +67 -65
- data/spec/routing/default_routes_spec.rb +22 -20
- data/spec/routing/scoped_routes_spec.rb +20 -18
- data/spec/spec_helper.rb +14 -13
- data/spec/spec_helper_integration.rb +3 -1
- data/spec/support/dependencies/factory_bot.rb +3 -1
- data/spec/support/doorkeeper_rspec.rb +3 -1
- data/spec/support/helpers/access_token_request_helper.rb +3 -1
- data/spec/support/helpers/authorization_request_helper.rb +4 -2
- data/spec/support/helpers/config_helper.rb +2 -0
- data/spec/support/helpers/model_helper.rb +3 -1
- data/spec/support/helpers/request_spec_helper.rb +5 -3
- data/spec/support/helpers/url_helper.rb +9 -7
- data/spec/support/http_method_shim.rb +4 -9
- data/spec/support/orm/active_record.rb +3 -1
- data/spec/support/shared/controllers_shared_context.rb +18 -16
- data/spec/support/shared/hashing_shared_context.rb +3 -3
- data/spec/support/shared/models_shared_examples.rb +12 -10
- data/spec/validators/redirect_uri_validator_spec.rb +74 -45
- data/spec/version/version_spec.rb +7 -5
- metadata +12 -16
- data/gemfiles/rails_4_2.gemfile +0 -17
- data/spec/dummy/config/initializers/new_framework_defaults.rb +0 -8
- data/spec/support/ruby_2_6_rails_4_2_patch.rb +0 -14
data/spec/lib/doorkeeper_spec.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe "Expirable" do
|
4
6
|
subject do
|
5
7
|
Class.new do
|
6
8
|
include Doorkeeper::Models::Expirable
|
@@ -12,46 +14,46 @@ describe 'Expirable' do
|
|
12
14
|
end
|
13
15
|
|
14
16
|
describe :expired? do
|
15
|
-
it
|
17
|
+
it "is not expired if time has not passed" do
|
16
18
|
allow(subject).to receive(:expires_in).and_return(2.minutes)
|
17
19
|
expect(subject).not_to be_expired
|
18
20
|
end
|
19
21
|
|
20
|
-
it
|
22
|
+
it "is expired if time has passed" do
|
21
23
|
allow(subject).to receive(:expires_in).and_return(10.seconds)
|
22
24
|
expect(subject).to be_expired
|
23
25
|
end
|
24
26
|
|
25
|
-
it
|
27
|
+
it "is not expired if expires_in is not set" do
|
26
28
|
allow(subject).to receive(:expires_in).and_return(nil)
|
27
29
|
expect(subject).not_to be_expired
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
31
33
|
describe :expires_in_seconds do
|
32
|
-
it
|
34
|
+
it "should return the amount of time remaining until the token is expired" do
|
33
35
|
allow(subject).to receive(:expires_in).and_return(2.minutes)
|
34
36
|
expect(subject.expires_in_seconds).to eq(60)
|
35
37
|
end
|
36
38
|
|
37
|
-
it
|
39
|
+
it "should return 0 when expired" do
|
38
40
|
allow(subject).to receive(:expires_in).and_return(30.seconds)
|
39
41
|
expect(subject.expires_in_seconds).to eq(0)
|
40
42
|
end
|
41
43
|
|
42
|
-
it
|
44
|
+
it "should return nil when expires_in is nil" do
|
43
45
|
allow(subject).to receive(:expires_in).and_return(nil)
|
44
46
|
expect(subject.expires_in_seconds).to be_nil
|
45
47
|
end
|
46
48
|
end
|
47
49
|
|
48
50
|
describe :expires_at do
|
49
|
-
it
|
51
|
+
it "should return the expiration time of the token" do
|
50
52
|
allow(subject).to receive(:expires_in).and_return(2.minutes)
|
51
53
|
expect(subject.expires_at).to be_a(Time)
|
52
54
|
end
|
53
55
|
|
54
|
-
it
|
56
|
+
it "should return nil when expires_in is nil" do
|
55
57
|
allow(subject).to receive(:expires_in).and_return(nil)
|
56
58
|
expect(subject.expires_at).to be_nil
|
57
59
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe "Reusable" do
|
6
6
|
subject do
|
7
7
|
Class.new do
|
8
8
|
include Doorkeeper::Models::Reusable
|
@@ -10,13 +10,13 @@ describe 'Reusable' do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
describe :reusable? do
|
13
|
-
it
|
13
|
+
it "is reusable if its expires_in is nil" do
|
14
14
|
allow(subject).to receive(:expired?).and_return(false)
|
15
15
|
allow(subject).to receive(:expires_in).and_return(nil)
|
16
16
|
expect(subject).to be_reusable
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
19
|
+
it "is reusable if its expiry has crossed reusable limit" do
|
20
20
|
allow(subject).to receive(:expired?).and_return(false)
|
21
21
|
allow(Doorkeeper.configuration).to receive(:token_reuse_limit).and_return(90)
|
22
22
|
allow(subject).to receive(:expires_in).and_return(100.seconds)
|
@@ -24,7 +24,7 @@ describe 'Reusable' do
|
|
24
24
|
expect(subject).to be_reusable
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
27
|
+
it "is not reusable if its expiry has crossed reusable limit" do
|
28
28
|
allow(subject).to receive(:expired?).and_return(false)
|
29
29
|
allow(Doorkeeper.configuration).to receive(:token_reuse_limit).and_return(90)
|
30
30
|
allow(subject).to receive(:expires_in).and_return(100.seconds)
|
@@ -32,7 +32,7 @@ describe 'Reusable' do
|
|
32
32
|
expect(subject).not_to be_reusable
|
33
33
|
end
|
34
34
|
|
35
|
-
it
|
35
|
+
it "is not reusable if it is already expired" do
|
36
36
|
allow(subject).to receive(:expired?).and_return(true)
|
37
37
|
expect(subject).not_to be_reusable
|
38
38
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe "Revocable" do
|
4
6
|
subject do
|
5
7
|
Class.new do
|
6
8
|
include Doorkeeper::Models::Revocable
|
@@ -8,7 +10,7 @@ describe 'Revocable' do
|
|
8
10
|
end
|
9
11
|
|
10
12
|
describe :revoke do
|
11
|
-
it
|
13
|
+
it "updates :revoked_at attribute with current time" do
|
12
14
|
utc = double utc: double
|
13
15
|
clock = double now: utc
|
14
16
|
expect(subject).to receive(:update_attribute).with(:revoked_at, clock.now.utc)
|
@@ -17,17 +19,17 @@ describe 'Revocable' do
|
|
17
19
|
end
|
18
20
|
|
19
21
|
describe :revoked? do
|
20
|
-
it
|
22
|
+
it "is revoked if :revoked_at has passed" do
|
21
23
|
allow(subject).to receive(:revoked_at).and_return(Time.now.utc - 1000)
|
22
24
|
expect(subject).to be_revoked
|
23
25
|
end
|
24
26
|
|
25
|
-
it
|
27
|
+
it "is not revoked if :revoked_at has not passed" do
|
26
28
|
allow(subject).to receive(:revoked_at).and_return(Time.now.utc + 1000)
|
27
29
|
expect(subject).not_to be_revoked
|
28
30
|
end
|
29
31
|
|
30
|
-
it
|
32
|
+
it "is not revoked if :revoked_at is not set" do
|
31
33
|
allow(subject).to receive(:revoked_at).and_return(nil)
|
32
34
|
expect(subject).not_to be_revoked
|
33
35
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe "Doorkeeper::Models::Scopes" do
|
4
6
|
subject do
|
5
7
|
Class.new(Struct.new(:scopes)) do
|
6
8
|
include Doorkeeper::Models::Scopes
|
@@ -8,44 +10,44 @@ describe 'Doorkeeper::Models::Scopes' do
|
|
8
10
|
end
|
9
11
|
|
10
12
|
before do
|
11
|
-
subject[:scopes] =
|
13
|
+
subject[:scopes] = "public admin"
|
12
14
|
end
|
13
15
|
|
14
16
|
describe :scopes do
|
15
|
-
it
|
17
|
+
it "is a `Scopes` class" do
|
16
18
|
expect(subject.scopes).to be_a(Doorkeeper::OAuth::Scopes)
|
17
19
|
end
|
18
20
|
|
19
|
-
it
|
20
|
-
expect(subject.scopes).to include(
|
21
|
+
it "includes scopes" do
|
22
|
+
expect(subject.scopes).to include("public")
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
24
26
|
describe :scopes= do
|
25
|
-
it
|
26
|
-
subject.scopes =
|
27
|
-
expect(subject.scopes_string).to eq(
|
27
|
+
it "accepts String" do
|
28
|
+
subject.scopes = "private admin"
|
29
|
+
expect(subject.scopes_string).to eq("private admin")
|
28
30
|
end
|
29
31
|
|
30
|
-
it
|
32
|
+
it "accepts Array" do
|
31
33
|
subject.scopes = %w[private admin]
|
32
|
-
expect(subject.scopes_string).to eq(
|
34
|
+
expect(subject.scopes_string).to eq("private admin")
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
36
38
|
describe :scopes_string do
|
37
|
-
it
|
38
|
-
expect(subject.scopes_string).to eq(
|
39
|
+
it "is a `Scopes` class" do
|
40
|
+
expect(subject.scopes_string).to eq("public admin")
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
42
44
|
describe :includes_scope? do
|
43
|
-
it
|
44
|
-
expect(subject.includes_scope?(
|
45
|
+
it "should return true if at least one scope is included" do
|
46
|
+
expect(subject.includes_scope?("public", "private")).to be true
|
45
47
|
end
|
46
48
|
|
47
|
-
it
|
48
|
-
expect(subject.includes_scope?(
|
49
|
+
it "should return false if no scopes are included" do
|
50
|
+
expect(subject.includes_scope?("teacher", "student")).to be false
|
49
51
|
end
|
50
52
|
end
|
51
53
|
end
|
@@ -1,112 +1,134 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe "SecretStorable" do
|
6
6
|
let(:clazz) do
|
7
7
|
Class.new do
|
8
8
|
include Doorkeeper::Models::SecretStorable
|
9
9
|
|
10
10
|
def self.find_by(*)
|
11
|
-
raise
|
11
|
+
raise "stub this"
|
12
12
|
end
|
13
13
|
|
14
14
|
def update_column(*)
|
15
|
-
raise
|
15
|
+
raise "stub this"
|
16
16
|
end
|
17
17
|
|
18
18
|
def token
|
19
|
-
raise
|
19
|
+
raise "stub this"
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
23
23
|
let(:strategy) { clazz.secret_strategy }
|
24
24
|
|
25
25
|
describe :find_by_plaintext_token do
|
26
|
-
subject { clazz.send(:find_by_plaintext_token,
|
26
|
+
subject { clazz.send(:find_by_plaintext_token, "attr", "input") }
|
27
27
|
|
28
|
-
it
|
28
|
+
it "forwards to the secret_strategy" do
|
29
29
|
expect(strategy)
|
30
30
|
.to receive(:transform_secret)
|
31
|
-
.with(
|
32
|
-
.and_return
|
31
|
+
.with("input")
|
32
|
+
.and_return "found"
|
33
33
|
|
34
34
|
expect(clazz)
|
35
35
|
.to receive(:find_by)
|
36
|
-
.with(
|
37
|
-
.and_return
|
36
|
+
.with("attr" => "found")
|
37
|
+
.and_return "result"
|
38
38
|
|
39
|
-
|
40
|
-
expect(subject).to eq 'result'
|
39
|
+
expect(subject).to eq "result"
|
41
40
|
end
|
42
41
|
|
43
|
-
it
|
42
|
+
it "calls find_by_fallback_token if not found" do
|
44
43
|
expect(clazz)
|
45
44
|
.to receive(:find_by)
|
46
|
-
.with(
|
45
|
+
.with("attr" => "input")
|
47
46
|
.and_return nil
|
48
47
|
|
49
48
|
expect(clazz)
|
50
49
|
.to receive(:find_by_fallback_token)
|
51
|
-
.with(
|
52
|
-
.and_return
|
50
|
+
.with("attr", "input")
|
51
|
+
.and_return "fallback"
|
53
52
|
|
54
|
-
expect(subject).to eq
|
53
|
+
expect(subject).to eq "fallback"
|
55
54
|
end
|
56
55
|
end
|
57
56
|
|
58
57
|
describe :find_by_fallback_token do
|
59
|
-
subject { clazz.send(:find_by_fallback_token,
|
58
|
+
subject { clazz.send(:find_by_fallback_token, "attr", "input") }
|
60
59
|
let(:fallback) { double(::Doorkeeper::SecretStoring::Plain) }
|
61
60
|
|
62
|
-
it
|
61
|
+
it "returns nil if none defined" do
|
63
62
|
expect(clazz.fallback_secret_strategy).to eq nil
|
64
63
|
expect(subject).to eq nil
|
65
64
|
end
|
66
65
|
|
67
|
-
context
|
68
|
-
let(:resource) { double('Token model') }
|
66
|
+
context "if a fallback strategy is defined" do
|
69
67
|
before do
|
70
68
|
allow(clazz).to receive(:fallback_secret_strategy).and_return(fallback)
|
71
69
|
end
|
72
70
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
71
|
+
context "if a resource is defined" do
|
72
|
+
let(:resource) { double("Token model") }
|
73
|
+
|
74
|
+
it "calls the strategy for lookup" do
|
75
|
+
expect(clazz)
|
76
|
+
.to receive(:find_by)
|
77
|
+
.with("attr" => "fallback")
|
78
|
+
.and_return(resource)
|
79
|
+
|
80
|
+
expect(fallback)
|
81
|
+
.to receive(:transform_secret)
|
82
|
+
.with("input")
|
83
|
+
.and_return("fallback")
|
84
|
+
|
85
|
+
# store_secret will call the resource
|
86
|
+
expect(resource)
|
87
|
+
.to receive(:attr=)
|
88
|
+
.with("new value")
|
89
|
+
|
90
|
+
# It will upgrade the secret automtically using the current strategy
|
91
|
+
expect(strategy)
|
92
|
+
.to receive(:transform_secret)
|
93
|
+
.with("input")
|
94
|
+
.and_return("new value")
|
95
|
+
|
96
|
+
expect(resource).to receive(:update).with("attr" => "new value")
|
97
|
+
expect(subject).to eq resource
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context "if a resource is not defined" do
|
102
|
+
before do
|
103
|
+
allow(clazz).to receive(:fallback_secret_strategy).and_return(fallback)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "returns nil" do
|
107
|
+
expect(clazz)
|
108
|
+
.to receive(:find_by)
|
109
|
+
.with("attr" => "fallback")
|
110
|
+
.and_return(nil)
|
111
|
+
|
112
|
+
expect(fallback)
|
113
|
+
.to receive(:transform_secret)
|
114
|
+
.with("input")
|
115
|
+
.and_return("fallback")
|
116
|
+
|
117
|
+
# It does not find a token even with the fallback method
|
118
|
+
expect(subject).to be_nil
|
119
|
+
end
|
97
120
|
end
|
98
121
|
end
|
99
122
|
end
|
100
123
|
|
101
|
-
|
102
124
|
describe :secret_strategy do
|
103
|
-
it
|
125
|
+
it "defaults to plain strategy" do
|
104
126
|
expect(strategy).to eq Doorkeeper::SecretStoring::Plain
|
105
127
|
end
|
106
128
|
end
|
107
129
|
|
108
130
|
describe :fallback_secret_strategy do
|
109
|
-
it
|
131
|
+
it "defaults to nil" do
|
110
132
|
expect(clazz.fallback_secret_strategy).to eq nil
|
111
133
|
end
|
112
134
|
end
|
@@ -1,36 +1,38 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
2
4
|
|
3
5
|
module Doorkeeper::OAuth::Authorization
|
4
6
|
describe URIBuilder do
|
5
7
|
subject { URIBuilder }
|
6
8
|
|
7
9
|
describe :uri_with_query do
|
8
|
-
it
|
9
|
-
uri = subject.uri_with_query
|
10
|
-
expect(uri).to eq(
|
10
|
+
it "returns the uri with query" do
|
11
|
+
uri = subject.uri_with_query "http://example.com/", parameter: "value"
|
12
|
+
expect(uri).to eq("http://example.com/?parameter=value")
|
11
13
|
end
|
12
14
|
|
13
|
-
it
|
14
|
-
uri = subject.uri_with_query
|
15
|
-
expect(uri).to eq(
|
15
|
+
it "rejects nil values" do
|
16
|
+
uri = subject.uri_with_query "http://example.com/", parameter: ""
|
17
|
+
expect(uri).to eq("http://example.com/?")
|
16
18
|
end
|
17
19
|
|
18
|
-
it
|
19
|
-
uri = subject.uri_with_query
|
20
|
+
it "preserves original query parameters" do
|
21
|
+
uri = subject.uri_with_query "http://example.com/?query1=value", parameter: "value"
|
20
22
|
expect(uri).to match(/query1=value/)
|
21
23
|
expect(uri).to match(/parameter=value/)
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
25
27
|
describe :uri_with_fragment do
|
26
|
-
it
|
27
|
-
uri = subject.uri_with_fragment
|
28
|
-
expect(uri).to eq(
|
28
|
+
it "returns uri with parameters as fragments" do
|
29
|
+
uri = subject.uri_with_fragment "http://example.com/", parameter: "value"
|
30
|
+
expect(uri).to eq("http://example.com/#parameter=value")
|
29
31
|
end
|
30
32
|
|
31
|
-
it
|
32
|
-
uri = subject.uri_with_fragment
|
33
|
-
expect(uri).to eq(
|
33
|
+
it "preserves original query parameters" do
|
34
|
+
uri = subject.uri_with_fragment "http://example.com/?query1=value1", parameter: "value"
|
35
|
+
expect(uri).to eq("http://example.com/?query1=value1#parameter=value")
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|