doorkeeper 1.0.0.rc2 → 1.0.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/CHANGELOG.md +2 -1
- data/lib/doorkeeper/version.rb +1 -1
- data/spec/controllers/applications_controller_spec.rb +4 -4
- data/spec/controllers/authorizations_controller_spec.rb +9 -9
- data/spec/controllers/protected_resources_controller_spec.rb +10 -10
- data/spec/controllers/token_info_controller_spec.rb +4 -4
- data/spec/controllers/tokens_controller_spec.rb +4 -4
- data/spec/lib/config_spec.rb +21 -21
- data/spec/lib/models/expirable_spec.rb +13 -13
- data/spec/lib/models/revocable_spec.rb +5 -5
- data/spec/lib/models/scopes_spec.rb +3 -3
- data/spec/lib/oauth/authorization/uri_builder_spec.rb +5 -5
- data/spec/lib/oauth/authorization_code_request_spec.rb +7 -7
- data/spec/lib/oauth/client/credentials_spec.rb +8 -8
- data/spec/lib/oauth/client/methods_spec.rb +8 -8
- data/spec/lib/oauth/client_credentials/creator_spec.rb +2 -2
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +10 -9
- data/spec/lib/oauth/client_credentials/validation_spec.rb +6 -6
- data/spec/lib/oauth/client_credentials_request_spec.rb +7 -7
- data/spec/lib/oauth/client_spec.rb +8 -8
- data/spec/lib/oauth/code_request_spec.rb +4 -4
- data/spec/lib/oauth/error_response_spec.rb +22 -15
- data/spec/lib/oauth/error_spec.rb +1 -1
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +13 -13
- data/spec/lib/oauth/helpers/unique_token_spec.rb +2 -2
- data/spec/lib/oauth/helpers/uri_checker_spec.rb +13 -13
- data/spec/lib/oauth/invalid_token_response_spec.rb +9 -4
- data/spec/lib/oauth/password_access_token_request_spec.rb +7 -7
- data/spec/lib/oauth/pre_authorization_spec.rb +14 -14
- data/spec/lib/oauth/refresh_token_request_spec.rb +8 -8
- data/spec/lib/oauth/scopes_spec.rb +27 -19
- data/spec/lib/oauth/token_request_spec.rb +4 -4
- data/spec/lib/oauth/token_response_spec.rb +11 -11
- data/spec/lib/oauth/token_spec.rb +9 -9
- data/spec/lib/server_spec.rb +1 -1
- data/spec/models/doorkeeper/access_token_spec.rb +15 -15
- data/spec/models/doorkeeper/application_spec.rb +21 -21
- data/spec/requests/flows/authorization_code_spec.rb +1 -1
- data/spec/requests/flows/client_credentials_spec.rb +1 -1
- data/spec/requests/flows/refresh_token_spec.rb +6 -6
- data/spec/requests/protected_resources/private_api_spec.rb +3 -3
- data/spec/routing/custom_controller_routes_spec.rb +16 -16
- data/spec/routing/default_routes_spec.rb +7 -7
- data/spec/routing/scoped_routes_spec.rb +7 -7
- data/spec/support/helpers/authorization_request_helper.rb +3 -3
- data/spec/support/helpers/model_helper.rb +6 -6
- data/spec/support/helpers/request_spec_helper.rb +9 -9
- data/spec/support/shared/controllers_shared_context.rb +6 -6
- data/spec/support/shared/models_shared_examples.rb +6 -6
- data/spec/validators/redirect_uri_validator_spec.rb +12 -12
- metadata +4 -4
@@ -11,7 +11,7 @@ module Doorkeeper::OAuth
|
|
11
11
|
|
12
12
|
describe :description do
|
13
13
|
it 'is translated from translation messages' do
|
14
|
-
I18n.
|
14
|
+
expect(I18n).to receive(:translate).with(:some_error, :scope => [:doorkeeper, :errors, :messages])
|
15
15
|
subject.description
|
16
16
|
end
|
17
17
|
end
|
@@ -12,30 +12,30 @@ module Doorkeeper::OAuth::Helpers
|
|
12
12
|
it "true if scopes matches" do
|
13
13
|
scopes = new_scope :public
|
14
14
|
scopes_to_match = new_scope :public
|
15
|
-
ScopeChecker.matches?(scopes, scopes_to_match).
|
15
|
+
expect(ScopeChecker.matches?(scopes, scopes_to_match)).to be_true
|
16
16
|
end
|
17
17
|
|
18
18
|
it "is false when scopes differs" do
|
19
19
|
scopes = new_scope :public
|
20
20
|
scopes_to_match = new_scope :write
|
21
|
-
ScopeChecker.matches?(scopes, scopes_to_match).
|
21
|
+
expect(ScopeChecker.matches?(scopes, scopes_to_match)).to be_false
|
22
22
|
end
|
23
23
|
|
24
24
|
it "is false when scope in array is missing" do
|
25
25
|
scopes = new_scope :public
|
26
26
|
scopes_to_match = new_scope :public, :write
|
27
|
-
ScopeChecker.matches?(scopes, scopes_to_match).
|
27
|
+
expect(ScopeChecker.matches?(scopes, scopes_to_match)).to be_false
|
28
28
|
end
|
29
29
|
|
30
30
|
it "is false when scope in string is missing" do
|
31
31
|
scopes = new_scope :public, :write
|
32
32
|
scopes_to_match = new_scope :public
|
33
|
-
ScopeChecker.matches?(scopes, scopes_to_match).
|
33
|
+
expect(ScopeChecker.matches?(scopes, scopes_to_match)).to be_false
|
34
34
|
end
|
35
35
|
|
36
36
|
it "is false when any of attributes is nil" do
|
37
|
-
ScopeChecker.matches?(nil, double).
|
38
|
-
ScopeChecker.matches?(double, nil).
|
37
|
+
expect(ScopeChecker.matches?(nil, double)).to be_false
|
38
|
+
expect(ScopeChecker.matches?(double, nil)).to be_false
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -44,31 +44,31 @@ module Doorkeeper::OAuth::Helpers
|
|
44
44
|
|
45
45
|
it "is valid if scope is present" do
|
46
46
|
server_scopes.add :scope
|
47
|
-
ScopeChecker.valid?("scope", server_scopes).
|
47
|
+
expect(ScopeChecker.valid?("scope", server_scopes)).to be_true
|
48
48
|
end
|
49
49
|
|
50
50
|
it "is invalid if includes tabs space" do
|
51
|
-
ScopeChecker.valid?("\tsomething", server_scopes).
|
51
|
+
expect(ScopeChecker.valid?("\tsomething", server_scopes)).to be_false
|
52
52
|
end
|
53
53
|
|
54
54
|
it "is invalid if scope is not present" do
|
55
|
-
ScopeChecker.valid?(nil, server_scopes).
|
55
|
+
expect(ScopeChecker.valid?(nil, server_scopes)).to be_false
|
56
56
|
end
|
57
57
|
|
58
58
|
it "is invalid if scope is blank" do
|
59
|
-
ScopeChecker.valid?(" ", server_scopes).
|
59
|
+
expect(ScopeChecker.valid?(" ", server_scopes)).to be_false
|
60
60
|
end
|
61
61
|
|
62
62
|
it "is invalid if includes return space" do
|
63
|
-
ScopeChecker.valid?("scope\r", server_scopes).
|
63
|
+
expect(ScopeChecker.valid?("scope\r", server_scopes)).to be_false
|
64
64
|
end
|
65
65
|
|
66
66
|
it "is invalid if includes new lines" do
|
67
|
-
ScopeChecker.valid?("scope\nanother", server_scopes).
|
67
|
+
expect(ScopeChecker.valid?("scope\nanother", server_scopes)).to be_false
|
68
68
|
end
|
69
69
|
|
70
70
|
it "is invalid if any scope is not included in server scopes" do
|
71
|
-
ScopeChecker.valid?("scope another", server_scopes).
|
71
|
+
expect(ScopeChecker.valid?("scope another", server_scopes)).to be_false
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
@@ -9,12 +9,12 @@ module Doorkeeper::OAuth::Helpers
|
|
9
9
|
|
10
10
|
it "is able to customize the generator method" do
|
11
11
|
token = UniqueToken.generate(:generator => generator)
|
12
|
-
token.
|
12
|
+
expect(token).to eq("a" * 32)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "is able to customize the size of the token" do
|
16
16
|
token = UniqueToken.generate(:generator => generator, :size => 2)
|
17
|
-
token.
|
17
|
+
expect(token).to eq("aa")
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -7,75 +7,75 @@ module Doorkeeper::OAuth::Helpers
|
|
7
7
|
describe ".valid?" do
|
8
8
|
it "is valid for valid uris" do
|
9
9
|
uri = "http://app.co"
|
10
|
-
URIChecker.valid?(uri).
|
10
|
+
expect(URIChecker.valid?(uri)).to be_true
|
11
11
|
end
|
12
12
|
|
13
13
|
it "is valid if include path param" do
|
14
14
|
uri = "http://app.co/path"
|
15
|
-
URIChecker.valid?(uri).
|
15
|
+
expect(URIChecker.valid?(uri)).to be_true
|
16
16
|
end
|
17
17
|
|
18
18
|
it "is valid if include query param" do
|
19
19
|
uri = "http://app.co/?query=1"
|
20
|
-
URIChecker.valid?(uri).
|
20
|
+
expect(URIChecker.valid?(uri)).to be_true
|
21
21
|
end
|
22
22
|
|
23
23
|
it "is invalid if uri includes fragment" do
|
24
24
|
uri = "http://app.co/test#fragment"
|
25
|
-
URIChecker.valid?(uri).
|
25
|
+
expect(URIChecker.valid?(uri)).to be_false
|
26
26
|
end
|
27
27
|
|
28
28
|
it "is invalid if scheme is missing" do
|
29
29
|
uri = "app.co"
|
30
|
-
URIChecker.valid?(uri).
|
30
|
+
expect(URIChecker.valid?(uri)).to be_false
|
31
31
|
end
|
32
32
|
|
33
33
|
it "is invalid if is a relative uri" do
|
34
34
|
uri = "/abc/123"
|
35
|
-
URIChecker.valid?(uri).
|
35
|
+
expect(URIChecker.valid?(uri)).to be_false
|
36
36
|
end
|
37
37
|
|
38
38
|
it "is invalid if is not a url" do
|
39
39
|
uri = "http://"
|
40
|
-
URIChecker.valid?(uri).
|
40
|
+
expect(URIChecker.valid?(uri)).to be_false
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
describe ".matches?" do
|
45
45
|
it "is true if both url matches" do
|
46
46
|
uri = client_uri = 'http://app.co/aaa'
|
47
|
-
URIChecker.matches?(uri, client_uri).
|
47
|
+
expect(URIChecker.matches?(uri, client_uri)).to be_true
|
48
48
|
end
|
49
49
|
|
50
50
|
it "ignores query parameter on comparsion" do
|
51
51
|
uri = 'http://app.co/?query=hello'
|
52
52
|
client_uri = 'http://app.co'
|
53
|
-
URIChecker.matches?(uri, client_uri).
|
53
|
+
expect(URIChecker.matches?(uri, client_uri)).to be_true
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
57
|
describe ".valid_for_authorization?" do
|
58
58
|
it "is true if valid and matches" do
|
59
59
|
uri = client_uri = 'http://app.co/aaa'
|
60
|
-
URIChecker.valid_for_authorization?(uri, client_uri).
|
60
|
+
expect(URIChecker.valid_for_authorization?(uri, client_uri)).to be_true
|
61
61
|
end
|
62
62
|
|
63
63
|
it "is false if valid and mismatches" do
|
64
64
|
uri = 'http://app.co/aaa'
|
65
65
|
client_uri = 'http://app.co/bbb'
|
66
|
-
URIChecker.valid_for_authorization?(uri, client_uri).
|
66
|
+
expect(URIChecker.valid_for_authorization?(uri, client_uri)).to be_false
|
67
67
|
end
|
68
68
|
|
69
69
|
it "is true if valid and included in array" do
|
70
70
|
uri = 'http://app.co/aaa'
|
71
71
|
client_uri = "http://example.com/bbb\nhttp://app.co/aaa"
|
72
|
-
URIChecker.valid_for_authorization?(uri, client_uri).
|
72
|
+
expect(URIChecker.valid_for_authorization?(uri, client_uri)).to be_true
|
73
73
|
end
|
74
74
|
|
75
75
|
it "is false if valid and not included in array" do
|
76
76
|
uri = 'http://app.co/aaa'
|
77
77
|
client_uri = "http://example.com/bbb\nhttp://app.co/cc"
|
78
|
-
URIChecker.valid_for_authorization?(uri, client_uri).
|
78
|
+
expect(URIChecker.valid_for_authorization?(uri, client_uri)).to be_false
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
@@ -5,18 +5,23 @@ require 'doorkeeper/oauth/invalid_token_response'
|
|
5
5
|
|
6
6
|
module Doorkeeper::OAuth
|
7
7
|
describe InvalidTokenResponse do
|
8
|
-
|
9
|
-
|
8
|
+
describe '#name' do
|
9
|
+
it { expect(subject.name).to eq(:invalid_token) }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#status' do
|
13
|
+
it { expect(subject.status).to eq(:unauthorized) }
|
14
|
+
end
|
10
15
|
|
11
16
|
describe :from_access_token do
|
12
17
|
it 'revoked' do
|
13
18
|
response = InvalidTokenResponse.from_access_token double(:revoked? => true, :expired? => true)
|
14
|
-
response.description.
|
19
|
+
expect(response.description).to include("revoked")
|
15
20
|
end
|
16
21
|
|
17
22
|
it 'expired' do
|
18
23
|
response = InvalidTokenResponse.from_access_token double(:revoked? => false, :expired? => true)
|
19
|
-
response.description.
|
24
|
+
expect(response.description).to include("expired")
|
20
25
|
end
|
21
26
|
end
|
22
27
|
end
|
@@ -30,18 +30,18 @@ module Doorkeeper::OAuth
|
|
30
30
|
subject.authorize
|
31
31
|
}.to_not change { Doorkeeper::AccessToken.count }
|
32
32
|
|
33
|
-
subject.error.
|
33
|
+
expect(subject.error).to eq(:invalid_client)
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'requires the owner' do
|
37
37
|
subject.resource_owner = nil
|
38
38
|
subject.validate
|
39
|
-
subject.error.
|
39
|
+
expect(subject.error).to eq(:invalid_resource_owner)
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'optionally accepts the client' do
|
43
43
|
subject.credentials = nil
|
44
|
-
subject.
|
44
|
+
expect(subject).to be_valid
|
45
45
|
end
|
46
46
|
|
47
47
|
describe "with scopes" do
|
@@ -50,17 +50,17 @@ module Doorkeeper::OAuth
|
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'validates the current scope' do
|
53
|
-
server.
|
53
|
+
allow(server).to receive(:scopes).and_return(Doorkeeper::OAuth::Scopes.from_string('another'))
|
54
54
|
subject.validate
|
55
|
-
subject.error.
|
55
|
+
expect(subject.error).to eq(:invalid_scope)
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'creates the token with scopes' do
|
59
|
-
server.
|
59
|
+
allow(server).to receive(:scopes).and_return(Doorkeeper::OAuth::Scopes.from_string("public"))
|
60
60
|
expect {
|
61
61
|
subject.authorize
|
62
62
|
}.to change { Doorkeeper::AccessToken.count }.by(1)
|
63
|
-
Doorkeeper::AccessToken.last.scopes.
|
63
|
+
expect(Doorkeeper::AccessToken.last.scopes).to include('public')
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
@@ -18,63 +18,63 @@ module Doorkeeper::OAuth
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'is authorizable when request is valid' do
|
21
|
-
subject.
|
21
|
+
expect(subject).to be_authorizable
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'accepts code as response type' do
|
25
25
|
subject.response_type = 'code'
|
26
|
-
subject.
|
26
|
+
expect(subject).to be_authorizable
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'accepts token as response type' do
|
30
30
|
subject.response_type = 'token'
|
31
|
-
subject.
|
31
|
+
expect(subject).to be_authorizable
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'accepts valid scopes' do
|
35
35
|
subject.scope = 'public'
|
36
|
-
subject.
|
36
|
+
expect(subject).to be_authorizable
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'uses default scopes when none is required' do
|
40
|
-
server.
|
40
|
+
allow(server).to receive(:default_scopes).and_return(Scopes.from_string('default'))
|
41
41
|
subject.scope = nil
|
42
|
-
subject.scope.
|
43
|
-
subject.scopes.
|
42
|
+
expect(subject.scope).to eq('default')
|
43
|
+
expect(subject.scopes).to eq(Scopes.from_string('default'))
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'accepts test uri' do
|
47
47
|
subject.redirect_uri = 'urn:ietf:wg:oauth:2.0:oob'
|
48
|
-
subject.
|
48
|
+
expect(subject).to be_authorizable
|
49
49
|
end
|
50
50
|
|
51
51
|
it "matches the redirect uri against client's one" do
|
52
52
|
subject.redirect_uri = 'http://nothesame.com'
|
53
|
-
subject.
|
53
|
+
expect(subject).not_to be_authorizable
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'stores the state' do
|
57
|
-
subject.state.
|
57
|
+
expect(subject.state).to eq('save-this')
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'rejects if response type is not allowed' do
|
61
61
|
subject.response_type = 'whops'
|
62
|
-
subject.
|
62
|
+
expect(subject).not_to be_authorizable
|
63
63
|
end
|
64
64
|
|
65
65
|
it 'requires an existing client' do
|
66
66
|
subject.client = nil
|
67
|
-
subject.
|
67
|
+
expect(subject).not_to be_authorizable
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'requires a redirect uri' do
|
71
71
|
subject.redirect_uri = nil
|
72
|
-
subject.
|
72
|
+
expect(subject).not_to be_authorizable
|
73
73
|
end
|
74
74
|
|
75
75
|
it 'rejects non-valid scopes' do
|
76
76
|
subject.scope = 'invalid'
|
77
|
-
subject.
|
77
|
+
expect(subject).not_to be_authorizable
|
78
78
|
end
|
79
79
|
end
|
80
80
|
end
|
@@ -26,32 +26,32 @@ module Doorkeeper::OAuth
|
|
26
26
|
it 'requires the refresh token' do
|
27
27
|
subject.refresh_token = nil
|
28
28
|
subject.validate
|
29
|
-
subject.error.
|
29
|
+
expect(subject.error).to eq(:invalid_request)
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'requires credentials to be valid if provided' do
|
33
33
|
subject.client = nil
|
34
34
|
subject.validate
|
35
|
-
subject.error.
|
35
|
+
expect(subject.error).to eq(:invalid_client)
|
36
36
|
end
|
37
37
|
|
38
38
|
it "requires the token's client and current client to match" do
|
39
39
|
subject.client = FactoryGirl.create(:application)
|
40
40
|
subject.validate
|
41
|
-
subject.error.
|
41
|
+
expect(subject.error).to eq(:invalid_grant)
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'rejects revoked tokens' do
|
45
45
|
refresh_token.revoke
|
46
46
|
subject.validate
|
47
|
-
subject.error.
|
47
|
+
expect(subject.error).to eq(:invalid_request)
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'accepts expired tokens' do
|
51
51
|
refresh_token.expires_in = -1
|
52
52
|
refresh_token.save
|
53
53
|
subject.validate
|
54
|
-
subject.
|
54
|
+
expect(subject).to be_valid
|
55
55
|
end
|
56
56
|
|
57
57
|
context 'clientless access tokens' do
|
@@ -77,20 +77,20 @@ module Doorkeeper::OAuth
|
|
77
77
|
|
78
78
|
it 'transfers scopes from the old token to the new token' do
|
79
79
|
subject.authorize
|
80
|
-
Doorkeeper::AccessToken.last.scopes.
|
80
|
+
expect(Doorkeeper::AccessToken.last.scopes).to eq([:public, :write])
|
81
81
|
end
|
82
82
|
|
83
83
|
it 'reduces scopes to the provided scopes' do
|
84
84
|
parameters[:scopes] = 'public'
|
85
85
|
subject.authorize
|
86
|
-
Doorkeeper::AccessToken.last.scopes.
|
86
|
+
expect(Doorkeeper::AccessToken.last.scopes).to eq([:public])
|
87
87
|
end
|
88
88
|
|
89
89
|
it 'validates that scopes are included in the original access token' do
|
90
90
|
parameters[:scopes] = 'public update'
|
91
91
|
|
92
92
|
subject.validate
|
93
|
-
subject.error.
|
93
|
+
expect(subject.error).to eq(:invalid_scope)
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
@@ -8,18 +8,18 @@ module Doorkeeper::OAuth
|
|
8
8
|
describe :add do
|
9
9
|
it 'allows you to add scopes with symbols' do
|
10
10
|
subject.add :public
|
11
|
-
subject.all.
|
11
|
+
expect(subject.all).to eq(['public'])
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'allows you to add scopes with strings' do
|
15
15
|
subject.add "public"
|
16
|
-
subject.all.
|
16
|
+
expect(subject.all).to eq(['public'])
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'do not add already included scopes' do
|
20
20
|
subject.add :public
|
21
21
|
subject.add :public
|
22
|
-
subject.all.
|
22
|
+
expect(subject.all).to eq(['public'])
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -29,16 +29,16 @@ module Doorkeeper::OAuth
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'returns true if scope with given name is present' do
|
32
|
-
subject.exists?("public").
|
32
|
+
expect(subject.exists?("public")).to be_true
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'returns false if scope with given name does not exist' do
|
36
|
-
subject.exists?("other").
|
36
|
+
expect(subject.exists?("other")).to be_false
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'handles symbols' do
|
40
|
-
subject.exists?(:public).
|
41
|
-
subject.exists?(:other).
|
40
|
+
expect(subject.exists?(:public)).to be_true
|
41
|
+
expect(subject.exists?(:other)).to be_false
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -48,19 +48,27 @@ module Doorkeeper::OAuth
|
|
48
48
|
subject { Scopes.from_string(string) }
|
49
49
|
|
50
50
|
it { should be_a(Scopes) }
|
51
|
-
|
51
|
+
|
52
|
+
describe '#all' do
|
53
|
+
it 'should be an array of the expected scopes' do
|
54
|
+
scopes_array = subject.all
|
55
|
+
expect(scopes_array.size).to eq(2)
|
56
|
+
expect(scopes_array).to include('public')
|
57
|
+
expect(scopes_array).to include('write')
|
58
|
+
end
|
59
|
+
end
|
52
60
|
end
|
53
61
|
|
54
62
|
describe :+ do
|
55
63
|
it "can add to another scope object" do
|
56
64
|
scopes = Scopes.from_string("public") + Scopes.from_string("admin")
|
57
|
-
scopes.all.
|
65
|
+
expect(scopes.all).to eq(['public', 'admin'])
|
58
66
|
end
|
59
67
|
|
60
68
|
it "does not change the existing object" do
|
61
69
|
origin = Scopes.from_string("public")
|
62
70
|
new_scope = origin + Scopes.from_string("admin")
|
63
|
-
origin.to_s.
|
71
|
+
expect(origin.to_s).to eq("public")
|
64
72
|
end
|
65
73
|
|
66
74
|
it "raises an error if cannot handle addition" do
|
@@ -72,15 +80,15 @@ module Doorkeeper::OAuth
|
|
72
80
|
|
73
81
|
describe :== do
|
74
82
|
it 'is equal to another set of scopes' do
|
75
|
-
Scopes.from_string("public").
|
83
|
+
expect(Scopes.from_string("public")).to eq(Scopes.from_string("public"))
|
76
84
|
end
|
77
85
|
|
78
86
|
it 'is equal to another set of scopes with no particular order' do
|
79
|
-
Scopes.from_string("public write").
|
87
|
+
expect(Scopes.from_string("public write")).to eq(Scopes.from_string("write public"))
|
80
88
|
end
|
81
89
|
|
82
90
|
it 'differs from another set of scopes when scopes are not the same' do
|
83
|
-
Scopes.from_string("public write").
|
91
|
+
expect(Scopes.from_string("public write")).not_to eq(Scopes.from_string("write"))
|
84
92
|
end
|
85
93
|
end
|
86
94
|
|
@@ -88,27 +96,27 @@ module Doorkeeper::OAuth
|
|
88
96
|
subject { Scopes.from_string("public admin") }
|
89
97
|
|
90
98
|
it "returns true when at least one scope is included" do
|
91
|
-
subject.has_scopes?(Scopes.from_string("public")).
|
99
|
+
expect(subject.has_scopes?(Scopes.from_string("public"))).to be_true
|
92
100
|
end
|
93
101
|
|
94
102
|
it "returns true when all scopes are included" do
|
95
|
-
subject.has_scopes?(Scopes.from_string("public admin")).
|
103
|
+
expect(subject.has_scopes?(Scopes.from_string("public admin"))).to be_true
|
96
104
|
end
|
97
105
|
|
98
106
|
it "is true if all scopes are included in any order" do
|
99
|
-
subject.has_scopes?(Scopes.from_string("admin public")).
|
107
|
+
expect(subject.has_scopes?(Scopes.from_string("admin public"))).to be_true
|
100
108
|
end
|
101
109
|
|
102
110
|
it "is false if no scopes are included" do
|
103
|
-
subject.has_scopes?(Scopes.from_string("notexistent")).
|
111
|
+
expect(subject.has_scopes?(Scopes.from_string("notexistent"))).to be_false
|
104
112
|
end
|
105
113
|
|
106
114
|
it "returns false when any scope is not included" do
|
107
|
-
subject.has_scopes?(Scopes.from_string("public nope")).
|
115
|
+
expect(subject.has_scopes?(Scopes.from_string("public nope"))).to be_false
|
108
116
|
end
|
109
117
|
|
110
118
|
it "is false if no scopes are included even for existing ones" do
|
111
|
-
subject.has_scopes?(Scopes.from_string("public admin notexistent")).
|
119
|
+
expect(subject.has_scopes?(Scopes.from_string("public admin notexistent"))).to be_false
|
112
120
|
end
|
113
121
|
end
|
114
122
|
end
|