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.

Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -2
  3. data/CHANGELOG.md +14 -2
  4. data/README.md +93 -42
  5. data/app/controllers/doorkeeper/application_controller.rb +1 -1
  6. data/app/controllers/doorkeeper/applications_controller.rb +4 -4
  7. data/app/controllers/doorkeeper/authorizations_controller.rb +3 -3
  8. data/app/controllers/doorkeeper/authorized_applications_controller.rb +1 -1
  9. data/app/controllers/doorkeeper/token_info_controller.rb +3 -3
  10. data/app/controllers/doorkeeper/tokens_controller.rb +29 -2
  11. data/app/helpers/doorkeeper/form_errors_helper.rb +2 -2
  12. data/app/validators/redirect_uri_validator.rb +1 -1
  13. data/app/views/doorkeeper/applications/_form.html.erb +3 -3
  14. data/app/views/doorkeeper/applications/edit.html.erb +1 -1
  15. data/app/views/doorkeeper/applications/new.html.erb +1 -1
  16. data/app/views/doorkeeper/applications/show.html.erb +1 -1
  17. data/app/views/doorkeeper/authorizations/new.html.erb +5 -5
  18. data/doorkeeper.gemspec +1 -1
  19. data/lib/doorkeeper.rb +31 -31
  20. data/lib/doorkeeper/config.rb +66 -37
  21. data/lib/doorkeeper/doorkeeper_for.rb +6 -3
  22. data/lib/doorkeeper/engine.rb +2 -2
  23. data/lib/doorkeeper/helpers/controller.rb +9 -9
  24. data/lib/doorkeeper/helpers/filter.rb +1 -1
  25. data/lib/doorkeeper/models/access_grant.rb +5 -5
  26. data/lib/doorkeeper/models/access_token.rb +22 -18
  27. data/lib/doorkeeper/models/active_record/access_token.rb +8 -8
  28. data/lib/doorkeeper/models/active_record/application.rb +5 -5
  29. data/lib/doorkeeper/models/application.rb +8 -9
  30. data/lib/doorkeeper/models/expirable.rb +1 -1
  31. data/lib/doorkeeper/models/mongo_mapper/access_grant.rb +2 -2
  32. data/lib/doorkeeper/models/mongo_mapper/access_token.rb +11 -11
  33. data/lib/doorkeeper/models/mongo_mapper/application.rb +4 -4
  34. data/lib/doorkeeper/models/mongoid/version.rb +2 -2
  35. data/lib/doorkeeper/models/mongoid2/access_grant.rb +7 -7
  36. data/lib/doorkeeper/models/mongoid2/access_token.rb +14 -14
  37. data/lib/doorkeeper/models/mongoid2/application.rb +7 -7
  38. data/lib/doorkeeper/models/mongoid3_4/access_grant.rb +7 -7
  39. data/lib/doorkeeper/models/mongoid3_4/access_token.rb +13 -13
  40. data/lib/doorkeeper/models/mongoid3_4/application.rb +6 -6
  41. data/lib/doorkeeper/models/ownership.rb +5 -5
  42. data/lib/doorkeeper/oauth/authorization/code.rb +5 -5
  43. data/lib/doorkeeper/oauth/authorization/token.rb +7 -7
  44. data/lib/doorkeeper/oauth/authorization_code_request.rb +18 -19
  45. data/lib/doorkeeper/oauth/client.rb +1 -1
  46. data/lib/doorkeeper/oauth/client_credentials/creator.rb +4 -4
  47. data/lib/doorkeeper/oauth/client_credentials/issuer.rb +6 -4
  48. data/lib/doorkeeper/oauth/client_credentials/validation.rb +2 -2
  49. data/lib/doorkeeper/oauth/client_credentials_request.rb +11 -15
  50. data/lib/doorkeeper/oauth/code_request.rb +5 -4
  51. data/lib/doorkeeper/oauth/code_response.rb +8 -7
  52. data/lib/doorkeeper/oauth/error.rb +1 -1
  53. data/lib/doorkeeper/oauth/error_response.rb +5 -5
  54. data/lib/doorkeeper/oauth/helpers/uri_checker.rb +1 -1
  55. data/lib/doorkeeper/oauth/invalid_token_response.rb +10 -10
  56. data/lib/doorkeeper/oauth/password_access_token_request.rb +57 -54
  57. data/lib/doorkeeper/oauth/pre_authorization.rb +7 -7
  58. data/lib/doorkeeper/oauth/refresh_token_request.rb +27 -24
  59. data/lib/doorkeeper/oauth/scopes.rb +3 -3
  60. data/lib/doorkeeper/oauth/token.rb +27 -1
  61. data/lib/doorkeeper/oauth/token_request.rb +14 -4
  62. data/lib/doorkeeper/rails/routes.rb +31 -22
  63. data/lib/doorkeeper/rails/routes/mapping.rb +11 -12
  64. data/lib/doorkeeper/request.rb +5 -5
  65. data/lib/doorkeeper/version.rb +1 -1
  66. data/lib/generators/doorkeeper/application_owner_generator.rb +1 -1
  67. data/lib/generators/doorkeeper/install_generator.rb +5 -5
  68. data/lib/generators/doorkeeper/migration_generator.rb +1 -1
  69. data/lib/generators/doorkeeper/mongo_mapper/indexes_generator.rb +2 -2
  70. data/lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb +2 -2
  71. data/lib/generators/doorkeeper/templates/initializer.rb +16 -3
  72. data/lib/generators/doorkeeper/templates/migration.rb +16 -17
  73. data/lib/generators/doorkeeper/views_generator.rb +1 -1
  74. data/spec/controllers/applications_controller_spec.rb +7 -7
  75. data/spec/controllers/authorizations_controller_spec.rb +48 -48
  76. data/spec/controllers/protected_resources_controller_spec.rb +108 -107
  77. data/spec/controllers/token_info_controller_spec.rb +11 -11
  78. data/spec/controllers/tokens_controller_spec.rb +8 -8
  79. data/spec/dummy/app/controllers/custom_authorizations_controller.rb +2 -2
  80. data/spec/dummy/app/controllers/full_protected_resources_controller.rb +3 -3
  81. data/spec/dummy/app/controllers/home_controller.rb +5 -5
  82. data/spec/dummy/app/controllers/metal_controller.rb +1 -1
  83. data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +2 -2
  84. data/spec/dummy/app/models/user.rb +3 -3
  85. data/spec/dummy/config/application.rb +8 -9
  86. data/spec/dummy/config/boot.rb +1 -1
  87. data/spec/dummy/config/environments/test.rb +1 -1
  88. data/spec/dummy/config/initializers/doorkeeper.rb +5 -5
  89. data/spec/dummy/config/initializers/session_store.rb +1 -1
  90. data/spec/dummy/config/initializers/wrap_parameters.rb +1 -1
  91. data/spec/dummy/config/routes.rb +27 -27
  92. data/spec/dummy/db/migrate/20130902165751_create_doorkeeper_tables.rb +16 -17
  93. data/spec/dummy/db/migrate/20130902175349_add_owner_to_application.rb +3 -3
  94. data/spec/dummy/db/schema.rb +39 -39
  95. data/spec/factories/access_grant.rb +3 -3
  96. data/spec/factories/access_token.rb +1 -1
  97. data/spec/factories/application.rb +3 -3
  98. data/spec/generators/application_owner_generator_spec.rb +6 -7
  99. data/spec/generators/install_generator_spec.rb +9 -9
  100. data/spec/generators/migration_generator_spec.rb +4 -4
  101. data/spec/lib/config_spec.rb +136 -44
  102. data/spec/lib/models/expirable_spec.rb +9 -9
  103. data/spec/lib/models/revocable_spec.rb +4 -4
  104. data/spec/lib/oauth/authorization/uri_builder_spec.rb +4 -4
  105. data/spec/lib/oauth/authorization_code_request_spec.rb +2 -2
  106. data/spec/lib/oauth/client/credentials_spec.rb +4 -4
  107. data/spec/lib/oauth/client/methods_spec.rb +10 -10
  108. data/spec/lib/oauth/client_credentials/issuer_spec.rb +9 -7
  109. data/spec/lib/oauth/client_credentials/validation_spec.rb +2 -2
  110. data/spec/lib/oauth/client_credentials_request_spec.rb +6 -6
  111. data/spec/lib/oauth/client_spec.rb +4 -4
  112. data/spec/lib/oauth/code_request_spec.rb +10 -9
  113. data/spec/lib/oauth/error_response_spec.rb +8 -8
  114. data/spec/lib/oauth/error_spec.rb +1 -1
  115. data/spec/lib/oauth/helpers/scope_checker_spec.rb +17 -17
  116. data/spec/lib/oauth/helpers/unique_token_spec.rb +7 -7
  117. data/spec/lib/oauth/helpers/uri_checker_spec.rb +33 -33
  118. data/spec/lib/oauth/invalid_token_response_spec.rb +4 -4
  119. data/spec/lib/oauth/password_access_token_request_spec.rb +13 -13
  120. data/spec/lib/oauth/pre_authorization_spec.rb +47 -7
  121. data/spec/lib/oauth/refresh_token_request_spec.rb +11 -21
  122. data/spec/lib/oauth/scopes_spec.rb +32 -32
  123. data/spec/lib/oauth/token_request_spec.rb +10 -9
  124. data/spec/lib/oauth/token_response_spec.rb +13 -15
  125. data/spec/lib/oauth/token_spec.rb +24 -10
  126. data/spec/lib/server_spec.rb +24 -2
  127. data/spec/models/doorkeeper/access_grant_spec.rb +8 -8
  128. data/spec/models/doorkeeper/access_token_spec.rb +79 -33
  129. data/spec/models/doorkeeper/application_spec.rb +29 -29
  130. data/spec/requests/applications/applications_request_spec.rb +15 -15
  131. data/spec/requests/applications/authorized_applications_spec.rb +7 -7
  132. data/spec/requests/endpoints/authorization_spec.rb +19 -12
  133. data/spec/requests/endpoints/token_spec.rb +26 -8
  134. data/spec/requests/flows/authorization_code_errors_spec.rb +17 -17
  135. data/spec/requests/flows/authorization_code_spec.rb +28 -28
  136. data/spec/requests/flows/client_credentials_spec.rb +3 -3
  137. data/spec/requests/flows/implicit_grant_errors_spec.rb +5 -5
  138. data/spec/requests/flows/implicit_grant_spec.rb +2 -2
  139. data/spec/requests/flows/password_spec.rb +32 -32
  140. data/spec/requests/flows/refresh_token_spec.rb +23 -23
  141. data/spec/requests/flows/revoke_token_spec.rb +165 -0
  142. data/spec/requests/flows/skip_authorization_spec.rb +10 -10
  143. data/spec/requests/protected_resources/metal_spec.rb +1 -1
  144. data/spec/requests/protected_resources/private_api_spec.rb +5 -5
  145. data/spec/routing/custom_controller_routes_spec.rb +4 -0
  146. data/spec/routing/default_routes_spec.rb +5 -1
  147. data/spec/spec_helper.rb +2 -2
  148. data/spec/spec_helper_integration.rb +8 -10
  149. data/spec/support/helpers/access_token_request_helper.rb +3 -3
  150. data/spec/support/helpers/authorization_request_helper.rb +3 -3
  151. data/spec/support/helpers/config_helper.rb +1 -1
  152. data/spec/support/helpers/model_helper.rb +2 -2
  153. data/spec/support/helpers/request_spec_helper.rb +3 -3
  154. data/spec/support/helpers/url_helper.rb +25 -21
  155. data/spec/support/orm/active_record.rb +4 -4
  156. data/spec/support/orm/mongo_mapper.rb +2 -3
  157. data/spec/support/orm/mongoid.rb +5 -6
  158. data/spec/support/shared/controllers_shared_context.rb +15 -15
  159. data/spec/support/shared/models_shared_examples.rb +13 -13
  160. data/spec/validators/redirect_uri_validator_spec.rb +9 -9
  161. metadata +5 -4
@@ -3,18 +3,19 @@ require 'spec_helper_integration'
3
3
  module Doorkeeper::OAuth
4
4
  describe TokenRequest do
5
5
  let :pre_auth do
6
- double(:pre_auth, {
7
- :client => double(:application, :id => 9990),
8
- :redirect_uri => 'http://tst.com/cb',
9
- :state => nil,
10
- :scopes => nil,
11
- :error => nil,
12
- :authorizable? => true
13
- })
6
+ double(
7
+ :pre_auth,
8
+ client: double(:application, id: 9990),
9
+ redirect_uri: 'http://tst.com/cb',
10
+ state: nil,
11
+ scopes: nil,
12
+ error: nil,
13
+ authorizable?: true
14
+ )
14
15
  end
15
16
 
16
17
  let :owner do
17
- double :owner, :id => 7866
18
+ double :owner, id: 7866
18
19
  end
19
20
 
20
21
  subject do
@@ -17,14 +17,13 @@ module Doorkeeper::OAuth
17
17
 
18
18
  describe '.body' do
19
19
  let(:access_token) do
20
- double :access_token, {
21
- :token => 'some-token',
22
- :expires_in => '3600',
23
- :expires_in_seconds => '300',
24
- :scopes_string => 'two scopes',
25
- :refresh_token => 'some-refresh-token',
26
- :token_type => 'bearer'
27
- }
20
+ double :access_token,
21
+ token: 'some-token',
22
+ expires_in: '3600',
23
+ expires_in_seconds: '300',
24
+ scopes_string: 'two scopes',
25
+ refresh_token: 'some-refresh-token',
26
+ token_type: 'bearer'
28
27
  end
29
28
 
30
29
  subject { TokenResponse.new(access_token).body }
@@ -54,13 +53,12 @@ module Doorkeeper::OAuth
54
53
 
55
54
  describe '.body filters out empty values' do
56
55
  let(:access_token) do
57
- double :access_token, {
58
- :token => 'some-token',
59
- :expires_in_seconds => '',
60
- :scopes_string => '',
61
- :refresh_token => '',
62
- :token_type => 'bearer'
63
- }
56
+ double :access_token,
57
+ token: 'some-token',
58
+ expires_in_seconds: '',
59
+ scopes_string: '',
60
+ refresh_token: '',
61
+ token_type: 'bearer'
64
62
  end
65
63
 
66
64
  subject { TokenResponse.new(access_token).body }
@@ -14,7 +14,7 @@ module Doorkeeper
14
14
  let(:request) { double.as_null_object }
15
15
 
16
16
  let(:method) do
17
- lambda { |request| return 'token-value' }
17
+ ->(request) { return 'token-value' }
18
18
  end
19
19
 
20
20
  it 'accepts anything that responds to #call' do
@@ -30,7 +30,7 @@ module Doorkeeper
30
30
  it 'stops at the first credentials found' do
31
31
  not_called_method = double
32
32
  expect(not_called_method).not_to receive(:call)
33
- credentials = Token.from_request request, lambda { |r| }, method, not_called_method
33
+ Token.from_request request, ->(r) {}, method, not_called_method
34
34
  end
35
35
 
36
36
  it 'returns the credential from extractor method' do
@@ -41,39 +41,53 @@ module Doorkeeper
41
41
 
42
42
  describe :from_access_token_param do
43
43
  it 'returns token from access_token parameter' do
44
- request = double :parameters => { :access_token => 'some-token' }
44
+ request = double parameters: { access_token: 'some-token' }
45
45
  token = Token.from_access_token_param(request)
46
- expect(token).to eq("some-token")
46
+ expect(token).to eq('some-token')
47
47
  end
48
48
  end
49
49
 
50
50
  describe :from_bearer_param do
51
51
  it 'returns token from bearer_token parameter' do
52
- request = double :parameters => { :bearer_token => 'some-token' }
52
+ request = double parameters: { bearer_token: 'some-token' }
53
53
  token = Token.from_bearer_param(request)
54
- expect(token).to eq("some-token")
54
+ expect(token).to eq('some-token')
55
55
  end
56
56
  end
57
57
 
58
58
  describe :from_bearer_authorization do
59
59
  it 'returns token from authorization bearer' do
60
- request = double :authorization => "Bearer SomeToken"
60
+ request = double authorization: 'Bearer SomeToken'
61
61
  token = Token.from_bearer_authorization(request)
62
- expect(token).to eq("SomeToken")
62
+ expect(token).to eq('SomeToken')
63
63
  end
64
64
 
65
65
  it 'does not return token if authorization is not bearer' do
66
- request = double :authorization => "MAC SomeToken"
66
+ request = double authorization: 'MAC SomeToken'
67
67
  token = Token.from_bearer_authorization(request)
68
68
  expect(token).to be_blank
69
69
  end
70
70
  end
71
71
 
72
+ describe :from_basic_authorization do
73
+ it 'returns token from authorization basic' do
74
+ request = double authorization: "Basic #{Base64.encode64 'SomeToken:'}"
75
+ token = Token.from_basic_authorization(request)
76
+ expect(token).to eq('SomeToken')
77
+ end
78
+
79
+ it 'does not return token if authorization is not basic' do
80
+ request = double authorization: "MAC #{Base64.encode64 'SomeToken:'}"
81
+ token = Token.from_basic_authorization(request)
82
+ expect(token).to be_blank
83
+ end
84
+ end
85
+
72
86
  describe :authenticate do
73
87
  let(:finder) { double :finder }
74
88
 
75
89
  it 'calls the finder if token was found' do
76
- token = lambda { |r| 'token' }
90
+ token = ->(r) { 'token' }
77
91
  expect(AccessToken).to receive(:authenticate).with('token')
78
92
  Token.authenticate double, token
79
93
  end
@@ -12,11 +12,33 @@ describe Doorkeeper::Server do
12
12
 
13
13
  describe '.authorization_request' do
14
14
  it 'raises error when strategy does not exist' do
15
- expect { subject.authorization_request(:duh) }.to raise_error(Doorkeeper::Errors::InvalidAuthorizationStrategy)
15
+ expect do
16
+ subject.authorization_request(:duh)
17
+ end.to raise_error(Doorkeeper::Errors::InvalidAuthorizationStrategy)
16
18
  end
17
19
 
18
20
  it 'raises error when strategy does not match phase' do
19
- expect { subject.token_request(:code) }.to raise_error(Doorkeeper::Errors::InvalidTokenStrategy)
21
+ expect do
22
+ subject.token_request(:code)
23
+ end.to raise_error(Doorkeeper::Errors::InvalidTokenStrategy)
24
+ end
25
+
26
+ context 'when only Authorization Code strategy is enabled' do
27
+ before do
28
+ Doorkeeper.configuration.stub(:grant_flows) { ['authorization_code'] }
29
+ end
30
+
31
+ it 'raises error when using the disabled Implicit strategy' do
32
+ expect do
33
+ subject.authorization_request(:token)
34
+ end.to raise_error(Doorkeeper::Errors::InvalidAuthorizationStrategy)
35
+ end
36
+
37
+ it 'raises error when using the disabled Client Credentials strategy' do
38
+ expect do
39
+ subject.token_request(:client_credentials)
40
+ end.to raise_error(Doorkeeper::Errors::InvalidTokenStrategy)
41
+ end
20
42
  end
21
43
 
22
44
  it 'builds the request with selected strategy' do
@@ -5,30 +5,30 @@ describe Doorkeeper::AccessGrant do
5
5
 
6
6
  it { should be_valid }
7
7
 
8
- it_behaves_like "an accessible token"
9
- it_behaves_like "a revocable token"
10
- it_behaves_like "an unique token" do
8
+ it_behaves_like 'an accessible token'
9
+ it_behaves_like 'a revocable token'
10
+ it_behaves_like 'an unique token' do
11
11
  let(:factory_name) { :access_grant }
12
12
  end
13
13
 
14
- describe "validations" do
15
- it "is invalid without resource_owner_id" do
14
+ describe 'validations' do
15
+ it 'is invalid without resource_owner_id' do
16
16
  subject.resource_owner_id = nil
17
17
  should_not be_valid
18
18
  end
19
19
 
20
- it "is invalid without application_id" do
20
+ it 'is invalid without application_id' do
21
21
  subject.application_id = nil
22
22
  should_not be_valid
23
23
  end
24
24
 
25
- it "is invalid without token" do
25
+ it 'is invalid without token' do
26
26
  subject.save
27
27
  subject.token = nil
28
28
  should_not be_valid
29
29
  end
30
30
 
31
- it "is invalid without expires_in" do
31
+ it 'is invalid without expires_in' do
32
32
  subject.expires_in = nil
33
33
  should_not be_valid
34
34
  end
@@ -6,9 +6,9 @@ module Doorkeeper
6
6
 
7
7
  it { should be_valid }
8
8
 
9
- it_behaves_like "an accessible token"
10
- it_behaves_like "a revocable token"
11
- it_behaves_like "an unique token" do
9
+ it_behaves_like 'an accessible token'
10
+ it_behaves_like 'a revocable token'
11
+ it_behaves_like 'an unique token' do
12
12
  let(:factory_name) { :access_token }
13
13
  end
14
14
 
@@ -19,40 +19,87 @@ module Doorkeeper
19
19
  end
20
20
 
21
21
  it 'generates a refresh token if it was requested' do
22
- token = FactoryGirl.create :access_token, :use_refresh_token => true
22
+ token = FactoryGirl.create :access_token, use_refresh_token: true
23
23
  expect(token.refresh_token).not_to be_nil
24
24
  end
25
25
 
26
- it "is not valid if token exists" do
27
- token1 = FactoryGirl.create :access_token, :use_refresh_token => true
28
- token2 = FactoryGirl.create :access_token, :use_refresh_token => true
26
+ it 'is not valid if token exists' do
27
+ token1 = FactoryGirl.create :access_token, use_refresh_token: true
28
+ token2 = FactoryGirl.create :access_token, use_refresh_token: true
29
29
  token2.send :write_attribute, :refresh_token, token1.refresh_token
30
30
  expect(token2).not_to be_valid
31
31
  end
32
32
 
33
33
  it 'expects database to raise an error if refresh tokens are the same' do
34
- token1 = FactoryGirl.create :access_token, :use_refresh_token => true
35
- token2 = FactoryGirl.create :access_token, :use_refresh_token => true
36
- expect {
34
+ token1 = FactoryGirl.create :access_token, use_refresh_token: true
35
+ token2 = FactoryGirl.create :access_token, use_refresh_token: true
36
+ expect do
37
37
  token2.write_attribute :refresh_token, token1.refresh_token
38
- token2.save(:validate => false)
39
- }.to raise_error
38
+ token2.save(validate: false)
39
+ end.to raise_error
40
40
  end
41
41
  end
42
42
 
43
- describe "validations" do
44
- it "is valid without resource_owner_id" do
43
+ describe 'validations' do
44
+ it 'is valid without resource_owner_id' do
45
45
  # For client credentials flow
46
46
  subject.resource_owner_id = nil
47
47
  should be_valid
48
48
  end
49
49
  end
50
50
 
51
+ describe '#same_credential?' do
52
+
53
+ context 'with default parameters' do
54
+
55
+ let(:resource_owner_id) { 100 }
56
+ let(:application) { FactoryGirl.create :application }
57
+ let(:default_attributes) do
58
+ { application: application, resource_owner_id: resource_owner_id }
59
+ end
60
+ let(:access_token1) { FactoryGirl.create :access_token, default_attributes }
61
+
62
+ context 'the second token has the same owner and same app' do
63
+ let(:access_token2) { FactoryGirl.create :access_token, default_attributes }
64
+ it 'success' do
65
+ expect(access_token1.same_credential?(access_token2)).to be_true
66
+ end
67
+ end
68
+
69
+ context 'the second token has same owner and different app' do
70
+ let(:other_application) { FactoryGirl.create :application }
71
+ let(:access_token2) { FactoryGirl.create :access_token, application: other_application, resource_owner_id: resource_owner_id }
72
+
73
+ it 'fail' do
74
+ expect(access_token1.same_credential?(access_token2)).to be_false
75
+ end
76
+ end
77
+
78
+ context 'the second token has different owner and different app' do
79
+
80
+ let(:other_application) { FactoryGirl.create :application }
81
+ let(:access_token2) { FactoryGirl.create :access_token, application: other_application, resource_owner_id: 42 }
82
+
83
+ it 'fail' do
84
+ expect(access_token1.same_credential?(access_token2)).to be_false
85
+ end
86
+ end
87
+
88
+ context 'the second token has different owner and same app' do
89
+ let(:access_token2) { FactoryGirl.create :access_token, application: application, resource_owner_id: 42 }
90
+
91
+ it 'fail' do
92
+ expect(access_token1.same_credential?(access_token2)).to be_false
93
+ end
94
+ end
95
+ end
96
+ end
97
+
51
98
  describe '.revoke_all_for' do
52
- let(:resource_owner) { double(:id => 100) }
99
+ let(:resource_owner) { double(id: 100) }
53
100
  let(:application) { FactoryGirl.create :application }
54
101
  let(:default_attributes) do
55
- { :application => application, :resource_owner_id => resource_owner.id }
102
+ { application: application, resource_owner_id: resource_owner.id }
56
103
  end
57
104
 
58
105
  it 'revokes all tokens for given application and resource owner' do
@@ -64,13 +111,13 @@ module Doorkeeper
64
111
  end
65
112
 
66
113
  it 'matches application' do
67
- FactoryGirl.create :access_token, default_attributes.merge(:application => FactoryGirl.create(:application))
114
+ FactoryGirl.create :access_token, default_attributes.merge(application: FactoryGirl.create(:application))
68
115
  AccessToken.revoke_all_for application.id, resource_owner
69
116
  expect(AccessToken.all).not_to be_empty
70
117
  end
71
118
 
72
119
  it 'matches resource owner' do
73
- FactoryGirl.create :access_token, default_attributes.merge(:resource_owner_id => 90)
120
+ FactoryGirl.create :access_token, default_attributes.merge(resource_owner_id: 90)
74
121
  AccessToken.revoke_all_for application.id, resource_owner
75
122
  expect(AccessToken.all).not_to be_empty
76
123
  end
@@ -79,9 +126,9 @@ module Doorkeeper
79
126
  describe '.matching_token_for' do
80
127
  let(:resource_owner_id) { 100 }
81
128
  let(:application) { FactoryGirl.create :application }
82
- let(:scopes) { Doorkeeper::OAuth::Scopes.from_string("public write") }
129
+ let(:scopes) { Doorkeeper::OAuth::Scopes.from_string('public write') }
83
130
  let(:default_attributes) do
84
- { :application => application, :resource_owner_id => resource_owner_id, :scopes => scopes.to_s }
131
+ { application: application, resource_owner_id: resource_owner_id, scopes: scopes.to_s }
85
132
  end
86
133
 
87
134
  it 'returns only one token' do
@@ -91,44 +138,44 @@ module Doorkeeper
91
138
  end
92
139
 
93
140
  it 'accepts resource owner as object' do
94
- resource_owner = double(:to_key => true, :id => 100)
141
+ resource_owner = double(to_key: true, id: 100)
95
142
  token = FactoryGirl.create :access_token, default_attributes
96
143
  last_token = AccessToken.matching_token_for(application, resource_owner, scopes)
97
144
  expect(last_token).to eq(token)
98
145
  end
99
146
 
100
147
  it 'accepts nil as resource owner' do
101
- token = FactoryGirl.create :access_token, default_attributes.merge(:resource_owner_id => nil)
148
+ token = FactoryGirl.create :access_token, default_attributes.merge(resource_owner_id: nil)
102
149
  last_token = AccessToken.matching_token_for(application, nil, scopes)
103
150
  expect(last_token).to eq(token)
104
151
  end
105
152
 
106
153
  it 'excludes revoked tokens' do
107
- FactoryGirl.create :access_token, default_attributes.merge(:revoked_at => 1.day.ago)
154
+ FactoryGirl.create :access_token, default_attributes.merge(revoked_at: 1.day.ago)
108
155
  last_token = AccessToken.matching_token_for(application, resource_owner_id, scopes)
109
156
  expect(last_token).to be_nil
110
157
  end
111
158
 
112
159
  it 'matches the application' do
113
- token = FactoryGirl.create :access_token, default_attributes.merge(:application => FactoryGirl.create(:application))
160
+ token = FactoryGirl.create :access_token, default_attributes.merge(application: FactoryGirl.create(:application))
114
161
  last_token = AccessToken.matching_token_for(application, resource_owner_id, scopes)
115
162
  expect(last_token).to be_nil
116
163
  end
117
164
 
118
165
  it 'matches the resource owner' do
119
- FactoryGirl.create :access_token, default_attributes.merge(:resource_owner_id => 2)
166
+ FactoryGirl.create :access_token, default_attributes.merge(resource_owner_id: 2)
120
167
  last_token = AccessToken.matching_token_for(application, resource_owner_id, scopes)
121
168
  expect(last_token).to be_nil
122
169
  end
123
170
 
124
171
  it 'matches the scopes' do
125
- FactoryGirl.create :access_token, default_attributes.merge(:scopes => 'public email')
172
+ FactoryGirl.create :access_token, default_attributes.merge(scopes: 'public email')
126
173
  last_token = AccessToken.matching_token_for(application, resource_owner_id, scopes)
127
174
  expect(last_token).to be_nil
128
175
  end
129
176
 
130
177
  it 'returns the last created token' do
131
- FactoryGirl.create :access_token, default_attributes.merge(:created_at => 1.day.ago)
178
+ FactoryGirl.create :access_token, default_attributes.merge(created_at: 1.day.ago)
132
179
  token = FactoryGirl.create :access_token, default_attributes
133
180
  last_token = AccessToken.matching_token_for(application, resource_owner_id, scopes)
134
181
  expect(last_token).to eq(token)
@@ -136,12 +183,11 @@ module Doorkeeper
136
183
 
137
184
  it 'returns as_json hash' do
138
185
  token = FactoryGirl.create :access_token, default_attributes
139
- token_hash = {
140
- :resource_owner_id => token.resource_owner_id,
141
- :scopes => token.scopes,
142
- :expires_in_seconds => token.expires_in_seconds,
143
- :application => { :uid => token.application.uid }
144
- }
186
+ token_hash = { resource_owner_id: token.resource_owner_id,
187
+ scopes: token.scopes,
188
+ expires_in_seconds: token.expires_in_seconds,
189
+ application: { uid: token.application.uid }
190
+ }
145
191
  expect(token.as_json).to eq token_hash
146
192
  end
147
193
  end
@@ -4,14 +4,14 @@ module Doorkeeper
4
4
  describe Application do
5
5
  include OrmHelper
6
6
 
7
- let(:require_owner) { Doorkeeper.configuration.instance_variable_set("@confirm_application_owner", true) }
8
- let(:unset_require_owner) { Doorkeeper.configuration.instance_variable_set("@confirm_application_owner", false) }
7
+ let(:require_owner) { Doorkeeper.configuration.instance_variable_set('@confirm_application_owner', true) }
8
+ let(:unset_require_owner) { Doorkeeper.configuration.instance_variable_set('@confirm_application_owner', false) }
9
9
  let(:new_application) { FactoryGirl.build(:application) }
10
10
 
11
11
  let(:uid) { SecureRandom.hex(8) }
12
12
  let(:secret) { SecureRandom.hex(8) }
13
13
 
14
- context "application_owner is enabled" do
14
+ context 'application_owner is enabled' do
15
15
  before do
16
16
  Doorkeeper.configure do
17
17
  orm DOORKEEPER_ORM
@@ -29,7 +29,7 @@ module Doorkeeper
29
29
  end
30
30
  end
31
31
 
32
- context "application owner is required" do
32
+ context 'application owner is required' do
33
33
  before(:each) do
34
34
  require_owner
35
35
  @owner = mock_application_owner
@@ -86,9 +86,7 @@ module Doorkeeper
86
86
  app1 = FactoryGirl.create(:application)
87
87
  app2 = FactoryGirl.create(:application)
88
88
  app2.uid = app1.uid
89
- expect {
90
- app2.save!(:validate => false)
91
- }.to raise_error
89
+ expect { app2.save!(validate: false) }.to raise_error
92
90
  end
93
91
 
94
92
  it 'generate secret on create' do
@@ -115,53 +113,55 @@ module Doorkeeper
115
113
  end
116
114
 
117
115
  it 'should destroy its access grants' do
118
- FactoryGirl.create(:access_grant, :application => new_application)
116
+ FactoryGirl.create(:access_grant, application: new_application)
119
117
  expect { new_application.destroy }.to change { Doorkeeper::AccessGrant.count }.by(-1)
120
118
  end
121
119
 
122
120
  it 'should destroy its access tokens' do
123
- FactoryGirl.create(:access_token, :application => new_application)
124
- FactoryGirl.create(:access_token, :application => new_application, :revoked_at => Time.now)
125
- expect { new_application.destroy }.to change { Doorkeeper::AccessToken.count }.by(-2)
121
+ FactoryGirl.create(:access_token, application: new_application)
122
+ FactoryGirl.create(:access_token, application: new_application, revoked_at: Time.now)
123
+ expect do
124
+ new_application.destroy
125
+ end.to change { Doorkeeper::AccessToken.count }.by(-2)
126
126
  end
127
127
  end
128
128
 
129
129
  describe :authorized_for do
130
- let(:resource_owner) { double(:resource_owner, :id => 10) }
130
+ let(:resource_owner) { double(:resource_owner, id: 10) }
131
131
 
132
- it "is empty if the application is not authorized for anyone" do
132
+ it 'is empty if the application is not authorized for anyone' do
133
133
  expect(Application.authorized_for(resource_owner)).to be_empty
134
134
  end
135
135
 
136
- it "returns only application for a specific resource owner" do
137
- FactoryGirl.create(:access_token, :resource_owner_id => resource_owner.id + 1)
138
- token = FactoryGirl.create(:access_token, :resource_owner_id => resource_owner.id)
136
+ it 'returns only application for a specific resource owner' do
137
+ FactoryGirl.create(:access_token, resource_owner_id: resource_owner.id + 1)
138
+ token = FactoryGirl.create(:access_token, resource_owner_id: resource_owner.id)
139
139
  expect(Application.authorized_for(resource_owner)).to eq([token.application])
140
140
  end
141
141
 
142
- it "excludes revoked tokens" do
143
- FactoryGirl.create(:access_token, :resource_owner_id => resource_owner.id, :revoked_at => 2.days.ago)
142
+ it 'excludes revoked tokens' do
143
+ FactoryGirl.create(:access_token, resource_owner_id: resource_owner.id, revoked_at: 2.days.ago)
144
144
  expect(Application.authorized_for(resource_owner)).to be_empty
145
145
  end
146
146
 
147
- it "returns all applications that have been authorized" do
148
- token1 = FactoryGirl.create(:access_token, :resource_owner_id => resource_owner.id)
149
- token2 = FactoryGirl.create(:access_token, :resource_owner_id => resource_owner.id)
147
+ it 'returns all applications that have been authorized' do
148
+ token1 = FactoryGirl.create(:access_token, resource_owner_id: resource_owner.id)
149
+ token2 = FactoryGirl.create(:access_token, resource_owner_id: resource_owner.id)
150
150
  expect(Application.authorized_for(resource_owner)).to eq([token1.application, token2.application])
151
151
  end
152
152
 
153
- it "returns only one application even if it has been authorized twice" do
153
+ it 'returns only one application even if it has been authorized twice' do
154
154
  application = FactoryGirl.create(:application)
155
- FactoryGirl.create(:access_token, :resource_owner_id => resource_owner.id, :application => application)
156
- FactoryGirl.create(:access_token, :resource_owner_id => resource_owner.id, :application => application)
155
+ FactoryGirl.create(:access_token, resource_owner_id: resource_owner.id, application: application)
156
+ FactoryGirl.create(:access_token, resource_owner_id: resource_owner.id, application: application)
157
157
  expect(Application.authorized_for(resource_owner)).to eq([application])
158
158
  end
159
159
 
160
- it "should fail to mass assign a new application", if: ::Rails::VERSION::MAJOR < 4 do
161
- mass_assign = { :name => 'Something',
162
- :redirect_uri => 'http://somewhere.com/something',
163
- :uid => 123,
164
- :secret => 'something' }
160
+ it 'should fail to mass assign a new application', if: ::Rails::VERSION::MAJOR < 4 do
161
+ mass_assign = { name: 'Something',
162
+ redirect_uri: 'http://somewhere.com/something',
163
+ uid: 123,
164
+ secret: 'something' }
165
165
  expect(Application.create(mass_assign).uid).not_to eq(123)
166
166
  end
167
167
  end