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
@@ -10,20 +10,20 @@ describe 'Revocable' do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
describe :revoke do
|
13
|
-
it
|
14
|
-
clock = double :
|
13
|
+
it 'updates :revoked_at attribute with current time' do
|
14
|
+
clock = double now: double
|
15
15
|
expect(subject).to receive(:update_column).with(:revoked_at, clock.now)
|
16
16
|
subject.revoke(clock)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
describe :revoked? do
|
21
|
-
it
|
21
|
+
it 'is revoked if :revoked_at is set' do
|
22
22
|
allow(subject).to receive(:revoked_at).and_return(double)
|
23
23
|
expect(subject).to be_revoked
|
24
24
|
end
|
25
25
|
|
26
|
-
it
|
26
|
+
it 'is not revoked if :revoked_at is not set' do
|
27
27
|
allow(subject).to receive(:revoked_at).and_return(nil)
|
28
28
|
expect(subject).not_to be_revoked
|
29
29
|
end
|
@@ -11,17 +11,17 @@ module Doorkeeper::OAuth::Authorization
|
|
11
11
|
|
12
12
|
describe :uri_with_query do
|
13
13
|
it 'returns the uri with query' do
|
14
|
-
uri = subject.uri_with_query 'http://example.com/', :
|
14
|
+
uri = subject.uri_with_query 'http://example.com/', parameter: 'value'
|
15
15
|
expect(uri).to eq('http://example.com/?parameter=value')
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'rejects nil values' do
|
19
|
-
uri = subject.uri_with_query 'http://example.com/', :
|
19
|
+
uri = subject.uri_with_query 'http://example.com/', parameter: ''
|
20
20
|
expect(uri).to eq('http://example.com/?')
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'preserves original query parameters' do
|
24
|
-
uri = subject.uri_with_query 'http://example.com/?query1=value', :
|
24
|
+
uri = subject.uri_with_query 'http://example.com/?query1=value', parameter: 'value'
|
25
25
|
expect(uri).to match(/query1=value/)
|
26
26
|
expect(uri).to match(/parameter=value/)
|
27
27
|
end
|
@@ -29,7 +29,7 @@ module Doorkeeper::OAuth::Authorization
|
|
29
29
|
|
30
30
|
describe :uri_with_fragment do
|
31
31
|
it 'returns uri with parameters as fragments' do
|
32
|
-
uri = subject.uri_with_fragment 'http://example.com/', :
|
32
|
+
uri = subject.uri_with_fragment 'http://example.com/', parameter: 'value'
|
33
33
|
expect(uri).to eq('http://example.com/#parameter=value')
|
34
34
|
end
|
35
35
|
end
|
@@ -2,12 +2,12 @@ require 'spec_helper_integration'
|
|
2
2
|
|
3
3
|
module Doorkeeper::OAuth
|
4
4
|
describe AuthorizationCodeRequest do
|
5
|
-
let(:server) { double :server, :
|
5
|
+
let(:server) { double :server, access_token_expires_in: 2.days, refresh_token_enabled?: false }
|
6
6
|
let(:grant) { FactoryGirl.create :access_grant }
|
7
7
|
let(:client) { grant.application }
|
8
8
|
|
9
9
|
subject do
|
10
|
-
AuthorizationCodeRequest.new server, grant, client, :
|
10
|
+
AuthorizationCodeRequest.new server, grant, client, redirect_uri: client.redirect_uri
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'issues a new token for the client' do
|
@@ -5,15 +5,15 @@ require 'doorkeeper/oauth/client'
|
|
5
5
|
class Doorkeeper::OAuth::Client
|
6
6
|
describe Credentials do
|
7
7
|
it 'is blank when any of the credentials is blank' do
|
8
|
-
expect(Credentials.new(nil,
|
9
|
-
expect(Credentials.new(
|
8
|
+
expect(Credentials.new(nil, 'something')).to be_blank
|
9
|
+
expect(Credentials.new('something', nil)).to be_blank
|
10
10
|
end
|
11
11
|
|
12
12
|
describe :from_request do
|
13
13
|
let(:request) { double.as_null_object }
|
14
14
|
|
15
15
|
let(:method) do
|
16
|
-
|
16
|
+
->(request) { return 'uid', 'secret' }
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'accepts anything that responds to #call' do
|
@@ -29,7 +29,7 @@ class Doorkeeper::OAuth::Client
|
|
29
29
|
it 'stops at the first credentials found' do
|
30
30
|
not_called_method = double
|
31
31
|
expect(not_called_method).not_to receive(:call)
|
32
|
-
credentials = Credentials.from_request request,
|
32
|
+
credentials = Credentials.from_request request, ->(r) {}, method, not_called_method
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'returns new Credentials' do
|
@@ -4,8 +4,8 @@ require 'doorkeeper/oauth/client'
|
|
4
4
|
|
5
5
|
class Doorkeeper::OAuth::Client
|
6
6
|
describe 'Methods' do
|
7
|
-
let(:client_id) {
|
8
|
-
let(:client_secret) {
|
7
|
+
let(:client_id) { 'some-uid' }
|
8
|
+
let(:client_secret) { 'some-secret' }
|
9
9
|
|
10
10
|
subject do
|
11
11
|
Class.new do
|
@@ -15,15 +15,15 @@ class Doorkeeper::OAuth::Client
|
|
15
15
|
|
16
16
|
describe :from_params do
|
17
17
|
it 'returns credentials from parameters when Authorization header is not available' do
|
18
|
-
request = double :
|
18
|
+
request = double parameters: { client_id: client_id, client_secret: client_secret }
|
19
19
|
uid, secret = subject.from_params(request)
|
20
20
|
|
21
|
-
expect(uid).to eq(
|
22
|
-
expect(secret).to eq(
|
21
|
+
expect(uid).to eq('some-uid')
|
22
|
+
expect(secret).to eq('some-secret')
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'is blank when there are no credentials' do
|
26
|
-
request = double :
|
26
|
+
request = double parameters: {}
|
27
27
|
uid, secret = subject.from_params(request)
|
28
28
|
|
29
29
|
expect(uid).to be_blank
|
@@ -35,15 +35,15 @@ class Doorkeeper::OAuth::Client
|
|
35
35
|
let(:credentials) { Base64.encode64("#{client_id}:#{client_secret}") }
|
36
36
|
|
37
37
|
it 'decodes the credentials' do
|
38
|
-
request = double :
|
38
|
+
request = double authorization: "Basic #{credentials}"
|
39
39
|
uid, secret = subject.from_basic(request)
|
40
40
|
|
41
|
-
expect(uid).to eq(
|
42
|
-
expect(secret).to eq(
|
41
|
+
expect(uid).to eq('some-uid')
|
42
|
+
expect(secret).to eq('some-secret')
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'is blank if Authorization is not Basic' do
|
46
|
-
request = double :
|
46
|
+
request = double authorization: "#{credentials}"
|
47
47
|
uid, secret = subject.from_basic(request)
|
48
48
|
|
49
49
|
expect(uid).to be_blank
|
@@ -5,13 +5,13 @@ require 'doorkeeper/oauth/client_credentials/issuer'
|
|
5
5
|
class Doorkeeper::OAuth::ClientCredentialsRequest
|
6
6
|
describe Issuer do
|
7
7
|
let(:creator) { double :acces_token_creator }
|
8
|
-
let(:server) { double :server, :
|
9
|
-
let(:validation) { double :validation,
|
8
|
+
let(:server) { double :server, access_token_expires_in: 100 }
|
9
|
+
let(:validation) { double :validation, valid?: true }
|
10
10
|
|
11
11
|
subject { Issuer.new(server, validation) }
|
12
12
|
|
13
13
|
describe :create do
|
14
|
-
let(:client) { double :client, :
|
14
|
+
let(:client) { double :client, id: 'some-id' }
|
15
15
|
let(:scopes) { 'some scope' }
|
16
16
|
|
17
17
|
it 'creates and sets the token' do
|
@@ -22,10 +22,12 @@ class Doorkeeper::OAuth::ClientCredentialsRequest
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'creates with correct token parameters' do
|
25
|
-
expect(creator).to receive(:call).with(
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
expect(creator).to receive(:call).with(
|
26
|
+
client,
|
27
|
+
scopes,
|
28
|
+
expires_in: 100,
|
29
|
+
use_refresh_token: false
|
30
|
+
)
|
29
31
|
|
30
32
|
subject.create client, scopes, creator
|
31
33
|
end
|
@@ -4,8 +4,8 @@ require 'doorkeeper/oauth/client_credentials/validation'
|
|
4
4
|
|
5
5
|
class Doorkeeper::OAuth::ClientCredentialsRequest
|
6
6
|
describe Validation do
|
7
|
-
let(:server) { double :server, :
|
8
|
-
let(:request) { double :request, :
|
7
|
+
let(:server) { double :server, scopes: nil }
|
8
|
+
let(:request) { double :request, client: double, original_scopes: nil }
|
9
9
|
|
10
10
|
subject { Validation.new(server, request) }
|
11
11
|
|
@@ -5,9 +5,9 @@ require 'doorkeeper/oauth/client_credentials_request'
|
|
5
5
|
|
6
6
|
module Doorkeeper::OAuth
|
7
7
|
describe ClientCredentialsRequest do
|
8
|
-
let(:server) { double :
|
8
|
+
let(:server) { double default_scopes: nil }
|
9
9
|
let(:client) { double }
|
10
|
-
let(:token_creator) { double :issuer, :
|
10
|
+
let(:token_creator) { double :issuer, create: true, token: double }
|
11
11
|
|
12
12
|
subject { ClientCredentialsRequest.new(server, client) }
|
13
13
|
|
@@ -27,7 +27,7 @@ module Doorkeeper::OAuth
|
|
27
27
|
|
28
28
|
context 'if issue was not created' do
|
29
29
|
before do
|
30
|
-
subject.issuer = double :
|
30
|
+
subject.issuer = double create: false, error: :invalid
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'has an error response' do
|
@@ -42,7 +42,7 @@ module Doorkeeper::OAuth
|
|
42
42
|
end
|
43
43
|
|
44
44
|
context 'with scopes' do
|
45
|
-
let(:default_scopes) { Doorkeeper::OAuth::Scopes.from_string(
|
45
|
+
let(:default_scopes) { Doorkeeper::OAuth::Scopes.from_string('public email') }
|
46
46
|
|
47
47
|
before do
|
48
48
|
allow(server).to receive(:default_scopes).and_return(default_scopes)
|
@@ -54,9 +54,9 @@ module Doorkeeper::OAuth
|
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'issues an access token with requested scopes' do
|
57
|
-
subject = ClientCredentialsRequest.new(server, client, :
|
57
|
+
subject = ClientCredentialsRequest.new(server, client, scope: 'email')
|
58
58
|
subject.issuer = token_creator
|
59
|
-
expect(token_creator).to receive(:create).with(client, Doorkeeper::OAuth::Scopes.from_string(
|
59
|
+
expect(token_creator).to receive(:create).with(client, Doorkeeper::OAuth::Scopes.from_string('email'))
|
60
60
|
subject.authorize
|
61
61
|
end
|
62
62
|
end
|
@@ -22,16 +22,16 @@ module Doorkeeper::OAuth
|
|
22
22
|
|
23
23
|
describe :authenticate do
|
24
24
|
it 'returns the authenticated client via credentials' do
|
25
|
-
credentials = Client::Credentials.new(
|
25
|
+
credentials = Client::Credentials.new('some-uid', 'some-secret')
|
26
26
|
authenticator = double
|
27
|
-
expect(authenticator).to receive(:call).with(
|
27
|
+
expect(authenticator).to receive(:call).with('some-uid', 'some-secret').and_return(double)
|
28
28
|
expect(Client.authenticate(credentials, authenticator)).to be_a(Client)
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'retunrs nil if client was not authenticated' do
|
32
|
-
credentials = Client::Credentials.new(
|
32
|
+
credentials = Client::Credentials.new('some-uid', 'some-secret')
|
33
33
|
authenticator = double
|
34
|
-
expect(authenticator).to receive(:call).with(
|
34
|
+
expect(authenticator).to receive(:call).with('some-uid', 'some-secret').and_return(nil)
|
35
35
|
expect(Client.authenticate(credentials, authenticator)).to be_nil
|
36
36
|
end
|
37
37
|
end
|
@@ -3,17 +3,18 @@ require 'spec_helper_integration'
|
|
3
3
|
module Doorkeeper::OAuth
|
4
4
|
describe CodeRequest do
|
5
5
|
let(:pre_auth) do
|
6
|
-
double(
|
7
|
-
:
|
8
|
-
:
|
9
|
-
:
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
13
|
-
|
6
|
+
double(
|
7
|
+
:pre_auth,
|
8
|
+
client: double(:application, id: 9990),
|
9
|
+
redirect_uri: 'http://tst.com/cb',
|
10
|
+
scopes: nil,
|
11
|
+
state: nil,
|
12
|
+
error: nil,
|
13
|
+
authorizable?: true
|
14
|
+
)
|
14
15
|
end
|
15
16
|
|
16
|
-
let(:owner) { double :owner, :
|
17
|
+
let(:owner) { double :owner, id: 8900 }
|
17
18
|
|
18
19
|
subject do
|
19
20
|
CodeRequest.new(pre_auth, owner)
|
@@ -13,28 +13,28 @@ module Doorkeeper::OAuth
|
|
13
13
|
|
14
14
|
describe :from_request do
|
15
15
|
it 'has the error from request' do
|
16
|
-
error = ErrorResponse.from_request double(:
|
16
|
+
error = ErrorResponse.from_request double(error: :some_error)
|
17
17
|
expect(error.name).to eq(:some_error)
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'ignores state if request does not respond to state' do
|
21
|
-
error = ErrorResponse.from_request double(:
|
21
|
+
error = ErrorResponse.from_request double(error: :some_error)
|
22
22
|
expect(error.state).to be_nil
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'has state if request responds to state' do
|
26
|
-
error = ErrorResponse.from_request double(:
|
26
|
+
error = ErrorResponse.from_request double(error: :some_error, state: :hello)
|
27
27
|
expect(error.state).to eq(:hello)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'ignores empty error values' do
|
32
|
-
subject = ErrorResponse.new(:
|
32
|
+
subject = ErrorResponse.new(error: :some_error, state: nil)
|
33
33
|
expect(subject.body).not_to have_key(:state)
|
34
34
|
end
|
35
35
|
|
36
36
|
describe '.body' do
|
37
|
-
subject { ErrorResponse.new(:
|
37
|
+
subject { ErrorResponse.new(name: :some_error, state: :some_state).body }
|
38
38
|
|
39
39
|
describe '#body' do
|
40
40
|
it { should have_key(:error) }
|
@@ -44,7 +44,7 @@ module Doorkeeper::OAuth
|
|
44
44
|
end
|
45
45
|
|
46
46
|
describe '.authenticate_info' do
|
47
|
-
let(:error_response) { ErrorResponse.new(:
|
47
|
+
let(:error_response) { ErrorResponse.new(name: :some_error, state: :some_state) }
|
48
48
|
subject { error_response.authenticate_info }
|
49
49
|
|
50
50
|
it { should include("realm=\"#{error_response.realm}\"") }
|
@@ -53,9 +53,9 @@ module Doorkeeper::OAuth
|
|
53
53
|
end
|
54
54
|
|
55
55
|
describe '.headers' do
|
56
|
-
subject { ErrorResponse.new(:
|
56
|
+
subject { ErrorResponse.new(name: :some_error, state: :some_state).headers }
|
57
57
|
|
58
|
-
it { should include
|
58
|
+
it { should include 'WWW-Authenticate' }
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -11,7 +11,7 @@ module Doorkeeper::OAuth
|
|
11
11
|
|
12
12
|
describe :description do
|
13
13
|
it 'is translated from translation messages' do
|
14
|
-
expect(I18n).to receive(:translate).with(:some_error, :
|
14
|
+
expect(I18n).to receive(:translate).with(:some_error, scope: [:doorkeeper, :errors, :messages])
|
15
15
|
subject.description
|
16
16
|
end
|
17
17
|
end
|
@@ -4,71 +4,71 @@ require 'doorkeeper/oauth/helpers/scope_checker'
|
|
4
4
|
require 'doorkeeper/oauth/scopes'
|
5
5
|
|
6
6
|
module Doorkeeper::OAuth::Helpers
|
7
|
-
describe ScopeChecker,
|
7
|
+
describe ScopeChecker, '.matches?' do
|
8
8
|
def new_scope(*args)
|
9
9
|
Doorkeeper::OAuth::Scopes.from_array args
|
10
10
|
end
|
11
11
|
|
12
|
-
it
|
12
|
+
it 'true if scopes matches' do
|
13
13
|
scopes = new_scope :public
|
14
14
|
scopes_to_match = new_scope :public
|
15
15
|
expect(ScopeChecker.matches?(scopes, scopes_to_match)).to be_true
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
18
|
+
it 'is false when scopes differs' do
|
19
19
|
scopes = new_scope :public
|
20
20
|
scopes_to_match = new_scope :write
|
21
21
|
expect(ScopeChecker.matches?(scopes, scopes_to_match)).to be_false
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
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
27
|
expect(ScopeChecker.matches?(scopes, scopes_to_match)).to be_false
|
28
28
|
end
|
29
29
|
|
30
|
-
it
|
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
33
|
expect(ScopeChecker.matches?(scopes, scopes_to_match)).to be_false
|
34
34
|
end
|
35
35
|
|
36
|
-
it
|
36
|
+
it 'is false when any of attributes is nil' do
|
37
37
|
expect(ScopeChecker.matches?(nil, double)).to be_false
|
38
38
|
expect(ScopeChecker.matches?(double, nil)).to be_false
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
describe ScopeChecker,
|
42
|
+
describe ScopeChecker, '.valid?' do
|
43
43
|
let(:server_scopes) { Doorkeeper::OAuth::Scopes.new }
|
44
44
|
|
45
|
-
it
|
45
|
+
it 'is valid if scope is present' do
|
46
46
|
server_scopes.add :scope
|
47
|
-
expect(ScopeChecker.valid?(
|
47
|
+
expect(ScopeChecker.valid?('scope', server_scopes)).to be_true
|
48
48
|
end
|
49
49
|
|
50
|
-
it
|
50
|
+
it 'is invalid if includes tabs space' do
|
51
51
|
expect(ScopeChecker.valid?("\tsomething", server_scopes)).to be_false
|
52
52
|
end
|
53
53
|
|
54
|
-
it
|
54
|
+
it 'is invalid if scope is not present' do
|
55
55
|
expect(ScopeChecker.valid?(nil, server_scopes)).to be_false
|
56
56
|
end
|
57
57
|
|
58
|
-
it
|
59
|
-
expect(ScopeChecker.valid?(
|
58
|
+
it 'is invalid if scope is blank' do
|
59
|
+
expect(ScopeChecker.valid?(' ', server_scopes)).to be_false
|
60
60
|
end
|
61
61
|
|
62
|
-
it
|
62
|
+
it 'is invalid if includes return space' do
|
63
63
|
expect(ScopeChecker.valid?("scope\r", server_scopes)).to be_false
|
64
64
|
end
|
65
65
|
|
66
|
-
it
|
66
|
+
it 'is invalid if includes new lines' do
|
67
67
|
expect(ScopeChecker.valid?("scope\nanother", server_scopes)).to be_false
|
68
68
|
end
|
69
69
|
|
70
|
-
it
|
71
|
-
expect(ScopeChecker.valid?(
|
70
|
+
it 'is invalid if any scope is not included in server scopes' do
|
71
|
+
expect(ScopeChecker.valid?('scope another', server_scopes)).to be_false
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
@@ -4,17 +4,17 @@ require 'doorkeeper/oauth/helpers/unique_token'
|
|
4
4
|
module Doorkeeper::OAuth::Helpers
|
5
5
|
describe UniqueToken do
|
6
6
|
let :generator do
|
7
|
-
|
7
|
+
->(size) { 'a' * size }
|
8
8
|
end
|
9
9
|
|
10
|
-
it
|
11
|
-
token = UniqueToken.generate(:
|
12
|
-
expect(token).to eq(
|
10
|
+
it 'is able to customize the generator method' do
|
11
|
+
token = UniqueToken.generate(generator: generator)
|
12
|
+
expect(token).to eq('a' * 32)
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
16
|
-
token = UniqueToken.generate(:
|
17
|
-
expect(token).to eq(
|
15
|
+
it 'is able to customize the size of the token' do
|
16
|
+
token = UniqueToken.generate(generator: generator, size: 2)
|
17
|
+
expect(token).to eq('aa')
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|