doorkeeper-mongodb 5.2.1 → 5.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -27
- data/lib/doorkeeper/orm/concerns/mongoid/ownership.rb +1 -1
- data/lib/doorkeeper/orm/concerns/mongoid/resource_ownerable.rb +1 -1
- data/lib/doorkeeper/orm/mongoid4.rb +18 -0
- data/lib/doorkeeper/orm/mongoid5.rb +18 -0
- data/lib/doorkeeper/orm/mongoid6.rb +18 -0
- data/lib/doorkeeper/orm/mongoid7.rb +18 -0
- data/lib/doorkeeper-mongodb/mixins/mongoid/access_grant_mixin.rb +7 -6
- data/lib/doorkeeper-mongodb/mixins/mongoid/access_token_mixin.rb +8 -5
- data/lib/doorkeeper-mongodb/mixins/mongoid/application_mixin.rb +82 -5
- data/lib/doorkeeper-mongodb/mixins/mongoid/base_mixin.rb +0 -8
- data/lib/doorkeeper-mongodb/mixins/mongoid/json_serializable.rb +17 -0
- data/lib/doorkeeper-mongodb/version.rb +1 -1
- data/lib/doorkeeper-mongodb.rb +1 -0
- data/spec/controllers/application_metal_controller_spec.rb +4 -4
- data/spec/controllers/applications_controller_spec.rb +198 -202
- data/spec/controllers/authorizations_controller_spec.rb +32 -31
- data/spec/controllers/protected_resources_controller_spec.rb +10 -10
- data/spec/controllers/token_info_controller_spec.rb +1 -1
- data/spec/controllers/tokens_controller_spec.rb +105 -62
- data/spec/doorkeeper/redirect_uri_validator_spec.rb +183 -0
- data/spec/{lib → doorkeeper}/server_spec.rb +5 -4
- data/spec/{lib → doorkeeper}/stale_records_cleaner_spec.rb +8 -7
- data/spec/{version → doorkeeper}/version_spec.rb +3 -3
- data/spec/dummy/app/assets/config/manifest.js +0 -0
- data/spec/dummy/app/controllers/application_controller.rb +0 -0
- data/spec/dummy/app/controllers/custom_authorizations_controller.rb +0 -0
- data/spec/dummy/app/controllers/full_protected_resources_controller.rb +0 -0
- data/spec/dummy/app/controllers/home_controller.rb +0 -0
- data/spec/dummy/app/controllers/metal_controller.rb +0 -0
- data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +0 -0
- data/spec/dummy/app/models/user.rb +0 -1
- data/spec/dummy/app/views/home/index.html.erb +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +0 -0
- data/spec/dummy/config/application.rb +0 -0
- data/spec/dummy/config/boot.rb +0 -0
- data/spec/dummy/config/database.yml +0 -0
- data/spec/dummy/config/environment.rb +0 -0
- data/spec/dummy/config/environments/development.rb +0 -0
- data/spec/dummy/config/environments/production.rb +0 -0
- data/spec/dummy/config/environments/test.rb +0 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -0
- data/spec/dummy/config/initializers/doorkeeper.rb +0 -0
- data/spec/dummy/config/initializers/secret_token.rb +0 -0
- data/spec/dummy/config/initializers/session_store.rb +0 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -0
- data/spec/dummy/config/locales/doorkeeper.en.yml +0 -0
- data/spec/dummy/config/mongo.yml +2 -2
- data/spec/dummy/config/routes.rb +0 -0
- data/spec/dummy/config.ru +0 -0
- data/spec/dummy/db/migrate/20111122132257_create_users.rb +0 -0
- data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +0 -0
- data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +0 -0
- data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +0 -0
- data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +0 -0
- data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +0 -0
- data/spec/dummy/db/migrate/20180210183654_add_confidential_to_applications.rb +0 -0
- data/spec/dummy/db/schema.rb +0 -0
- data/spec/dummy/public/404.html +0 -0
- data/spec/dummy/public/422.html +0 -0
- data/spec/dummy/public/500.html +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/-o/-ofn45zIfO5vx4VD6m6NXesLf6da5usA-Sbw2SVju3o.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/0_/0_ouGcG_o_1zmVmBe-tdQYk594LBwVa1bumjrKtdfEw.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/2X/2XMMcHbyTSRqh1GkV0xzyIETNtt-zgN6iniziShaKmQ.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/4Q/4QQw-pMQ98JIj3xdcFhGBQdysdGPY9rWffRqWMmyjew.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/7H/7HjRsym0tTpXFCVhWt6kteMs_-CozKVbr9s5syHm8es.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/8B/8BxJyv22HPFHu1se_l2J8qW1N9NzZ16UOWOy1YMSgs4.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/8D/8DJG7JfPvShfLLyeSom6NZ_TcQc6QH27tJ7prEWZPfI.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/9x/9xjtGv-yKjj62x9uFwBZg8pTSh9ERPAgANwNo9uwIaA.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Bt/BtXO7f0PZ8DNt3TMLYM-zY7LkbWa_KgyB0v1V98M1CQ.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/E0/E02f1Q2tutWumMulGCFNfqQNjvEP_hMAK_5E83eWepI.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/EZ/EZGpd6pUEJZxO6uT2yIS4Fpn5KX7VDgC9VB3AaemF5Q.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/FJ/FJlQpfMtpRbrM5P8A7d2FAelFKwo6GrVs2xks8z5GKU.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/L8/L8mOWakJlWKr6MU85rj0V7yGFfNyIR6vE6YXtqArPGw.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Lk/LklIq5hrBAPESXVUpFMwQ9L-1qTj90sPVi6U19_Xi-Q.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/MB/MBWRxa9S470ee8suxVKp0jYgv6K6FQOqKGV0kPGQNMs.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Ma/MaK3K1AoZZ4xM5fOOifhROd73hfZJpP4yGbkGdoYtEk.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/PA/PAH_jI20wRw12tngeJ-V619c30avNLDu5U9Z-9Pc5SQ.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Ph/Ph7RtH_NvG2I8XpTa8mA8SBQXZDzBPVIh4CH6g7OXJ0.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{eS/eSL1QMz46gKLM0GR6S9fL6uyARPxOImcappZ9_ZtSyg.cache → Pm/PmheG0PGFqDws1qgFOxOyIL-gpMof3Ar9eSRKVLYuik.cache} +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Pn/PnXU_mkG2fLZFm9BwiZ03BZdBTjKuInP-cRXjHS7yJo.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Qs/QsVgO6vM5Yn9oeYTYlrqtyVnK6sdVDWDa083N7zpfHw.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/So/So59ksdx2dw-_A3-zFZ6Palr7fROjm7_0JDZb04temw.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Wt/WtXL_iDofLeTH_v0Yf3PM421r9b1V0g-VBvMPeu9KA0.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/b6/b6QRH6ZdCc0e6bUWu4qni_kZmptaMgWciO8Jl9q6_p8.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/dX/dX6FDdUIy8yBCOoaoXcjf71rX9N_bpiXGJ4Urt32NTk.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/jC/jCTZ1jAldKBn4OTANBBmCKzxLrDgok1ur4meoTqlDNg.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/qT/qTQIQsmS0Wbbg2JxNn9rxdI5qVOTg5SfyQdaTvr9vLo.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/yN/yNOFGOsnHmxXNMkuEAWuL1u3jlmdvrdeoTx6DDJ1in8.cache +0 -0
- data/spec/factories.rb +0 -0
- data/spec/grape/grape_integration_spec.rb +1 -1
- data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +1 -1
- data/spec/lib/config_spec.rb +23 -12
- data/spec/lib/doorkeeper_spec.rb +4 -4
- data/spec/lib/models/expirable_spec.rb +9 -9
- data/spec/lib/models/reusable_spec.rb +2 -2
- data/spec/lib/models/revocable_spec.rb +4 -7
- data/spec/lib/models/scopes_spec.rb +7 -7
- data/spec/lib/models/secret_storable_spec.rb +9 -8
- data/spec/lib/oauth/authorization/uri_builder_spec.rb +23 -27
- data/spec/lib/oauth/authorization_code_request_spec.rb +6 -6
- data/spec/lib/oauth/base_request_spec.rb +11 -27
- data/spec/lib/oauth/base_response_spec.rb +2 -2
- data/spec/lib/oauth/client/credentials_spec.rb +25 -25
- data/spec/lib/oauth/client_credentials/creator_spec.rb +89 -91
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +84 -86
- data/spec/lib/oauth/client_credentials/validation_spec.rb +72 -39
- data/spec/lib/oauth/client_credentials_integration_spec.rb +5 -5
- data/spec/lib/oauth/client_credentials_request_spec.rb +7 -10
- data/spec/lib/oauth/client_spec.rb +8 -8
- data/spec/lib/oauth/code_request_spec.rb +5 -5
- data/spec/lib/oauth/code_response_spec.rb +4 -4
- data/spec/lib/oauth/error_response_spec.rb +6 -5
- data/spec/lib/oauth/error_spec.rb +1 -1
- data/spec/lib/oauth/forbidden_token_response_spec.rb +2 -2
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +37 -37
- data/spec/lib/oauth/helpers/unique_token_spec.rb +2 -2
- data/spec/lib/oauth/helpers/uri_checker_spec.rb +54 -54
- data/spec/lib/oauth/invalid_request_response_spec.rb +6 -6
- data/spec/lib/oauth/invalid_token_response_spec.rb +4 -4
- data/spec/lib/oauth/password_access_token_request_spec.rb +10 -9
- data/spec/lib/oauth/pre_authorization_spec.rb +20 -8
- data/spec/lib/oauth/refresh_token_request_spec.rb +10 -10
- data/spec/lib/oauth/scopes_spec.rb +14 -14
- data/spec/lib/oauth/token_request_spec.rb +9 -9
- data/spec/lib/oauth/token_response_spec.rb +5 -5
- data/spec/lib/oauth/token_spec.rb +5 -5
- data/spec/lib/option_spec.rb +1 -1
- data/spec/lib/request/strategy_spec.rb +34 -37
- data/spec/lib/secret_storing/base_spec.rb +3 -2
- data/spec/lib/secret_storing/bcrypt_spec.rb +2 -1
- data/spec/lib/secret_storing/plain_spec.rb +2 -1
- data/spec/lib/secret_storing/sha256_hash_spec.rb +2 -1
- data/spec/models/doorkeeper/access_grant_spec.rb +7 -9
- data/spec/models/doorkeeper/access_token_spec.rb +20 -26
- data/spec/models/doorkeeper/application_spec.rb +83 -26
- data/spec/requests/applications/applications_request_spec.rb +91 -93
- data/spec/requests/applications/authorized_applications_spec.rb +0 -0
- data/spec/requests/endpoints/authorization_spec.rb +1 -1
- data/spec/requests/endpoints/token_spec.rb +22 -16
- data/spec/requests/flows/authorization_code_errors_spec.rb +12 -8
- data/spec/requests/flows/authorization_code_spec.rb +108 -79
- data/spec/requests/flows/client_credentials_spec.rb +57 -45
- data/spec/requests/flows/implicit_grant_errors_spec.rb +0 -0
- data/spec/requests/flows/implicit_grant_spec.rb +4 -4
- data/spec/requests/flows/password_spec.rb +253 -213
- data/spec/requests/flows/refresh_token_spec.rb +53 -39
- data/spec/requests/flows/revoke_token_spec.rb +24 -24
- data/spec/requests/flows/skip_authorization_spec.rb +1 -1
- data/spec/requests/protected_resources/metal_spec.rb +2 -2
- data/spec/requests/protected_resources/private_api_spec.rb +0 -0
- data/spec/routing/custom_controller_routes_spec.rb +1 -1
- data/spec/routing/default_routes_spec.rb +1 -1
- data/spec/routing/scoped_routes_spec.rb +1 -1
- data/spec/spec_helper.rb +0 -0
- data/spec/spec_helper_integration.rb +0 -0
- data/spec/support/dependencies/factory_bot.rb +0 -0
- data/spec/support/doorkeeper_rspec.rb +0 -0
- data/spec/support/helpers/access_token_request_helper.rb +0 -0
- data/spec/support/helpers/authorization_request_helper.rb +0 -0
- data/spec/support/helpers/config_helper.rb +0 -0
- data/spec/support/helpers/model_helper.rb +0 -0
- data/spec/support/helpers/request_spec_helper.rb +1 -13
- data/spec/support/helpers/url_helper.rb +2 -2
- data/spec/support/orm/active_record.rb +0 -0
- data/spec/support/orm/mongoid4.rb +1 -1
- data/spec/support/orm/mongoid5.rb +1 -1
- data/spec/support/orm/mongoid6.rb +1 -1
- data/spec/support/orm/mongoid7.rb +1 -1
- data/spec/support/shared/controllers_shared_context.rb +5 -38
- data/spec/support/shared/hashing_shared_context.rb +4 -0
- data/spec/support/shared/models_shared_examples.rb +6 -6
- metadata +154 -167
- data/spec/dummy/log/test.log +0 -6108
@@ -2,110 +2,108 @@
|
|
2
2
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
RSpec.describe Doorkeeper::OAuth::ClientCredentials::Issuer do
|
6
|
+
subject { described_class.new(server, validator) }
|
7
|
+
|
8
|
+
let(:creator) { double :access_token_creator }
|
9
|
+
let(:server) do
|
10
|
+
double(
|
11
|
+
:server,
|
12
|
+
access_token_expires_in: 100,
|
13
|
+
)
|
14
|
+
end
|
15
|
+
let(:validator) { double :validator, valid?: true }
|
16
|
+
|
17
|
+
before do
|
18
|
+
allow(server).to receive(:option_defined?).with(:custom_access_token_expires_in).and_return(false)
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#create" do
|
22
|
+
let(:client) { double :client, id: "some-id" }
|
23
|
+
let(:scopes) { "some scope" }
|
24
|
+
|
25
|
+
it "creates and sets the token" do
|
26
|
+
expect(creator).to receive(:call).and_return("token")
|
27
|
+
subject.create client, scopes, creator
|
28
|
+
|
29
|
+
expect(subject.token).to eq("token")
|
13
30
|
end
|
14
|
-
let(:validator) { double :validator, valid?: true }
|
15
31
|
|
16
|
-
|
17
|
-
|
32
|
+
it "creates with correct token parameters" do
|
33
|
+
expect(creator).to receive(:call).with(
|
34
|
+
client,
|
35
|
+
scopes,
|
36
|
+
expires_in: 100,
|
37
|
+
use_refresh_token: false,
|
38
|
+
)
|
39
|
+
|
40
|
+
subject.create client, scopes, creator
|
18
41
|
end
|
19
42
|
|
20
|
-
|
43
|
+
it "has error set to :server_error if creator fails" do
|
44
|
+
expect(creator).to receive(:call).and_return(false)
|
45
|
+
subject.create client, scopes, creator
|
46
|
+
|
47
|
+
expect(subject.error).to eq(:server_error)
|
48
|
+
end
|
21
49
|
|
22
|
-
|
23
|
-
|
24
|
-
|
50
|
+
context "when validator fails" do
|
51
|
+
before do
|
52
|
+
allow(validator).to receive(:valid?).and_return(false)
|
53
|
+
allow(validator).to receive(:error).and_return(:validation_error)
|
54
|
+
end
|
25
55
|
|
26
|
-
it "
|
27
|
-
expect(creator).
|
56
|
+
it "has error set from validator" do
|
57
|
+
expect(creator).not_to receive(:create)
|
28
58
|
subject.create client, scopes, creator
|
59
|
+
expect(subject.error).to eq(:validation_error)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "returns false" do
|
63
|
+
expect(subject.create(client, scopes, creator)).to be_falsey
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "with custom expiration" do
|
68
|
+
let(:custom_ttl_grant) { 1234 }
|
69
|
+
let(:custom_ttl_scope) { 1235 }
|
70
|
+
let(:custom_scope) { "special" }
|
71
|
+
let(:server) do
|
72
|
+
double(
|
73
|
+
:server,
|
74
|
+
custom_access_token_expires_in: lambda { |context|
|
75
|
+
# scopes is normally an object but is a string in this test
|
76
|
+
if context.scopes == custom_scope
|
77
|
+
custom_ttl_scope
|
78
|
+
elsif context.grant_type == Doorkeeper::OAuth::CLIENT_CREDENTIALS
|
79
|
+
custom_ttl_grant
|
80
|
+
end
|
81
|
+
},
|
82
|
+
)
|
83
|
+
end
|
29
84
|
|
30
|
-
|
85
|
+
before do
|
86
|
+
allow(server).to receive(:option_defined?).with(:custom_access_token_expires_in).and_return(true)
|
31
87
|
end
|
32
88
|
|
33
|
-
it "
|
89
|
+
it "respects grant based rules" do
|
34
90
|
expect(creator).to receive(:call).with(
|
35
91
|
client,
|
36
92
|
scopes,
|
37
|
-
expires_in:
|
93
|
+
expires_in: custom_ttl_grant,
|
38
94
|
use_refresh_token: false,
|
39
95
|
)
|
40
|
-
|
41
96
|
subject.create client, scopes, creator
|
42
97
|
end
|
43
98
|
|
44
|
-
it "
|
45
|
-
expect(creator).to receive(:call).
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
before do
|
53
|
-
allow(validator).to receive(:valid?).and_return(false)
|
54
|
-
allow(validator).to receive(:error).and_return(:validation_error)
|
55
|
-
expect(creator).not_to receive(:create)
|
56
|
-
end
|
57
|
-
|
58
|
-
it "has error set from validator" 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 expiration" 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
|
99
|
+
it "respects scope based rules" do
|
100
|
+
expect(creator).to receive(:call).with(
|
101
|
+
client,
|
102
|
+
custom_scope,
|
103
|
+
expires_in: custom_ttl_scope,
|
104
|
+
use_refresh_token: false,
|
105
|
+
)
|
106
|
+
subject.create client, custom_scope, creator
|
109
107
|
end
|
110
108
|
end
|
111
109
|
end
|
@@ -2,58 +2,91 @@
|
|
2
2
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
|
-
|
6
|
-
|
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 }
|
5
|
+
RSpec.describe Doorkeeper::OAuth::ClientCredentials::Validator do
|
6
|
+
subject { described_class.new(server, request) }
|
11
7
|
|
12
|
-
|
8
|
+
let(:server) { double :server, scopes: nil }
|
9
|
+
let(:application) { double scopes: nil }
|
10
|
+
let(:client) { double application: application }
|
11
|
+
let(:request) { double :request, client: client, scopes: nil }
|
13
12
|
|
14
|
-
|
15
|
-
|
13
|
+
it "is valid with valid request" do
|
14
|
+
expect(subject).to be_valid
|
15
|
+
end
|
16
|
+
|
17
|
+
it "is invalid when client is not present" do
|
18
|
+
allow(request).to receive(:client).and_return(nil)
|
19
|
+
expect(subject).not_to be_valid
|
20
|
+
end
|
21
|
+
|
22
|
+
context "when a grant flow check is configured" do
|
23
|
+
let(:callback) { double("callback") }
|
24
|
+
|
25
|
+
before do
|
26
|
+
allow(Doorkeeper.config).to receive(:option_defined?).with(:allow_grant_flow_for_client).and_return(true)
|
27
|
+
allow(Doorkeeper.config).to receive(:allow_grant_flow_for_client).and_return(callback)
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when the callback rejects the grant flow" do
|
31
|
+
let(:callback_response) { false }
|
32
|
+
|
33
|
+
it "is invalid" do
|
34
|
+
expect(callback).to receive(:call).twice.with(
|
35
|
+
Doorkeeper::OAuth::CLIENT_CREDENTIALS,
|
36
|
+
application,
|
37
|
+
).and_return(callback_response)
|
38
|
+
|
39
|
+
expect(subject).not_to be_valid
|
40
|
+
end
|
16
41
|
end
|
17
42
|
|
18
|
-
|
19
|
-
|
43
|
+
context "when the callback allows the grant flow" do
|
44
|
+
let(:callback_response) { true }
|
45
|
+
|
46
|
+
it "is invalid" do
|
47
|
+
expect(callback).to receive(:call).twice.with(
|
48
|
+
Doorkeeper::OAuth::CLIENT_CREDENTIALS,
|
49
|
+
application,
|
50
|
+
).and_return(callback_response)
|
51
|
+
|
52
|
+
expect(subject).to be_valid
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "with scopes" do
|
58
|
+
it "is invalid when scopes are not included in the server" do
|
59
|
+
server_scopes = Doorkeeper::OAuth::Scopes.from_string "email"
|
60
|
+
allow(request).to receive(:grant_type).and_return(Doorkeeper::OAuth::CLIENT_CREDENTIALS)
|
61
|
+
allow(server).to receive(:scopes).and_return(server_scopes)
|
62
|
+
allow(request).to receive(:scopes).and_return(
|
63
|
+
Doorkeeper::OAuth::Scopes.from_string("invalid"),
|
64
|
+
)
|
20
65
|
expect(subject).not_to be_valid
|
21
66
|
end
|
22
67
|
|
23
|
-
context "with scopes" do
|
24
|
-
it "is
|
25
|
-
|
68
|
+
context "with application scopes" do
|
69
|
+
it "is valid when scopes are included in the application" do
|
70
|
+
application_scopes = Doorkeeper::OAuth::Scopes.from_string "app"
|
71
|
+
server_scopes = Doorkeeper::OAuth::Scopes.from_string "email app"
|
72
|
+
allow(application).to receive(:scopes).and_return(application_scopes)
|
73
|
+
allow(server).to receive(:scopes).and_return(server_scopes)
|
74
|
+
allow(request).to receive(:grant_type).and_return(Doorkeeper::OAuth::CLIENT_CREDENTIALS)
|
75
|
+
allow(request).to receive(:scopes).and_return(application_scopes)
|
76
|
+
expect(subject).to be_valid
|
77
|
+
end
|
78
|
+
|
79
|
+
it "is invalid when scopes are not included in the application" do
|
80
|
+
application_scopes = Doorkeeper::OAuth::Scopes.from_string "app"
|
81
|
+
server_scopes = Doorkeeper::OAuth::Scopes.from_string "email app"
|
82
|
+
allow(application).to receive(:scopes).and_return(application_scopes)
|
26
83
|
allow(request).to receive(:grant_type).and_return(Doorkeeper::OAuth::CLIENT_CREDENTIALS)
|
27
84
|
allow(server).to receive(:scopes).and_return(server_scopes)
|
28
85
|
allow(request).to receive(:scopes).and_return(
|
29
|
-
Doorkeeper::OAuth::Scopes.from_string("
|
86
|
+
Doorkeeper::OAuth::Scopes.from_string("email"),
|
30
87
|
)
|
31
88
|
expect(subject).not_to be_valid
|
32
89
|
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
90
|
end
|
58
91
|
end
|
59
92
|
end
|
@@ -2,14 +2,14 @@
|
|
2
2
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
|
-
describe Doorkeeper::OAuth::ClientCredentialsRequest do
|
5
|
+
RSpec.describe Doorkeeper::OAuth::ClientCredentialsRequest do
|
6
6
|
let(:server) { Doorkeeper.configuration }
|
7
7
|
|
8
8
|
context "with a valid request" do
|
9
|
-
let(:client) { FactoryBot.
|
9
|
+
let(:client) { Doorkeeper::OAuth::Client.new(FactoryBot.build_stubbed(:application)) }
|
10
10
|
|
11
11
|
it "issues an access token" do
|
12
|
-
request =
|
12
|
+
request = described_class.new(server, client, {})
|
13
13
|
expect do
|
14
14
|
request.authorize
|
15
15
|
end.to change { Doorkeeper::AccessToken.count }.by(1)
|
@@ -18,10 +18,10 @@ describe Doorkeeper::OAuth::ClientCredentialsRequest do
|
|
18
18
|
|
19
19
|
describe "with an invalid request" do
|
20
20
|
it "does not issue an access token" do
|
21
|
-
request =
|
21
|
+
request = described_class.new(server, nil, {})
|
22
22
|
expect do
|
23
23
|
request.authorize
|
24
|
-
end.
|
24
|
+
end.not_to(change { Doorkeeper::AccessToken.count })
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -2,7 +2,9 @@
|
|
2
2
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
|
-
describe Doorkeeper::OAuth::ClientCredentialsRequest do
|
5
|
+
RSpec.describe Doorkeeper::OAuth::ClientCredentialsRequest do
|
6
|
+
subject { described_class.new(server, client) }
|
7
|
+
|
6
8
|
let(:server) do
|
7
9
|
double(
|
8
10
|
default_scopes: nil,
|
@@ -17,11 +19,6 @@ describe Doorkeeper::OAuth::ClientCredentialsRequest do
|
|
17
19
|
|
18
20
|
before do
|
19
21
|
allow(server).to receive(:option_defined?).with(:custom_access_token_expires_in).and_return(true)
|
20
|
-
end
|
21
|
-
|
22
|
-
subject { Doorkeeper::OAuth::ClientCredentialsRequest.new(server, client) }
|
23
|
-
|
24
|
-
before do
|
25
22
|
allow(subject).to receive(:issuer).and_return(token_creator)
|
26
23
|
end
|
27
24
|
|
@@ -35,7 +32,7 @@ describe Doorkeeper::OAuth::ClientCredentialsRequest do
|
|
35
32
|
expect(subject.response).to be_a(Doorkeeper::OAuth::TokenResponse)
|
36
33
|
end
|
37
34
|
|
38
|
-
context "
|
35
|
+
context "when issue was not created" do
|
39
36
|
before do
|
40
37
|
issuer = double create: false, error: :invalid
|
41
38
|
allow(subject).to receive(:issuer).and_return(issuer)
|
@@ -65,7 +62,7 @@ describe Doorkeeper::OAuth::ClientCredentialsRequest do
|
|
65
62
|
end
|
66
63
|
|
67
64
|
it "issues an access token with requested scopes" do
|
68
|
-
subject =
|
65
|
+
subject = described_class.new(server, client, scope: "email")
|
69
66
|
allow(subject).to receive(:issuer).and_return(token_creator)
|
70
67
|
expect(token_creator).to receive(:create).with(client, Doorkeeper::OAuth::Scopes.from_string("email"))
|
71
68
|
subject.authorize
|
@@ -92,14 +89,14 @@ describe Doorkeeper::OAuth::ClientCredentialsRequest do
|
|
92
89
|
end
|
93
90
|
|
94
91
|
it "delegates the error to issuer if no scope was requested" do
|
95
|
-
subject =
|
92
|
+
subject = described_class.new(server, client)
|
96
93
|
subject.authorize
|
97
94
|
expect(subject.response).to be_a(Doorkeeper::OAuth::ErrorResponse)
|
98
95
|
expect(subject.error).to eq(:invalid_scope)
|
99
96
|
end
|
100
97
|
|
101
98
|
it "issues an access token with requested scopes" do
|
102
|
-
subject =
|
99
|
+
subject = described_class.new(server, client, scope: "phone")
|
103
100
|
subject.authorize
|
104
101
|
expect(subject.response).to be_a(Doorkeeper::OAuth::TokenResponse)
|
105
102
|
expect(subject.response.token.scopes_string).to eq("phone")
|
@@ -2,20 +2,20 @@
|
|
2
2
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
|
-
describe Doorkeeper::OAuth::Client do
|
6
|
-
describe
|
5
|
+
RSpec.describe Doorkeeper::OAuth::Client do
|
6
|
+
describe ".find" do
|
7
7
|
let(:method) { double }
|
8
8
|
|
9
9
|
it "finds the client via uid" do
|
10
10
|
client = double
|
11
11
|
expect(method).to receive(:call).with("uid").and_return(client)
|
12
|
-
expect(
|
13
|
-
.to be_a(
|
12
|
+
expect(described_class.find("uid", method))
|
13
|
+
.to be_a(described_class)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "returns nil if client was not found" do
|
17
17
|
expect(method).to receive(:call).with("uid").and_return(nil)
|
18
|
-
expect(
|
18
|
+
expect(described_class.find("uid", method)).to be_nil
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -24,15 +24,15 @@ describe Doorkeeper::OAuth::Client do
|
|
24
24
|
credentials = Doorkeeper::OAuth::Client::Credentials.new("some-uid", "some-secret")
|
25
25
|
authenticator = double
|
26
26
|
expect(authenticator).to receive(:call).with("some-uid", "some-secret").and_return(double)
|
27
|
-
expect(
|
28
|
-
.to be_a(
|
27
|
+
expect(described_class.authenticate(credentials, authenticator))
|
28
|
+
.to be_a(described_class)
|
29
29
|
end
|
30
30
|
|
31
31
|
it "returns nil if client was not authenticated" do
|
32
32
|
credentials = Doorkeeper::OAuth::Client::Credentials.new("some-uid", "some-secret")
|
33
33
|
authenticator = double
|
34
34
|
expect(authenticator).to receive(:call).with("some-uid", "some-secret").and_return(nil)
|
35
|
-
expect(
|
35
|
+
expect(described_class.authenticate(credentials, authenticator)).to be_nil
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -2,7 +2,11 @@
|
|
2
2
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
|
-
describe Doorkeeper::OAuth::CodeRequest do
|
5
|
+
RSpec.describe Doorkeeper::OAuth::CodeRequest do
|
6
|
+
subject do
|
7
|
+
described_class.new(pre_auth, owner)
|
8
|
+
end
|
9
|
+
|
6
10
|
let(:pre_auth) do
|
7
11
|
server = Doorkeeper.configuration
|
8
12
|
allow(server)
|
@@ -26,10 +30,6 @@ describe Doorkeeper::OAuth::CodeRequest do
|
|
26
30
|
|
27
31
|
let(:owner) { FactoryBot.create(:resource_owner) }
|
28
32
|
|
29
|
-
subject do
|
30
|
-
described_class.new(pre_auth, owner)
|
31
|
-
end
|
32
|
-
|
33
33
|
context "when pre_auth is authorized" do
|
34
34
|
it "creates an access grant and returns a code response" do
|
35
35
|
expect { subject.authorize }.to change { Doorkeeper::AccessGrant.count }.by(1)
|
@@ -2,9 +2,11 @@
|
|
2
2
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
|
-
describe Doorkeeper::OAuth::CodeResponse do
|
5
|
+
RSpec.describe Doorkeeper::OAuth::CodeResponse do
|
6
6
|
describe "#redirect_uri" do
|
7
7
|
context "when generating the redirect URI for an implicit grant" do
|
8
|
+
subject { described_class.new(pre_auth, auth, response_on_fragment: true).redirect_uri }
|
9
|
+
|
8
10
|
let :pre_auth do
|
9
11
|
double(
|
10
12
|
:pre_auth,
|
@@ -21,13 +23,11 @@ describe Doorkeeper::OAuth::CodeResponse do
|
|
21
23
|
|
22
24
|
let :auth do
|
23
25
|
Doorkeeper::OAuth::Authorization::Token.new(pre_auth, owner).tap do |c|
|
24
|
-
c.issue_token
|
26
|
+
c.issue_token!
|
25
27
|
allow(c.token).to receive(:expires_in_seconds).and_return(3600)
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
29
|
-
subject { described_class.new(pre_auth, auth, response_on_fragment: true).redirect_uri }
|
30
|
-
|
31
31
|
it "includes the remaining TTL of the token relative to the time the token was generated" do
|
32
32
|
expect(subject).to include("expires_in=3600")
|
33
33
|
end
|
@@ -2,13 +2,13 @@
|
|
2
2
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
|
-
describe Doorkeeper::OAuth::ErrorResponse do
|
5
|
+
RSpec.describe Doorkeeper::OAuth::ErrorResponse do
|
6
6
|
describe "#status" do
|
7
|
-
it "
|
7
|
+
it "has a status of bad_request" do
|
8
8
|
expect(subject.status).to eq(:bad_request)
|
9
9
|
end
|
10
10
|
|
11
|
-
it "
|
11
|
+
it "has a status of unauthorized for an invalid_client error" do
|
12
12
|
subject = described_class.new(name: :invalid_client)
|
13
13
|
|
14
14
|
expect(subject.status).to eq(:unauthorized)
|
@@ -48,15 +48,16 @@ describe Doorkeeper::OAuth::ErrorResponse do
|
|
48
48
|
end
|
49
49
|
|
50
50
|
describe ".headers" do
|
51
|
-
let(:error_response) { described_class.new(name: :some_error, state: :some_state) }
|
52
51
|
subject { error_response.headers }
|
53
52
|
|
53
|
+
let(:error_response) { described_class.new(name: :some_error, state: :some_state) }
|
54
|
+
|
54
55
|
it { expect(subject).to include "WWW-Authenticate" }
|
55
56
|
|
56
57
|
describe "WWW-Authenticate header" do
|
57
58
|
subject { error_response.headers["WWW-Authenticate"] }
|
58
59
|
|
59
|
-
it { expect(subject).to include("realm=\"#{error_response.realm}\"") }
|
60
|
+
it { expect(subject).to include("realm=\"#{error_response.send(:realm)}\"") }
|
60
61
|
it { expect(subject).to include("error=\"#{error_response.name}\"") }
|
61
62
|
it { expect(subject).to include("error_description=\"#{error_response.description}\"") }
|
62
63
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
|
-
describe Doorkeeper::OAuth::ForbiddenTokenResponse do
|
5
|
+
RSpec.describe Doorkeeper::OAuth::ForbiddenTokenResponse do
|
6
6
|
describe "#name" do
|
7
7
|
it { expect(subject.name).to eq(:invalid_scope) }
|
8
8
|
end
|
@@ -12,7 +12,7 @@ describe Doorkeeper::OAuth::ForbiddenTokenResponse do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
describe ".from_scopes" do
|
15
|
-
it "
|
15
|
+
it "have a list of acceptable scopes" do
|
16
16
|
response = described_class.from_scopes(["public"])
|
17
17
|
expect(response.description).to include("public")
|
18
18
|
end
|