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.

Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +2 -1
  3. data/lib/doorkeeper/version.rb +1 -1
  4. data/spec/controllers/applications_controller_spec.rb +4 -4
  5. data/spec/controllers/authorizations_controller_spec.rb +9 -9
  6. data/spec/controllers/protected_resources_controller_spec.rb +10 -10
  7. data/spec/controllers/token_info_controller_spec.rb +4 -4
  8. data/spec/controllers/tokens_controller_spec.rb +4 -4
  9. data/spec/lib/config_spec.rb +21 -21
  10. data/spec/lib/models/expirable_spec.rb +13 -13
  11. data/spec/lib/models/revocable_spec.rb +5 -5
  12. data/spec/lib/models/scopes_spec.rb +3 -3
  13. data/spec/lib/oauth/authorization/uri_builder_spec.rb +5 -5
  14. data/spec/lib/oauth/authorization_code_request_spec.rb +7 -7
  15. data/spec/lib/oauth/client/credentials_spec.rb +8 -8
  16. data/spec/lib/oauth/client/methods_spec.rb +8 -8
  17. data/spec/lib/oauth/client_credentials/creator_spec.rb +2 -2
  18. data/spec/lib/oauth/client_credentials/issuer_spec.rb +10 -9
  19. data/spec/lib/oauth/client_credentials/validation_spec.rb +6 -6
  20. data/spec/lib/oauth/client_credentials_request_spec.rb +7 -7
  21. data/spec/lib/oauth/client_spec.rb +8 -8
  22. data/spec/lib/oauth/code_request_spec.rb +4 -4
  23. data/spec/lib/oauth/error_response_spec.rb +22 -15
  24. data/spec/lib/oauth/error_spec.rb +1 -1
  25. data/spec/lib/oauth/helpers/scope_checker_spec.rb +13 -13
  26. data/spec/lib/oauth/helpers/unique_token_spec.rb +2 -2
  27. data/spec/lib/oauth/helpers/uri_checker_spec.rb +13 -13
  28. data/spec/lib/oauth/invalid_token_response_spec.rb +9 -4
  29. data/spec/lib/oauth/password_access_token_request_spec.rb +7 -7
  30. data/spec/lib/oauth/pre_authorization_spec.rb +14 -14
  31. data/spec/lib/oauth/refresh_token_request_spec.rb +8 -8
  32. data/spec/lib/oauth/scopes_spec.rb +27 -19
  33. data/spec/lib/oauth/token_request_spec.rb +4 -4
  34. data/spec/lib/oauth/token_response_spec.rb +11 -11
  35. data/spec/lib/oauth/token_spec.rb +9 -9
  36. data/spec/lib/server_spec.rb +1 -1
  37. data/spec/models/doorkeeper/access_token_spec.rb +15 -15
  38. data/spec/models/doorkeeper/application_spec.rb +21 -21
  39. data/spec/requests/flows/authorization_code_spec.rb +1 -1
  40. data/spec/requests/flows/client_credentials_spec.rb +1 -1
  41. data/spec/requests/flows/refresh_token_spec.rb +6 -6
  42. data/spec/requests/protected_resources/private_api_spec.rb +3 -3
  43. data/spec/routing/custom_controller_routes_spec.rb +16 -16
  44. data/spec/routing/default_routes_spec.rb +7 -7
  45. data/spec/routing/scoped_routes_spec.rb +7 -7
  46. data/spec/support/helpers/authorization_request_helper.rb +3 -3
  47. data/spec/support/helpers/model_helper.rb +6 -6
  48. data/spec/support/helpers/request_spec_helper.rb +9 -9
  49. data/spec/support/shared/controllers_shared_context.rb +6 -6
  50. data/spec/support/shared/models_shared_examples.rb +6 -6
  51. data/spec/validators/redirect_uri_validator_spec.rb +12 -12
  52. metadata +4 -4
@@ -12,20 +12,20 @@ describe 'Revocable' do
12
12
  describe :revoke do
13
13
  it "updates :revoked_at attribute with current time" do
14
14
  clock = double :now => double
15
- subject.should_receive(:update_column).with(:revoked_at, clock.now)
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
21
  it "is revoked if :revoked_at is set" do
22
- subject.stub :revoked_at => double
23
- subject.should be_revoked
22
+ allow(subject).to receive(:revoked_at).and_return(double)
23
+ expect(subject).to be_revoked
24
24
  end
25
25
 
26
26
  it "is not revoked if :revoked_at is not set" do
27
- subject.stub :revoked_at => nil
28
- subject.should_not be_revoked
27
+ allow(subject).to receive(:revoked_at).and_return(nil)
28
+ expect(subject).not_to be_revoked
29
29
  end
30
30
  end
31
31
  end
@@ -16,17 +16,17 @@ describe 'Doorkeeper::Models::Scopes' do
16
16
 
17
17
  describe :scopes do
18
18
  it 'is a `Scopes` class' do
19
- subject.scopes.should be_a(Doorkeeper::OAuth::Scopes)
19
+ expect(subject.scopes).to be_a(Doorkeeper::OAuth::Scopes)
20
20
  end
21
21
 
22
22
  it 'includes scopes' do
23
- subject.scopes.should include('public')
23
+ expect(subject.scopes).to include('public')
24
24
  end
25
25
  end
26
26
 
27
27
  describe :scopes_string do
28
28
  it 'is a `Scopes` class' do
29
- subject.scopes_string.should == 'public admin'
29
+ expect(subject.scopes_string).to eq('public admin')
30
30
  end
31
31
  end
32
32
  end
@@ -12,25 +12,25 @@ module Doorkeeper::OAuth::Authorization
12
12
  describe :uri_with_query do
13
13
  it 'returns the uri with query' do
14
14
  uri = subject.uri_with_query 'http://example.com/', :parameter => 'value'
15
- uri.should == 'http://example.com/?parameter=value'
15
+ expect(uri).to eq('http://example.com/?parameter=value')
16
16
  end
17
17
 
18
18
  it 'rejects nil values' do
19
19
  uri = subject.uri_with_query 'http://example.com/', :parameter => ""
20
- uri.should == 'http://example.com/?'
20
+ expect(uri).to eq('http://example.com/?')
21
21
  end
22
22
 
23
23
  it 'preserves original query parameters' do
24
24
  uri = subject.uri_with_query 'http://example.com/?query1=value', :parameter => 'value'
25
- uri.should =~ /query1=value/
26
- uri.should =~ /parameter=value/
25
+ expect(uri).to match(/query1=value/)
26
+ expect(uri).to match(/parameter=value/)
27
27
  end
28
28
  end
29
29
 
30
30
  describe :uri_with_fragment do
31
31
  it 'returns uri with parameters as fragments' do
32
32
  uri = subject.uri_with_fragment 'http://example.com/', :parameter => 'value'
33
- uri.should == 'http://example.com/#parameter=value'
33
+ expect(uri).to eq('http://example.com/#parameter=value')
34
34
  end
35
35
  end
36
36
  end
@@ -18,7 +18,7 @@ module Doorkeeper::OAuth
18
18
 
19
19
  it "issues the token with same grant's scopes" do
20
20
  subject.authorize
21
- Doorkeeper::AccessToken.last.scopes.should == grant.scopes
21
+ expect(Doorkeeper::AccessToken.last.scopes).to eq(grant.scopes)
22
22
  end
23
23
 
24
24
  it 'revokes the grant' do
@@ -30,37 +30,37 @@ module Doorkeeper::OAuth
30
30
  it 'requires the grant to be accessible' do
31
31
  grant.revoke
32
32
  subject.validate
33
- subject.error.should == :invalid_grant
33
+ expect(subject.error).to eq(:invalid_grant)
34
34
  end
35
35
 
36
36
  it 'requires the grant' do
37
37
  subject.grant = nil
38
38
  subject.validate
39
- subject.error.should == :invalid_grant
39
+ expect(subject.error).to eq(:invalid_grant)
40
40
  end
41
41
 
42
42
  it 'requires the client' do
43
43
  subject.client = nil
44
44
  subject.validate
45
- subject.error.should == :invalid_client
45
+ expect(subject.error).to eq(:invalid_client)
46
46
  end
47
47
 
48
48
  it 'requires the redirect_uri' do
49
49
  subject.redirect_uri = nil
50
50
  subject.validate
51
- subject.error.should == :invalid_request
51
+ expect(subject.error).to eq(:invalid_request)
52
52
  end
53
53
 
54
54
  it "matches the redirect_uri with grant's one" do
55
55
  subject.redirect_uri = 'http://other.com'
56
56
  subject.validate
57
- subject.error.should == :invalid_grant
57
+ expect(subject.error).to eq(:invalid_grant)
58
58
  end
59
59
 
60
60
  it "matches the client with grant's one" do
61
61
  subject.client = FactoryGirl.create :application
62
62
  subject.validate
63
- subject.error.should == :invalid_grant
63
+ expect(subject.error).to eq(:invalid_grant)
64
64
  end
65
65
  end
66
66
  end
@@ -5,8 +5,8 @@ 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
- Credentials.new(nil, "something").should be_blank
9
- Credentials.new("something", nil).should be_blank
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
@@ -17,30 +17,30 @@ class Doorkeeper::OAuth::Client
17
17
  end
18
18
 
19
19
  it 'accepts anything that responds to #call' do
20
- method.should_receive(:call).with(request)
20
+ expect(method).to receive(:call).with(request)
21
21
  Credentials.from_request request, method
22
22
  end
23
23
 
24
24
  it 'delegates methods received as symbols to Credentials class' do
25
- Credentials.should_receive(:from_params).with(request)
25
+ expect(Credentials).to receive(:from_params).with(request)
26
26
  Credentials.from_request request, :from_params
27
27
  end
28
28
 
29
29
  it 'stops at the first credentials found' do
30
30
  not_called_method = double
31
- not_called_method.should_not_receive(:call)
31
+ expect(not_called_method).not_to receive(:call)
32
32
  credentials = Credentials.from_request request, lambda { |r| }, method, not_called_method
33
33
  end
34
34
 
35
35
  it 'returns new Credentials' do
36
36
  credentials = Credentials.from_request request, method
37
- credentials.should be_a(Credentials)
37
+ expect(credentials).to be_a(Credentials)
38
38
  end
39
39
 
40
40
  it 'returns uid and secret from extractor method' do
41
41
  credentials = Credentials.from_request request, method
42
- credentials.uid.should == 'uid'
43
- credentials.secret.should == 'secret'
42
+ expect(credentials.uid).to eq('uid')
43
+ expect(credentials.secret).to eq('secret')
44
44
  end
45
45
  end
46
46
  end
@@ -18,16 +18,16 @@ class Doorkeeper::OAuth::Client
18
18
  request = double :parameters => { :client_id => client_id, :client_secret => client_secret }
19
19
  uid, secret = subject.from_params(request)
20
20
 
21
- uid.should == "some-uid"
22
- secret.should == "some-secret"
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
26
  request = double :parameters => {}
27
27
  uid, secret = subject.from_params(request)
28
28
 
29
- uid.should be_blank
30
- secret.should be_blank
29
+ expect(uid).to be_blank
30
+ expect(secret).to be_blank
31
31
  end
32
32
  end
33
33
 
@@ -38,16 +38,16 @@ class Doorkeeper::OAuth::Client
38
38
  request = double :authorization => "Basic #{credentials}"
39
39
  uid, secret = subject.from_basic(request)
40
40
 
41
- uid.should == "some-uid"
42
- secret.should == "some-secret"
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
46
  request = double :authorization => "#{credentials}"
47
47
  uid, secret = subject.from_basic(request)
48
48
 
49
- uid.should be_blank
50
- secret.should be_blank
49
+ expect(uid).to be_blank
50
+ expect(secret).to be_blank
51
51
  end
52
52
  end
53
53
  end
@@ -12,9 +12,9 @@ class Doorkeeper::OAuth::ClientCredentialsRequest
12
12
  end
13
13
 
14
14
  it 'returns false if creation fails' do
15
- Doorkeeper::AccessToken.should_receive(:create).and_return(false)
15
+ expect(Doorkeeper::AccessToken).to receive(:create).and_return(false)
16
16
  created = subject.call(client, scopes)
17
- created.should be_false
17
+ expect(created).to be_false
18
18
  end
19
19
  end
20
20
  end
@@ -15,14 +15,14 @@ class Doorkeeper::OAuth::ClientCredentialsRequest
15
15
  let(:scopes) { 'some scope' }
16
16
 
17
17
  it 'creates and sets the token' do
18
- creator.should_receive(:call).and_return('token')
18
+ expect(creator).to receive(:call).and_return('token')
19
19
  subject.create client, scopes, creator
20
20
 
21
- subject.token.should == 'token'
21
+ expect(subject.token).to eq('token')
22
22
  end
23
23
 
24
24
  it 'creates with correct token parameters' do
25
- creator.should_receive(:call).with(client, scopes, {
25
+ expect(creator).to receive(:call).with(client, scopes, {
26
26
  :expires_in => 100,
27
27
  :use_refresh_token => false
28
28
  })
@@ -31,25 +31,26 @@ class Doorkeeper::OAuth::ClientCredentialsRequest
31
31
  end
32
32
 
33
33
  it 'has error set to :server_error if creator fails' do
34
- creator.should_receive(:call).and_return(false)
34
+ expect(creator).to receive(:call).and_return(false)
35
35
  subject.create client, scopes, creator
36
36
 
37
- subject.error.should == :server_error
37
+ expect(subject.error).to eq(:server_error)
38
38
  end
39
39
 
40
40
  context 'when validation fails' do
41
41
  before do
42
- validation.stub :valid? => false, :error => :validation_error
43
- creator.should_not_receive(:create)
42
+ allow(validation).to receive(:valid?).and_return(false)
43
+ allow(validation).to receive(:error).and_return(:validation_error)
44
+ expect(creator).not_to receive(:create)
44
45
  end
45
46
 
46
47
  it 'has error set from validation' do
47
48
  subject.create client, scopes, creator
48
- subject.error.should == :validation_error
49
+ expect(subject.error).to eq(:validation_error)
49
50
  end
50
51
 
51
52
  it 'returns false' do
52
- subject.create(client, scopes, creator).should be_false
53
+ expect(subject.create(client, scopes, creator)).to be_false
53
54
  end
54
55
  end
55
56
  end
@@ -10,19 +10,19 @@ class Doorkeeper::OAuth::ClientCredentialsRequest
10
10
  subject { Validation.new(server, request) }
11
11
 
12
12
  it 'is valid with valid request' do
13
- subject.should be_valid
13
+ expect(subject).to be_valid
14
14
  end
15
15
 
16
16
  it 'is invalid when client is not present' do
17
- request.stub :client => nil
18
- subject.should_not be_valid
17
+ allow(request).to receive(:client).and_return(nil)
18
+ expect(subject).not_to be_valid
19
19
  end
20
20
 
21
21
  context 'with scopes' do
22
22
  it 'is invalid when scopes are not included in the server' do
23
- server.stub :scopes => Doorkeeper::OAuth::Scopes.from_string('email')
24
- request.stub :original_scopes => 'invalid'
25
- subject.should_not be_valid
23
+ allow(server).to receive(:scopes).and_return(Doorkeeper::OAuth::Scopes.from_string('email'))
24
+ allow(request).to receive(:original_scopes).and_return('invalid')
25
+ expect(subject).not_to be_valid
26
26
  end
27
27
  end
28
28
  end
@@ -16,13 +16,13 @@ module Doorkeeper::OAuth
16
16
  end
17
17
 
18
18
  it 'issues an access token for the current client' do
19
- token_creator.should_receive(:create).with(client, nil)
19
+ expect(token_creator).to receive(:create).with(client, nil)
20
20
  subject.authorize
21
21
  end
22
22
 
23
23
  it 'has successful response when issue was created' do
24
24
  subject.authorize
25
- subject.response.should be_a(TokenResponse)
25
+ expect(subject.response).to be_a(TokenResponse)
26
26
  end
27
27
 
28
28
  context 'if issue was not created' do
@@ -32,12 +32,12 @@ module Doorkeeper::OAuth
32
32
 
33
33
  it 'has an error response' do
34
34
  subject.authorize
35
- subject.response.should be_a(Doorkeeper::OAuth::ErrorResponse)
35
+ expect(subject.response).to be_a(Doorkeeper::OAuth::ErrorResponse)
36
36
  end
37
37
 
38
38
  it 'delegates the error to issuer' do
39
39
  subject.authorize
40
- subject.error.should == :invalid
40
+ expect(subject.error).to eq(:invalid)
41
41
  end
42
42
  end
43
43
 
@@ -45,18 +45,18 @@ module Doorkeeper::OAuth
45
45
  let(:default_scopes) { Doorkeeper::OAuth::Scopes.from_string("public email") }
46
46
 
47
47
  before do
48
- server.stub(:default_scopes).and_return(default_scopes)
48
+ allow(server).to receive(:default_scopes).and_return(default_scopes)
49
49
  end
50
50
 
51
51
  it 'issues an access token with default scopes if none was requested' do
52
- token_creator.should_receive(:create).with(client, default_scopes)
52
+ expect(token_creator).to receive(:create).with(client, default_scopes)
53
53
  subject.authorize
54
54
  end
55
55
 
56
56
  it 'issues an access token with requested scopes' do
57
57
  subject = ClientCredentialsRequest.new(server, client, :scope => "email")
58
58
  subject.issuer = token_creator
59
- token_creator.should_receive(:create).with(client, Doorkeeper::OAuth::Scopes.from_string("email"))
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
@@ -10,13 +10,13 @@ module Doorkeeper::OAuth
10
10
 
11
11
  it 'finds the client via uid' do
12
12
  client = double
13
- method.should_receive(:call).with('uid').and_return(client)
14
- Client.find('uid', method).should be_a(Client)
13
+ expect(method).to receive(:call).with('uid').and_return(client)
14
+ expect(Client.find('uid', method)).to be_a(Client)
15
15
  end
16
16
 
17
17
  it 'returns nil if client was not found' do
18
- method.should_receive(:call).with('uid').and_return(nil)
19
- Client.find('uid', method).should be_nil
18
+ expect(method).to receive(:call).with('uid').and_return(nil)
19
+ expect(Client.find('uid', method)).to be_nil
20
20
  end
21
21
  end
22
22
 
@@ -24,15 +24,15 @@ module Doorkeeper::OAuth
24
24
  it 'returns the authenticated client via credentials' do
25
25
  credentials = Client::Credentials.new("some-uid", "some-secret")
26
26
  authenticator = double
27
- authenticator.should_receive(:call).with("some-uid", "some-secret").and_return(double)
28
- Client.authenticate(credentials, authenticator).should be_a(Client)
27
+ expect(authenticator).to receive(:call).with("some-uid", "some-secret").and_return(double)
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
32
  credentials = Client::Credentials.new("some-uid", "some-secret")
33
33
  authenticator = double
34
- authenticator.should_receive(:call).with("some-uid", "some-secret").and_return(nil)
35
- Client.authenticate(credentials, authenticator).should be_nil
34
+ expect(authenticator).to receive(:call).with("some-uid", "some-secret").and_return(nil)
35
+ expect(Client.authenticate(credentials, authenticator)).to be_nil
36
36
  end
37
37
  end
38
38
  end
@@ -26,19 +26,19 @@ module Doorkeeper::OAuth
26
26
  end
27
27
 
28
28
  it 'returns a code response' do
29
- subject.authorize.should be_a(CodeResponse)
29
+ expect(subject.authorize).to be_a(CodeResponse)
30
30
  end
31
31
 
32
32
  it 'does not create grant when not authorizable' do
33
- pre_auth.stub :authorizable? => false
33
+ allow(pre_auth).to receive(:authorizable?).and_return(false)
34
34
  expect do
35
35
  subject.authorize
36
36
  end.to_not change { Doorkeeper::AccessGrant.count }
37
37
  end
38
38
 
39
39
  it 'returns a error response' do
40
- pre_auth.stub :authorizable? => false
41
- subject.authorize.should be_a(ErrorResponse)
40
+ allow(pre_auth).to receive(:authorizable?).and_return(false)
41
+ expect(subject.authorize).to be_a(ErrorResponse)
42
42
  end
43
43
  end
44
44
  end
@@ -5,50 +5,57 @@ require 'doorkeeper/oauth/error_response'
5
5
 
6
6
  module Doorkeeper::OAuth
7
7
  describe ErrorResponse do
8
- its(:status) { should == :unauthorized }
8
+ describe '#status' do
9
+ it 'should have a status of unauthorized' do
10
+ expect(subject.status).to eq(:unauthorized)
11
+ end
12
+ end
9
13
 
10
14
  describe :from_request do
11
15
  it 'has the error from request' do
12
16
  error = ErrorResponse.from_request double(:error => :some_error)
13
- error.name.should == :some_error
17
+ expect(error.name).to eq(:some_error)
14
18
  end
15
19
 
16
20
  it 'ignores state if request does not respond to state' do
17
21
  error = ErrorResponse.from_request double(:error => :some_error)
18
- error.state.should be_nil
22
+ expect(error.state).to be_nil
19
23
  end
20
24
 
21
25
  it 'has state if request responds to state' do
22
26
  error = ErrorResponse.from_request double(:error => :some_error, :state => :hello)
23
- error.state.should == :hello
27
+ expect(error.state).to eq(:hello)
24
28
  end
25
29
  end
26
30
 
27
31
  it 'ignores empty error values' do
28
32
  subject = ErrorResponse.new(:error => :some_error, :state => nil)
29
- subject.body.should_not have_key(:state)
33
+ expect(subject.body).not_to have_key(:state)
30
34
  end
31
35
 
32
36
  describe '.body' do
33
- subject { ErrorResponse.new(:name => :some_error, :state => :some_state) }
37
+ subject { ErrorResponse.new(:name => :some_error, :state => :some_state).body }
34
38
 
35
- its(:body) { should have_key(:error) }
36
- its(:body) { should have_key(:error_description) }
37
- its(:body) { should have_key(:state) }
39
+ describe '#body' do
40
+ it { should have_key(:error) }
41
+ it { should have_key(:error_description) }
42
+ it { should have_key(:state) }
43
+ end
38
44
  end
39
45
 
40
46
  describe '.authenticate_info' do
41
- subject { ErrorResponse.new(:name => :some_error, :state => :some_state) }
47
+ let(:error_response) { ErrorResponse.new(:name => :some_error, :state => :some_state) }
48
+ subject { error_response.authenticate_info }
42
49
 
43
- its(:authenticate_info) { should include("realm=\"#{subject.realm}\"") }
44
- its(:authenticate_info) { should include("error=\"#{subject.name}\"") }
45
- its(:authenticate_info) { should include("error_description=\"#{subject.description}\"") }
50
+ it { should include("realm=\"#{error_response.realm}\"") }
51
+ it { should include("error=\"#{error_response.name}\"") }
52
+ it { should include("error_description=\"#{error_response.description}\"") }
46
53
  end
47
54
 
48
55
  describe '.headers' do
49
- subject { ErrorResponse.new(:name => :some_error, :state => :some_state) }
56
+ subject { ErrorResponse.new(:name => :some_error, :state => :some_state).headers }
50
57
 
51
- its(:headers) { should include "WWW-Authenticate" }
58
+ it { should include "WWW-Authenticate" }
52
59
  end
53
60
  end
54
61
  end