doorkeeper-mongodb 5.2.1 → 5.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/doorkeeper-mongodb.rb +1 -0
- data/lib/doorkeeper-mongodb/mixins/mongoid/access_grant_mixin.rb +1 -0
- data/lib/doorkeeper-mongodb/mixins/mongoid/access_token_mixin.rb +1 -0
- data/lib/doorkeeper-mongodb/mixins/mongoid/application_mixin.rb +76 -0
- 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/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/log/test.log +4220 -4184
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{eS/eSL1QMz46gKLM0GR6S9fL6uyARPxOImcappZ9_ZtSyg.cache → Pm/PmheG0PGFqDws1qgFOxOyIL-gpMof3Ar9eSRKVLYuik.cache} +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/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_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/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/support/helpers/request_spec_helper.rb +1 -13
- data/spec/support/helpers/url_helper.rb +2 -2
- 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 +13 -10
@@ -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
|