doorkeeper 1.1.0 → 1.2.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/.travis.yml +2 -2
- data/CHANGELOG.md +14 -2
- data/README.md +93 -42
- data/app/controllers/doorkeeper/application_controller.rb +1 -1
- data/app/controllers/doorkeeper/applications_controller.rb +4 -4
- data/app/controllers/doorkeeper/authorizations_controller.rb +3 -3
- data/app/controllers/doorkeeper/authorized_applications_controller.rb +1 -1
- data/app/controllers/doorkeeper/token_info_controller.rb +3 -3
- data/app/controllers/doorkeeper/tokens_controller.rb +29 -2
- data/app/helpers/doorkeeper/form_errors_helper.rb +2 -2
- data/app/validators/redirect_uri_validator.rb +1 -1
- data/app/views/doorkeeper/applications/_form.html.erb +3 -3
- data/app/views/doorkeeper/applications/edit.html.erb +1 -1
- data/app/views/doorkeeper/applications/new.html.erb +1 -1
- data/app/views/doorkeeper/applications/show.html.erb +1 -1
- data/app/views/doorkeeper/authorizations/new.html.erb +5 -5
- data/doorkeeper.gemspec +1 -1
- data/lib/doorkeeper.rb +31 -31
- data/lib/doorkeeper/config.rb +66 -37
- data/lib/doorkeeper/doorkeeper_for.rb +6 -3
- data/lib/doorkeeper/engine.rb +2 -2
- data/lib/doorkeeper/helpers/controller.rb +9 -9
- data/lib/doorkeeper/helpers/filter.rb +1 -1
- data/lib/doorkeeper/models/access_grant.rb +5 -5
- data/lib/doorkeeper/models/access_token.rb +22 -18
- data/lib/doorkeeper/models/active_record/access_token.rb +8 -8
- data/lib/doorkeeper/models/active_record/application.rb +5 -5
- data/lib/doorkeeper/models/application.rb +8 -9
- data/lib/doorkeeper/models/expirable.rb +1 -1
- data/lib/doorkeeper/models/mongo_mapper/access_grant.rb +2 -2
- data/lib/doorkeeper/models/mongo_mapper/access_token.rb +11 -11
- data/lib/doorkeeper/models/mongo_mapper/application.rb +4 -4
- data/lib/doorkeeper/models/mongoid/version.rb +2 -2
- data/lib/doorkeeper/models/mongoid2/access_grant.rb +7 -7
- data/lib/doorkeeper/models/mongoid2/access_token.rb +14 -14
- data/lib/doorkeeper/models/mongoid2/application.rb +7 -7
- data/lib/doorkeeper/models/mongoid3_4/access_grant.rb +7 -7
- data/lib/doorkeeper/models/mongoid3_4/access_token.rb +13 -13
- data/lib/doorkeeper/models/mongoid3_4/application.rb +6 -6
- data/lib/doorkeeper/models/ownership.rb +5 -5
- data/lib/doorkeeper/oauth/authorization/code.rb +5 -5
- data/lib/doorkeeper/oauth/authorization/token.rb +7 -7
- data/lib/doorkeeper/oauth/authorization_code_request.rb +18 -19
- data/lib/doorkeeper/oauth/client.rb +1 -1
- data/lib/doorkeeper/oauth/client_credentials/creator.rb +4 -4
- data/lib/doorkeeper/oauth/client_credentials/issuer.rb +6 -4
- data/lib/doorkeeper/oauth/client_credentials/validation.rb +2 -2
- data/lib/doorkeeper/oauth/client_credentials_request.rb +11 -15
- data/lib/doorkeeper/oauth/code_request.rb +5 -4
- data/lib/doorkeeper/oauth/code_response.rb +8 -7
- data/lib/doorkeeper/oauth/error.rb +1 -1
- data/lib/doorkeeper/oauth/error_response.rb +5 -5
- data/lib/doorkeeper/oauth/helpers/uri_checker.rb +1 -1
- data/lib/doorkeeper/oauth/invalid_token_response.rb +10 -10
- data/lib/doorkeeper/oauth/password_access_token_request.rb +57 -54
- data/lib/doorkeeper/oauth/pre_authorization.rb +7 -7
- data/lib/doorkeeper/oauth/refresh_token_request.rb +27 -24
- data/lib/doorkeeper/oauth/scopes.rb +3 -3
- data/lib/doorkeeper/oauth/token.rb +27 -1
- data/lib/doorkeeper/oauth/token_request.rb +14 -4
- data/lib/doorkeeper/rails/routes.rb +31 -22
- data/lib/doorkeeper/rails/routes/mapping.rb +11 -12
- data/lib/doorkeeper/request.rb +5 -5
- data/lib/doorkeeper/version.rb +1 -1
- data/lib/generators/doorkeeper/application_owner_generator.rb +1 -1
- data/lib/generators/doorkeeper/install_generator.rb +5 -5
- data/lib/generators/doorkeeper/migration_generator.rb +1 -1
- data/lib/generators/doorkeeper/mongo_mapper/indexes_generator.rb +2 -2
- data/lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb +2 -2
- data/lib/generators/doorkeeper/templates/initializer.rb +16 -3
- data/lib/generators/doorkeeper/templates/migration.rb +16 -17
- data/lib/generators/doorkeeper/views_generator.rb +1 -1
- data/spec/controllers/applications_controller_spec.rb +7 -7
- data/spec/controllers/authorizations_controller_spec.rb +48 -48
- data/spec/controllers/protected_resources_controller_spec.rb +108 -107
- data/spec/controllers/token_info_controller_spec.rb +11 -11
- data/spec/controllers/tokens_controller_spec.rb +8 -8
- data/spec/dummy/app/controllers/custom_authorizations_controller.rb +2 -2
- data/spec/dummy/app/controllers/full_protected_resources_controller.rb +3 -3
- data/spec/dummy/app/controllers/home_controller.rb +5 -5
- data/spec/dummy/app/controllers/metal_controller.rb +1 -1
- data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +2 -2
- data/spec/dummy/app/models/user.rb +3 -3
- data/spec/dummy/config/application.rb +8 -9
- data/spec/dummy/config/boot.rb +1 -1
- data/spec/dummy/config/environments/test.rb +1 -1
- data/spec/dummy/config/initializers/doorkeeper.rb +5 -5
- data/spec/dummy/config/initializers/session_store.rb +1 -1
- data/spec/dummy/config/initializers/wrap_parameters.rb +1 -1
- data/spec/dummy/config/routes.rb +27 -27
- data/spec/dummy/db/migrate/20130902165751_create_doorkeeper_tables.rb +16 -17
- data/spec/dummy/db/migrate/20130902175349_add_owner_to_application.rb +3 -3
- data/spec/dummy/db/schema.rb +39 -39
- data/spec/factories/access_grant.rb +3 -3
- data/spec/factories/access_token.rb +1 -1
- data/spec/factories/application.rb +3 -3
- data/spec/generators/application_owner_generator_spec.rb +6 -7
- data/spec/generators/install_generator_spec.rb +9 -9
- data/spec/generators/migration_generator_spec.rb +4 -4
- data/spec/lib/config_spec.rb +136 -44
- data/spec/lib/models/expirable_spec.rb +9 -9
- data/spec/lib/models/revocable_spec.rb +4 -4
- data/spec/lib/oauth/authorization/uri_builder_spec.rb +4 -4
- data/spec/lib/oauth/authorization_code_request_spec.rb +2 -2
- data/spec/lib/oauth/client/credentials_spec.rb +4 -4
- data/spec/lib/oauth/client/methods_spec.rb +10 -10
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +9 -7
- data/spec/lib/oauth/client_credentials/validation_spec.rb +2 -2
- data/spec/lib/oauth/client_credentials_request_spec.rb +6 -6
- data/spec/lib/oauth/client_spec.rb +4 -4
- data/spec/lib/oauth/code_request_spec.rb +10 -9
- data/spec/lib/oauth/error_response_spec.rb +8 -8
- data/spec/lib/oauth/error_spec.rb +1 -1
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +17 -17
- data/spec/lib/oauth/helpers/unique_token_spec.rb +7 -7
- data/spec/lib/oauth/helpers/uri_checker_spec.rb +33 -33
- data/spec/lib/oauth/invalid_token_response_spec.rb +4 -4
- data/spec/lib/oauth/password_access_token_request_spec.rb +13 -13
- data/spec/lib/oauth/pre_authorization_spec.rb +47 -7
- data/spec/lib/oauth/refresh_token_request_spec.rb +11 -21
- data/spec/lib/oauth/scopes_spec.rb +32 -32
- data/spec/lib/oauth/token_request_spec.rb +10 -9
- data/spec/lib/oauth/token_response_spec.rb +13 -15
- data/spec/lib/oauth/token_spec.rb +24 -10
- data/spec/lib/server_spec.rb +24 -2
- data/spec/models/doorkeeper/access_grant_spec.rb +8 -8
- data/spec/models/doorkeeper/access_token_spec.rb +79 -33
- data/spec/models/doorkeeper/application_spec.rb +29 -29
- data/spec/requests/applications/applications_request_spec.rb +15 -15
- data/spec/requests/applications/authorized_applications_spec.rb +7 -7
- data/spec/requests/endpoints/authorization_spec.rb +19 -12
- data/spec/requests/endpoints/token_spec.rb +26 -8
- data/spec/requests/flows/authorization_code_errors_spec.rb +17 -17
- data/spec/requests/flows/authorization_code_spec.rb +28 -28
- data/spec/requests/flows/client_credentials_spec.rb +3 -3
- data/spec/requests/flows/implicit_grant_errors_spec.rb +5 -5
- data/spec/requests/flows/implicit_grant_spec.rb +2 -2
- data/spec/requests/flows/password_spec.rb +32 -32
- data/spec/requests/flows/refresh_token_spec.rb +23 -23
- data/spec/requests/flows/revoke_token_spec.rb +165 -0
- data/spec/requests/flows/skip_authorization_spec.rb +10 -10
- data/spec/requests/protected_resources/metal_spec.rb +1 -1
- data/spec/requests/protected_resources/private_api_spec.rb +5 -5
- data/spec/routing/custom_controller_routes_spec.rb +4 -0
- data/spec/routing/default_routes_spec.rb +5 -1
- data/spec/spec_helper.rb +2 -2
- data/spec/spec_helper_integration.rb +8 -10
- data/spec/support/helpers/access_token_request_helper.rb +3 -3
- data/spec/support/helpers/authorization_request_helper.rb +3 -3
- data/spec/support/helpers/config_helper.rb +1 -1
- data/spec/support/helpers/model_helper.rb +2 -2
- data/spec/support/helpers/request_spec_helper.rb +3 -3
- data/spec/support/helpers/url_helper.rb +25 -21
- data/spec/support/orm/active_record.rb +4 -4
- data/spec/support/orm/mongo_mapper.rb +2 -3
- data/spec/support/orm/mongoid.rb +5 -6
- data/spec/support/shared/controllers_shared_context.rb +15 -15
- data/spec/support/shared/models_shared_examples.rb +13 -13
- data/spec/validators/redirect_uri_validator_spec.rb +9 -9
- metadata +5 -4
@@ -4,73 +4,73 @@ require 'doorkeeper/oauth/helpers/uri_checker'
|
|
4
4
|
|
5
5
|
module Doorkeeper::OAuth::Helpers
|
6
6
|
describe URIChecker do
|
7
|
-
describe
|
8
|
-
it
|
9
|
-
uri =
|
7
|
+
describe '.valid?' do
|
8
|
+
it 'is valid for valid uris' do
|
9
|
+
uri = 'http://app.co'
|
10
10
|
expect(URIChecker.valid?(uri)).to be_true
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
14
|
-
uri =
|
13
|
+
it 'is valid if include path param' do
|
14
|
+
uri = 'http://app.co/path'
|
15
15
|
expect(URIChecker.valid?(uri)).to be_true
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
19
|
-
uri =
|
18
|
+
it 'is valid if include query param' do
|
19
|
+
uri = 'http://app.co/?query=1'
|
20
20
|
expect(URIChecker.valid?(uri)).to be_true
|
21
21
|
end
|
22
22
|
|
23
|
-
it
|
24
|
-
uri =
|
23
|
+
it 'is invalid if uri includes fragment' do
|
24
|
+
uri = 'http://app.co/test#fragment'
|
25
25
|
expect(URIChecker.valid?(uri)).to be_false
|
26
26
|
end
|
27
27
|
|
28
|
-
it
|
29
|
-
uri =
|
28
|
+
it 'is invalid if scheme is missing' do
|
29
|
+
uri = 'app.co'
|
30
30
|
expect(URIChecker.valid?(uri)).to be_false
|
31
31
|
end
|
32
32
|
|
33
|
-
it
|
34
|
-
uri =
|
33
|
+
it 'is invalid if is a relative uri' do
|
34
|
+
uri = '/abc/123'
|
35
35
|
expect(URIChecker.valid?(uri)).to be_false
|
36
36
|
end
|
37
37
|
|
38
|
-
it
|
39
|
-
uri =
|
38
|
+
it 'is invalid if is not a url' do
|
39
|
+
uri = 'http://'
|
40
40
|
expect(URIChecker.valid?(uri)).to be_false
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
describe
|
45
|
-
it
|
44
|
+
describe '.matches?' do
|
45
|
+
it 'is true if both url matches' do
|
46
46
|
uri = client_uri = 'http://app.co/aaa'
|
47
47
|
expect(URIChecker.matches?(uri, client_uri)).to be_true
|
48
48
|
end
|
49
49
|
|
50
|
-
it
|
50
|
+
it 'ignores query parameter on comparsion' do
|
51
51
|
uri = 'http://app.co/?query=hello'
|
52
52
|
client_uri = 'http://app.co'
|
53
53
|
expect(URIChecker.matches?(uri, client_uri)).to be_true
|
54
54
|
end
|
55
55
|
|
56
|
-
context
|
56
|
+
context 'allows wildcard redirect_uri' do
|
57
57
|
before do
|
58
|
-
Doorkeeper.configuration.stub(wildcard_redirect_uri: true
|
58
|
+
Doorkeeper.configuration.stub(wildcard_redirect_uri: true)
|
59
59
|
end
|
60
60
|
|
61
|
-
it
|
61
|
+
it 'ignores query parameter on comparison' do
|
62
62
|
uri = 'http://app.co/?query=hello'
|
63
63
|
client_uri = 'http://app.co'
|
64
64
|
expect(URIChecker.matches?(uri, client_uri)).to be true
|
65
65
|
end
|
66
66
|
|
67
|
-
it
|
67
|
+
it 'doesn\'t allow non-matching domains through' do
|
68
68
|
uri = 'http://app.abc/?query=hello'
|
69
69
|
client_uri = 'http://app.co'
|
70
70
|
expect(URIChecker.matches?(uri, client_uri)).to be false
|
71
71
|
end
|
72
72
|
|
73
|
-
it
|
73
|
+
it 'doesn\'t allow non-matching domains that don\'t start at the beginning' do
|
74
74
|
uri = 'http://app.co/?query=hello'
|
75
75
|
client_uri = 'http://example.com?app.co=test'
|
76
76
|
expect(URIChecker.matches?(uri, client_uri)).to be false
|
@@ -78,46 +78,46 @@ module Doorkeeper::OAuth::Helpers
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
-
describe
|
82
|
-
it
|
81
|
+
describe '.valid_for_authorization?' do
|
82
|
+
it 'is true if valid and matches' do
|
83
83
|
uri = client_uri = 'http://app.co/aaa'
|
84
84
|
expect(URIChecker.valid_for_authorization?(uri, client_uri)).to be_true
|
85
85
|
end
|
86
86
|
|
87
|
-
it
|
87
|
+
it 'is false if valid and mismatches' do
|
88
88
|
uri = 'http://app.co/aaa'
|
89
89
|
client_uri = 'http://app.co/bbb'
|
90
90
|
expect(URIChecker.valid_for_authorization?(uri, client_uri)).to be_false
|
91
91
|
end
|
92
92
|
|
93
|
-
it
|
93
|
+
it 'is true if valid and included in array' do
|
94
94
|
uri = 'http://app.co/aaa'
|
95
95
|
client_uri = "http://example.com/bbb\nhttp://app.co/aaa"
|
96
96
|
expect(URIChecker.valid_for_authorization?(uri, client_uri)).to be_true
|
97
97
|
end
|
98
98
|
|
99
|
-
it
|
99
|
+
it 'is false if valid and not included in array' do
|
100
100
|
uri = 'http://app.co/aaa'
|
101
101
|
client_uri = "http://example.com/bbb\nhttp://app.co/cc"
|
102
102
|
expect(URIChecker.valid_for_authorization?(uri, client_uri)).to be_false
|
103
103
|
end
|
104
104
|
|
105
|
-
it
|
105
|
+
it 'is true if valid and matches' do
|
106
106
|
uri = client_uri = 'http://app.co/aaa'
|
107
107
|
expect(URIChecker.valid_for_authorization?(uri, client_uri)).to be true
|
108
108
|
end
|
109
109
|
|
110
|
-
it
|
110
|
+
it 'is false if invalid' do
|
111
111
|
uri = client_uri = 'http://app.co/aaa?waffles=abc'
|
112
112
|
expect(URIChecker.valid_for_authorization?(uri, client_uri)).to be false
|
113
113
|
end
|
114
114
|
|
115
|
-
context
|
115
|
+
context 'allows wildcard redirect_uri' do
|
116
116
|
before do
|
117
|
-
Doorkeeper.configuration.stub(wildcard_redirect_uri: true
|
117
|
+
Doorkeeper.configuration.stub(wildcard_redirect_uri: true)
|
118
118
|
end
|
119
119
|
|
120
|
-
it
|
120
|
+
it 'is true if valid, matches and contains a query parameter' do
|
121
121
|
uri = client_uri = 'http://app.co/aaa?waffles=abc'
|
122
122
|
expect(URIChecker.valid_for_authorization?(uri, client_uri)).to be true
|
123
123
|
end
|
@@ -15,13 +15,13 @@ module Doorkeeper::OAuth
|
|
15
15
|
|
16
16
|
describe :from_access_token do
|
17
17
|
it 'revoked' do
|
18
|
-
response = InvalidTokenResponse.from_access_token double(
|
19
|
-
expect(response.description).to include(
|
18
|
+
response = InvalidTokenResponse.from_access_token double(revoked?: true, expired?: true)
|
19
|
+
expect(response.description).to include('revoked')
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'expired' do
|
23
|
-
response = InvalidTokenResponse.from_access_token double(
|
24
|
-
expect(response.description).to include(
|
23
|
+
response = InvalidTokenResponse.from_access_token double(revoked?: false, expired?: true)
|
24
|
+
expect(response.description).to include('expired')
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -2,33 +2,33 @@ require 'spec_helper_integration'
|
|
2
2
|
|
3
3
|
module Doorkeeper::OAuth
|
4
4
|
describe PasswordAccessTokenRequest do
|
5
|
-
let(:server) { double :server, :
|
5
|
+
let(:server) { double :server, default_scopes: Doorkeeper::OAuth::Scopes.new, access_token_expires_in: 2.hours, refresh_token_enabled?: false }
|
6
6
|
let(:credentials) { Client::Credentials.new(client.uid, client.secret) }
|
7
7
|
let(:client) { FactoryGirl.create(:application) }
|
8
|
-
let(:owner) { double :owner, :
|
8
|
+
let(:owner) { double :owner, id: 99 }
|
9
9
|
|
10
10
|
subject do
|
11
11
|
PasswordAccessTokenRequest.new(server, credentials, owner)
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'issues a new token for the client' do
|
15
|
-
expect
|
15
|
+
expect do
|
16
16
|
subject.authorize
|
17
|
-
|
17
|
+
end.to change { client.access_tokens.count }.by(1)
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'issues a new token without a client' do
|
21
|
-
expect
|
21
|
+
expect do
|
22
22
|
subject.credentials = nil
|
23
23
|
subject.authorize
|
24
|
-
|
24
|
+
end.to change { Doorkeeper::AccessToken.count }.by(1)
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'does not issue a new token with an invalid client' do
|
28
|
-
expect
|
28
|
+
expect do
|
29
29
|
subject.client = nil
|
30
30
|
subject.authorize
|
31
|
-
|
31
|
+
end.to_not change { Doorkeeper::AccessToken.count }
|
32
32
|
|
33
33
|
expect(subject.error).to eq(:invalid_client)
|
34
34
|
end
|
@@ -44,9 +44,9 @@ module Doorkeeper::OAuth
|
|
44
44
|
expect(subject).to be_valid
|
45
45
|
end
|
46
46
|
|
47
|
-
describe
|
47
|
+
describe 'with scopes' do
|
48
48
|
subject do
|
49
|
-
PasswordAccessTokenRequest.new(server, client, owner, :
|
49
|
+
PasswordAccessTokenRequest.new(server, client, owner, scope: 'public')
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'validates the current scope' do
|
@@ -56,10 +56,10 @@ module Doorkeeper::OAuth
|
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'creates the token with scopes' do
|
59
|
-
allow(server).to receive(:scopes).and_return(Doorkeeper::OAuth::Scopes.from_string(
|
60
|
-
expect
|
59
|
+
allow(server).to receive(:scopes).and_return(Doorkeeper::OAuth::Scopes.from_string('public'))
|
60
|
+
expect do
|
61
61
|
subject.authorize
|
62
|
-
|
62
|
+
end.to change { Doorkeeper::AccessToken.count }.by(1)
|
63
63
|
expect(Doorkeeper::AccessToken.last.scopes).to include('public')
|
64
64
|
end
|
65
65
|
end
|
@@ -1,15 +1,21 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper_integration'
|
2
2
|
|
3
3
|
module Doorkeeper::OAuth
|
4
4
|
describe PreAuthorization do
|
5
|
-
let(:server) {
|
6
|
-
|
5
|
+
let(:server) {
|
6
|
+
server = Doorkeeper.configuration
|
7
|
+
server.stub(:default_scopes) { Scopes.new }
|
8
|
+
server.stub(:scopes) { Scopes.from_string('public') }
|
9
|
+
server
|
10
|
+
}
|
11
|
+
|
12
|
+
let(:client) { double :client, redirect_uri: 'http://tst.com/auth' }
|
7
13
|
|
8
14
|
let :attributes do
|
9
15
|
{
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
16
|
+
response_type: 'code',
|
17
|
+
redirect_uri: 'http://tst.com/auth',
|
18
|
+
state: 'save-this'
|
13
19
|
}
|
14
20
|
end
|
15
21
|
|
@@ -31,6 +37,40 @@ module Doorkeeper::OAuth
|
|
31
37
|
expect(subject).to be_authorizable
|
32
38
|
end
|
33
39
|
|
40
|
+
context 'when using default grant flows' do
|
41
|
+
it 'accepts "code" as response type' do
|
42
|
+
subject.response_type = 'code'
|
43
|
+
expect(subject).to be_authorizable
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'accepts "token" as response type' do
|
47
|
+
subject.response_type = 'token'
|
48
|
+
expect(subject).to be_authorizable
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when authorization code grant flow is disabled' do
|
53
|
+
before do
|
54
|
+
server.stub(:grant_flows) { ['implicit'] }
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'does not accept "code" as response type' do
|
58
|
+
subject.response_type = 'code'
|
59
|
+
expect(subject).not_to be_authorizable
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'when implicit grant flow is disabled' do
|
64
|
+
before do
|
65
|
+
server.stub(:grant_flows) { ['authorization_code'] }
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'does not accept "token" as response type' do
|
69
|
+
subject.response_type = 'token'
|
70
|
+
expect(subject).not_to be_authorizable
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
34
74
|
it 'accepts valid scopes' do
|
35
75
|
subject.scope = 'public'
|
36
76
|
expect(subject).to be_authorizable
|
@@ -48,7 +88,7 @@ module Doorkeeper::OAuth
|
|
48
88
|
expect(subject).to be_authorizable
|
49
89
|
end
|
50
90
|
|
51
|
-
it
|
91
|
+
it 'matches the redirect uri against client\'s one' do
|
52
92
|
subject.redirect_uri = 'http://nothesame.com'
|
53
93
|
expect(subject).not_to be_authorizable
|
54
94
|
end
|
@@ -2,25 +2,21 @@ require 'spec_helper_integration'
|
|
2
2
|
|
3
3
|
module Doorkeeper::OAuth
|
4
4
|
describe RefreshTokenRequest do
|
5
|
-
let(:server) { double :server, :
|
6
|
-
let!(:refresh_token) { FactoryGirl.create(:access_token, :
|
5
|
+
let(:server) { double :server, access_token_expires_in: 2.minutes }
|
6
|
+
let!(:refresh_token) { FactoryGirl.create(:access_token, use_refresh_token: true) }
|
7
7
|
let(:client) { refresh_token.application }
|
8
8
|
let(:credentials) { Client::Credentials.new(client.uid, client.secret) }
|
9
9
|
|
10
|
-
subject {
|
11
|
-
RefreshTokenRequest.new server, refresh_token, credentials
|
12
|
-
}
|
10
|
+
subject { RefreshTokenRequest.new server, refresh_token, credentials }
|
13
11
|
|
14
12
|
it 'issues a new token for the client' do
|
15
|
-
expect
|
13
|
+
expect do
|
16
14
|
subject.authorize
|
17
|
-
|
15
|
+
end.to change { client.access_tokens.count }.by(1)
|
18
16
|
end
|
19
17
|
|
20
18
|
it 'revokes the previous token' do
|
21
|
-
expect {
|
22
|
-
subject.authorize
|
23
|
-
}.to change { refresh_token.revoked? }.from(false).to(true)
|
19
|
+
expect { subject.authorize } .to change { refresh_token.revoked? }.from(false).to(true)
|
24
20
|
end
|
25
21
|
|
26
22
|
it 'requires the refresh token' do
|
@@ -55,25 +51,19 @@ module Doorkeeper::OAuth
|
|
55
51
|
end
|
56
52
|
|
57
53
|
context 'clientless access tokens' do
|
58
|
-
let!(:refresh_token) { FactoryGirl.create(:clientless_access_token, :
|
54
|
+
let!(:refresh_token) { FactoryGirl.create(:clientless_access_token, use_refresh_token: true) }
|
59
55
|
|
60
|
-
subject {
|
61
|
-
RefreshTokenRequest.new server, refresh_token, nil
|
62
|
-
}
|
56
|
+
subject { RefreshTokenRequest.new server, refresh_token, nil }
|
63
57
|
|
64
58
|
it 'issues a new token without a client' do
|
65
|
-
expect {
|
66
|
-
subject.authorize
|
67
|
-
}.to change { Doorkeeper::AccessToken.count }.by(1)
|
59
|
+
expect { subject.authorize }.to change { Doorkeeper::AccessToken.count }.by(1)
|
68
60
|
end
|
69
61
|
end
|
70
62
|
|
71
63
|
context 'with scopes' do
|
72
|
-
let!(:refresh_token) { FactoryGirl.create(:access_token, :
|
64
|
+
let!(:refresh_token) { FactoryGirl.create(:access_token, use_refresh_token: true, scopes: 'public write') }
|
73
65
|
let(:parameters) { {} }
|
74
|
-
subject {
|
75
|
-
RefreshTokenRequest.new server, refresh_token, credentials, parameters
|
76
|
-
}
|
66
|
+
subject { RefreshTokenRequest.new server, refresh_token, credentials, parameters }
|
77
67
|
|
78
68
|
it 'transfers scopes from the old token to the new token' do
|
79
69
|
subject.authorize
|
@@ -12,7 +12,7 @@ module Doorkeeper::OAuth
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'allows you to add scopes with strings' do
|
15
|
-
subject.add
|
15
|
+
subject.add 'public'
|
16
16
|
expect(subject.all).to eq(['public'])
|
17
17
|
end
|
18
18
|
|
@@ -29,11 +29,11 @@ module Doorkeeper::OAuth
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'returns true if scope with given name is present' do
|
32
|
-
expect(subject.exists?(
|
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
|
-
expect(subject.exists?(
|
36
|
+
expect(subject.exists?('other')).to be_false
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'handles symbols' do
|
@@ -42,8 +42,8 @@ module Doorkeeper::OAuth
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
describe
|
46
|
-
let(:string) {
|
45
|
+
describe '.from_string' do
|
46
|
+
let(:string) { 'public write' }
|
47
47
|
|
48
48
|
subject { Scopes.from_string(string) }
|
49
49
|
|
@@ -60,63 +60,63 @@ module Doorkeeper::OAuth
|
|
60
60
|
end
|
61
61
|
|
62
62
|
describe :+ do
|
63
|
-
it
|
64
|
-
scopes = Scopes.from_string(
|
65
|
-
expect(scopes.all).to eq(
|
63
|
+
it 'can add to another scope object' do
|
64
|
+
scopes = Scopes.from_string('public') + Scopes.from_string('admin')
|
65
|
+
expect(scopes.all).to eq(%w(public admin))
|
66
66
|
end
|
67
67
|
|
68
|
-
it
|
69
|
-
origin = Scopes.from_string(
|
70
|
-
new_scope = origin + Scopes.from_string(
|
71
|
-
expect(origin.to_s).to eq(
|
68
|
+
it 'does not change the existing object' do
|
69
|
+
origin = Scopes.from_string('public')
|
70
|
+
new_scope = origin + Scopes.from_string('admin')
|
71
|
+
expect(origin.to_s).to eq('public')
|
72
72
|
end
|
73
73
|
|
74
|
-
it
|
75
|
-
expect
|
76
|
-
Scopes.from_string(
|
77
|
-
|
74
|
+
it 'raises an error if cannot handle addition' do
|
75
|
+
expect do
|
76
|
+
Scopes.from_string('public') + 'admin'
|
77
|
+
end.to raise_error(NoMethodError)
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
81
|
describe :== do
|
82
82
|
it 'is equal to another set of scopes' do
|
83
|
-
expect(Scopes.from_string(
|
83
|
+
expect(Scopes.from_string('public')).to eq(Scopes.from_string('public'))
|
84
84
|
end
|
85
85
|
|
86
86
|
it 'is equal to another set of scopes with no particular order' do
|
87
|
-
expect(Scopes.from_string(
|
87
|
+
expect(Scopes.from_string('public write')).to eq(Scopes.from_string('write public'))
|
88
88
|
end
|
89
89
|
|
90
90
|
it 'differs from another set of scopes when scopes are not the same' do
|
91
|
-
expect(Scopes.from_string(
|
91
|
+
expect(Scopes.from_string('public write')).not_to eq(Scopes.from_string('write'))
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
95
|
describe :has_scopes? do
|
96
|
-
subject { Scopes.from_string(
|
96
|
+
subject { Scopes.from_string('public admin') }
|
97
97
|
|
98
|
-
it
|
99
|
-
expect(subject.has_scopes?(Scopes.from_string(
|
98
|
+
it 'returns true when at least one scope is included' do
|
99
|
+
expect(subject.has_scopes?(Scopes.from_string('public'))).to be_true
|
100
100
|
end
|
101
101
|
|
102
|
-
it
|
103
|
-
expect(subject.has_scopes?(Scopes.from_string(
|
102
|
+
it 'returns true when all scopes are included' do
|
103
|
+
expect(subject.has_scopes?(Scopes.from_string('public admin'))).to be_true
|
104
104
|
end
|
105
105
|
|
106
|
-
it
|
107
|
-
expect(subject.has_scopes?(Scopes.from_string(
|
106
|
+
it 'is true if all scopes are included in any order' do
|
107
|
+
expect(subject.has_scopes?(Scopes.from_string('admin public'))).to be_true
|
108
108
|
end
|
109
109
|
|
110
|
-
it
|
111
|
-
expect(subject.has_scopes?(Scopes.from_string(
|
110
|
+
it 'is false if no scopes are included' do
|
111
|
+
expect(subject.has_scopes?(Scopes.from_string('notexistent'))).to be_false
|
112
112
|
end
|
113
113
|
|
114
|
-
it
|
115
|
-
expect(subject.has_scopes?(Scopes.from_string(
|
114
|
+
it 'returns false when any scope is not included' do
|
115
|
+
expect(subject.has_scopes?(Scopes.from_string('public nope'))).to be_false
|
116
116
|
end
|
117
117
|
|
118
|
-
it
|
119
|
-
expect(subject.has_scopes?(Scopes.from_string(
|
118
|
+
it 'is false if no scopes are included even for existing ones' do
|
119
|
+
expect(subject.has_scopes?(Scopes.from_string('public admin notexistent'))).to be_false
|
120
120
|
end
|
121
121
|
end
|
122
122
|
end
|