doorkeeper 2.1.4 → 3.1.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 (135) hide show
  1. checksums.yaml +4 -4
  2. data/.hound.yml +4 -0
  3. data/.travis.yml +5 -24
  4. data/CONTRIBUTING.md +23 -13
  5. data/Gemfile +3 -7
  6. data/{CHANGELOG.md → NEWS.md} +137 -42
  7. data/README.md +60 -46
  8. data/RELEASING.md +5 -3
  9. data/app/assets/stylesheets/doorkeeper/admin/application.css +1 -5
  10. data/app/controllers/doorkeeper/applications_controller.rb +2 -2
  11. data/app/helpers/doorkeeper/dashboard_helper.rb +1 -1
  12. data/app/validators/redirect_uri_validator.rb +1 -1
  13. data/app/views/doorkeeper/applications/_form.html.erb +13 -2
  14. data/app/views/doorkeeper/applications/show.html.erb +3 -2
  15. data/app/views/doorkeeper/authorizations/new.html.erb +1 -1
  16. data/app/views/layouts/doorkeeper/admin.html.erb +5 -2
  17. data/config/locales/en.yml +4 -32
  18. data/doorkeeper.gemspec +4 -8
  19. data/lib/doorkeeper/config.rb +20 -29
  20. data/lib/doorkeeper/engine.rb +7 -1
  21. data/lib/doorkeeper/errors.rb +12 -0
  22. data/lib/doorkeeper/grape/helpers.rb +1 -1
  23. data/lib/doorkeeper/helpers/controller.rb +6 -0
  24. data/lib/doorkeeper/models/access_grant_mixin.rb +3 -2
  25. data/lib/doorkeeper/models/access_token_mixin.rb +12 -4
  26. data/lib/doorkeeper/models/application_mixin.rb +11 -18
  27. data/lib/doorkeeper/models/concerns/revocable.rb +2 -2
  28. data/lib/doorkeeper/oauth/authorization/token.rb +15 -6
  29. data/lib/doorkeeper/oauth/authorization_code_request.rb +10 -5
  30. data/lib/doorkeeper/oauth/client.rb +9 -8
  31. data/lib/doorkeeper/oauth/client_credentials/creator.rb +3 -4
  32. data/lib/doorkeeper/oauth/error.rb +5 -1
  33. data/lib/doorkeeper/oauth/helpers/scope_checker.rb +1 -1
  34. data/lib/doorkeeper/oauth/refresh_token_request.rb +17 -7
  35. data/lib/doorkeeper/orm/active_record/access_grant.rb +2 -2
  36. data/lib/doorkeeper/orm/active_record/access_token.rb +2 -2
  37. data/lib/doorkeeper/orm/active_record/application.rb +2 -2
  38. data/lib/doorkeeper/orm/active_record.rb +22 -0
  39. data/lib/doorkeeper/rails/helpers.rb +19 -29
  40. data/lib/doorkeeper/request/authorization_code.rb +10 -15
  41. data/lib/doorkeeper/request/client_credentials.rb +9 -15
  42. data/lib/doorkeeper/request/code.rb +7 -13
  43. data/lib/doorkeeper/request/password.rb +10 -15
  44. data/lib/doorkeeper/request/refresh_token.rb +11 -13
  45. data/lib/doorkeeper/request/strategy.rb +17 -0
  46. data/lib/doorkeeper/request/token.rb +7 -13
  47. data/lib/doorkeeper/request.rb +18 -8
  48. data/lib/doorkeeper/server.rb +2 -2
  49. data/lib/doorkeeper/version.rb +1 -1
  50. data/lib/doorkeeper.rb +0 -4
  51. data/lib/generators/doorkeeper/templates/README +0 -20
  52. data/lib/generators/doorkeeper/templates/initializer.rb +5 -3
  53. data/lib/generators/doorkeeper/templates/migration.rb +8 -0
  54. data/spec/controllers/applications_controller_spec.rb +0 -1
  55. data/spec/controllers/protected_resources_controller_spec.rb +115 -14
  56. data/spec/controllers/token_info_controller_spec.rb +0 -4
  57. data/spec/controllers/tokens_controller_spec.rb +34 -3
  58. data/spec/dummy/app/models/user.rb +2 -24
  59. data/spec/dummy/config/application.rb +2 -1
  60. data/spec/dummy/config/initializers/doorkeeper.rb +0 -2
  61. data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +24 -0
  62. data/spec/lib/config_spec.rb +20 -4
  63. data/spec/lib/models/revocable_spec.rb +2 -2
  64. data/spec/lib/oauth/authorization_code_request_spec.rb +1 -1
  65. data/spec/lib/oauth/client/credentials_spec.rb +2 -2
  66. data/spec/lib/oauth/client_credentials/creator_spec.rb +25 -1
  67. data/spec/lib/oauth/error_response_spec.rb +7 -7
  68. data/spec/lib/oauth/error_spec.rb +9 -5
  69. data/spec/lib/oauth/helpers/scope_checker_spec.rb +3 -3
  70. data/spec/lib/oauth/password_access_token_request_spec.rb +1 -1
  71. data/spec/lib/oauth/pre_authorization_spec.rb +9 -10
  72. data/spec/lib/oauth/refresh_token_request_spec.rb +26 -6
  73. data/spec/lib/oauth/scopes_spec.rb +1 -1
  74. data/spec/lib/oauth/token_request_spec.rb +6 -3
  75. data/spec/lib/request/strategy_spec.rb +53 -0
  76. data/spec/lib/server_spec.rb +4 -2
  77. data/spec/models/doorkeeper/access_grant_spec.rb +5 -5
  78. data/spec/models/doorkeeper/access_token_spec.rb +102 -5
  79. data/spec/models/doorkeeper/application_spec.rb +13 -16
  80. data/spec/requests/applications/applications_request_spec.rb +1 -1
  81. data/spec/requests/endpoints/authorization_spec.rb +2 -1
  82. data/spec/requests/endpoints/token_spec.rb +9 -9
  83. data/spec/requests/flows/authorization_code_errors_spec.rb +4 -4
  84. data/spec/requests/flows/authorization_code_spec.rb +36 -2
  85. data/spec/requests/flows/implicit_grant_spec.rb +14 -5
  86. data/spec/requests/flows/password_spec.rb +14 -20
  87. data/spec/requests/flows/refresh_token_spec.rb +15 -7
  88. data/spec/requests/flows/revoke_token_spec.rb +9 -31
  89. data/spec/requests/protected_resources/metal_spec.rb +3 -3
  90. data/spec/requests/protected_resources/private_api_spec.rb +11 -0
  91. data/spec/routing/custom_controller_routes_spec.rb +1 -2
  92. data/spec/routing/default_routes_spec.rb +1 -2
  93. data/spec/routing/scoped_routes_spec.rb +0 -1
  94. data/spec/spec_helper_integration.rb +10 -7
  95. data/spec/support/helpers/access_token_request_helper.rb +1 -1
  96. data/spec/support/helpers/authorization_request_helper.rb +1 -1
  97. data/spec/support/helpers/config_helper.rb +1 -1
  98. data/spec/support/helpers/model_helper.rb +1 -1
  99. data/spec/support/helpers/request_spec_helper.rb +1 -1
  100. data/spec/support/helpers/url_helper.rb +1 -1
  101. data/spec/support/shared/models_shared_examples.rb +1 -1
  102. data/spec/validators/redirect_uri_validator_spec.rb +5 -0
  103. metadata +127 -98
  104. data/gemfiles/Gemfile.common.rb +0 -14
  105. data/gemfiles/Gemfile.mongo_mapper.rb +0 -5
  106. data/gemfiles/Gemfile.mongoid2.rb +0 -5
  107. data/gemfiles/Gemfile.mongoid3.rb +0 -4
  108. data/gemfiles/Gemfile.mongoid4.rb +0 -5
  109. data/lib/doorkeeper/generators/doorkeeper/mongo_mapper/indexes_generator.rb +0 -12
  110. data/lib/doorkeeper/generators/doorkeeper/mongo_mapper/templates/indexes.rb +0 -3
  111. data/lib/doorkeeper/orm/mongo_mapper/access_grant.rb +0 -24
  112. data/lib/doorkeeper/orm/mongo_mapper/access_token.rb +0 -43
  113. data/lib/doorkeeper/orm/mongo_mapper/application.rb +0 -29
  114. data/lib/doorkeeper/orm/mongo_mapper.rb +0 -11
  115. data/lib/doorkeeper/orm/mongoid2/access_grant.rb +0 -22
  116. data/lib/doorkeeper/orm/mongoid2/access_token.rb +0 -37
  117. data/lib/doorkeeper/orm/mongoid2/application.rb +0 -25
  118. data/lib/doorkeeper/orm/mongoid2/concerns/scopes.rb +0 -30
  119. data/lib/doorkeeper/orm/mongoid2.rb +0 -11
  120. data/lib/doorkeeper/orm/mongoid3/access_grant.rb +0 -22
  121. data/lib/doorkeeper/orm/mongoid3/access_token.rb +0 -37
  122. data/lib/doorkeeper/orm/mongoid3/application.rb +0 -25
  123. data/lib/doorkeeper/orm/mongoid3/concerns/scopes.rb +0 -30
  124. data/lib/doorkeeper/orm/mongoid3.rb +0 -11
  125. data/lib/doorkeeper/orm/mongoid4/access_grant.rb +0 -22
  126. data/lib/doorkeeper/orm/mongoid4/access_token.rb +0 -37
  127. data/lib/doorkeeper/orm/mongoid4/application.rb +0 -25
  128. data/lib/doorkeeper/orm/mongoid4/concerns/scopes.rb +0 -17
  129. data/lib/doorkeeper/orm/mongoid4.rb +0 -11
  130. data/spec/dummy/config/mongo.yml +0 -11
  131. data/spec/dummy/config/mongoid2.yml +0 -9
  132. data/spec/dummy/config/mongoid3.yml +0 -18
  133. data/spec/dummy/config/mongoid4.yml +0 -19
  134. data/spec/support/orm/mongo_mapper.rb +0 -10
  135. data/spec/support/orm/mongoid.rb +0 -10
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper_integration'
2
2
 
3
- feature 'Implicit Grant Flow' do
3
+ feature 'Implicit Grant Flow (feature spec)' do
4
4
  background do
5
5
  config_is_set(:authenticate_resource_owner) { User.first || redirect_to('/sign_in') }
6
6
  config_is_set(:grant_flows, ["implicit"])
@@ -17,10 +17,19 @@ feature 'Implicit Grant Flow' do
17
17
 
18
18
  i_should_be_on_client_callback @client
19
19
  end
20
+ end
21
+
22
+ describe 'Implicit Grant Flow (request spec)' do
23
+ before do
24
+ config_is_set(:authenticate_resource_owner) { User.first || redirect_to('/sign_in') }
25
+ config_is_set(:grant_flows, ["implicit"])
26
+ client_exists
27
+ create_resource_owner
28
+ end
20
29
 
21
30
  context 'token reuse' do
22
- scenario 'should return a new token each request' do
23
- Doorkeeper.configuration.stub(:reuse_access_token).and_return(false)
31
+ it 'should return a new token each request' do
32
+ allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(false)
24
33
 
25
34
  token = client_is_authorized(@client, @resource_owner)
26
35
 
@@ -34,8 +43,8 @@ feature 'Implicit Grant Flow' do
34
43
  expect(response.location).not_to include(token.token)
35
44
  end
36
45
 
37
- scenario 'should return the same token if it is still accessible' do
38
- Doorkeeper.configuration.stub(:reuse_access_token).and_return(true)
46
+ it 'should return the same token if it is still accessible' do
47
+ allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(true)
39
48
 
40
49
  token = client_is_authorized(@client, @resource_owner)
41
50
 
@@ -1,19 +1,13 @@
1
- # coding: utf-8
2
-
3
- # TODO: this flow should be configurable (letting Doorkeeper users decide if
4
- # they want to make it available)
5
-
6
1
  require 'spec_helper_integration'
7
2
 
8
- feature 'Resource Owner Password Credentials Flow inproperly set up' do
9
- background do
3
+ describe 'Resource Owner Password Credentials Flow not set up' do
4
+ before do
10
5
  client_exists
11
6
  create_resource_owner
12
7
  end
13
8
 
14
9
  context 'with valid user credentials' do
15
- scenario 'should issue new token' do
16
- skip 'Check a way to supress warnings here (or handle config better)'
10
+ it 'doesn\'t issue new token' do
17
11
  expect do
18
12
  post password_token_endpoint_url(client: @client, resource_owner: @resource_owner)
19
13
  end.to_not change { Doorkeeper::AccessToken.count }
@@ -21,8 +15,8 @@ feature 'Resource Owner Password Credentials Flow inproperly set up' do
21
15
  end
22
16
  end
23
17
 
24
- feature 'Resource Owner Password Credentials Flow' do
25
- background do
18
+ describe 'Resource Owner Password Credentials Flow' do
19
+ before do
26
20
  config_is_set(:grant_flows, ["password"])
27
21
  config_is_set(:resource_owner_from_credentials) { User.authenticate! params[:username], params[:password] }
28
22
  client_exists
@@ -30,7 +24,7 @@ feature 'Resource Owner Password Credentials Flow' do
30
24
  end
31
25
 
32
26
  context 'with valid user credentials' do
33
- scenario 'should issue new token' do
27
+ it 'should issue new token' do
34
28
  expect do
35
29
  post password_token_endpoint_url(client: @client, resource_owner: @resource_owner)
36
30
  end.to change { Doorkeeper::AccessToken.count }.by(1)
@@ -40,7 +34,7 @@ feature 'Resource Owner Password Credentials Flow' do
40
34
  should_have_json 'access_token', token.token
41
35
  end
42
36
 
43
- scenario 'should issue new token without client credentials' do
37
+ it 'should issue new token without client credentials' do
44
38
  expect do
45
39
  post password_token_endpoint_url(resource_owner: @resource_owner)
46
40
  end.to change { Doorkeeper::AccessToken.count }.by(1)
@@ -50,7 +44,7 @@ feature 'Resource Owner Password Credentials Flow' do
50
44
  should_have_json 'access_token', token.token
51
45
  end
52
46
 
53
- scenario 'should issue a refresh token if enabled' do
47
+ it 'should issue a refresh token if enabled' do
54
48
  config_is_set(:refresh_token_enabled, true)
55
49
 
56
50
  post password_token_endpoint_url(client: @client, resource_owner: @resource_owner)
@@ -60,20 +54,20 @@ feature 'Resource Owner Password Credentials Flow' do
60
54
  should_have_json 'refresh_token', token.refresh_token
61
55
  end
62
56
 
63
- scenario 'should return the same token if it is still accessible' do
64
- Doorkeeper.configuration.stub(:reuse_access_token).and_return(true)
57
+ it 'should return the same token if it is still accessible' do
58
+ allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(true)
65
59
 
66
60
  client_is_authorized(@client, @resource_owner)
67
61
 
68
62
  post password_token_endpoint_url(client: @client, resource_owner: @resource_owner)
69
63
 
70
- Doorkeeper::AccessToken.count.should be(1)
64
+ expect(Doorkeeper::AccessToken.count).to be(1)
71
65
  should_have_json 'access_token', Doorkeeper::AccessToken.first.token
72
66
  end
73
67
  end
74
68
 
75
69
  context 'with invalid user credentials' do
76
- scenario 'should not issue new token with bad password' do
70
+ it 'should not issue new token with bad password' do
77
71
  expect do
78
72
  post password_token_endpoint_url(client: @client,
79
73
  resource_owner_username: @resource_owner.name,
@@ -81,7 +75,7 @@ feature 'Resource Owner Password Credentials Flow' do
81
75
  end.to_not change { Doorkeeper::AccessToken.count }
82
76
  end
83
77
 
84
- scenario 'should not issue new token without credentials' do
78
+ it 'should not issue new token without credentials' do
85
79
  expect do
86
80
  post password_token_endpoint_url(client: @client)
87
81
  end.to_not change { Doorkeeper::AccessToken.count }
@@ -89,7 +83,7 @@ feature 'Resource Owner Password Credentials Flow' do
89
83
  end
90
84
 
91
85
  context 'with invalid client credentials' do
92
- scenario 'should not issue new token with bad client credentials' do
86
+ it 'should not issue new token with bad client credentials' do
93
87
  expect do
94
88
  post password_token_endpoint_url(client_id: @client.uid,
95
89
  client_secret: 'bad_secret',
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper_integration'
2
2
 
3
- feature 'Refresh Token Flow' do
3
+ describe 'Refresh Token Flow' do
4
4
  before do
5
5
  Doorkeeper.configure do
6
6
  orm DOORKEEPER_ORM
@@ -14,7 +14,7 @@ feature 'Refresh Token Flow' do
14
14
  authorization_code_exists application: @client
15
15
  end
16
16
 
17
- scenario 'client gets the refresh token and refreshses it' do
17
+ it 'client gets the refresh token and refreshses it' do
18
18
  post token_endpoint_url(code: @authorization.token, client: @client)
19
19
 
20
20
  token = Doorkeeper::AccessToken.first
@@ -40,31 +40,39 @@ feature 'Refresh Token Flow' do
40
40
  @token = FactoryGirl.create(:access_token, application: @client, resource_owner_id: 1, use_refresh_token: true)
41
41
  end
42
42
 
43
- scenario 'client request a token with refresh token' do
43
+ it 'client request a token with refresh token' do
44
44
  post refresh_token_endpoint_url(client: @client, refresh_token: @token.refresh_token)
45
45
  should_have_json 'refresh_token', Doorkeeper::AccessToken.last.refresh_token
46
46
  expect(@token.reload).to be_revoked
47
47
  end
48
48
 
49
- scenario 'client request a token with expired access token' do
49
+ it 'client request a token with expired access token' do
50
50
  @token.update_attribute :expires_in, -100
51
51
  post refresh_token_endpoint_url(client: @client, refresh_token: @token.refresh_token)
52
52
  should_have_json 'refresh_token', Doorkeeper::AccessToken.last.refresh_token
53
53
  expect(@token.reload).to be_revoked
54
54
  end
55
55
 
56
- scenario 'client gets an error for invalid refresh token' do
56
+ it 'client gets an error for invalid refresh token' do
57
57
  post refresh_token_endpoint_url(client: @client, refresh_token: 'invalid')
58
58
  should_not_have_json 'refresh_token'
59
59
  should_have_json 'error', 'invalid_grant'
60
60
  end
61
61
 
62
- scenario 'client gets an error for revoked acccess token' do
62
+ it 'client gets an error for revoked acccess token' do
63
63
  @token.revoke
64
64
  post refresh_token_endpoint_url(client: @client, refresh_token: @token.refresh_token)
65
65
  should_not_have_json 'refresh_token'
66
66
  should_have_json 'error', 'invalid_grant'
67
67
  end
68
+
69
+ it 'second of simultaneous client requests get an error for revoked acccess token' do
70
+ allow_any_instance_of(Doorkeeper::AccessToken).to receive(:revoked?).and_return(false, true)
71
+ post refresh_token_endpoint_url(client: @client, refresh_token: @token.refresh_token)
72
+
73
+ should_not_have_json 'refresh_token'
74
+ should_have_json 'error', 'invalid_request'
75
+ end
68
76
  end
69
77
 
70
78
  context 'refreshing the token with multiple sessions (devices)' do
@@ -80,7 +88,7 @@ feature 'Refresh Token Flow' do
80
88
  @token.update_attribute :expires_in, -100
81
89
  end
82
90
 
83
- scenario 'client request a token after creating another token with the same user' do
91
+ it 'client request a token after creating another token with the same user' do
84
92
  post refresh_token_endpoint_url(client: @client, refresh_token: @token.refresh_token)
85
93
 
86
94
  should_have_json 'refresh_token', last_token.refresh_token
@@ -1,13 +1,11 @@
1
1
  require 'spec_helper_integration'
2
2
 
3
- feature 'Revoke Token Flow' do
4
-
3
+ describe 'Revoke Token Flow' do
5
4
  before do
6
5
  Doorkeeper.configure { orm DOORKEEPER_ORM }
7
6
  end
8
7
 
9
8
  context 'with default parameters' do
10
-
11
9
  let(:client_application) { FactoryGirl.create :application }
12
10
  let(:resource_owner) { User.create!(name: 'John', password: 'sekret') }
13
11
  let(:authorization_access_token) do
@@ -16,13 +14,10 @@ feature 'Revoke Token Flow' do
16
14
  resource_owner_id: resource_owner.id,
17
15
  use_refresh_token: true)
18
16
  end
19
-
20
17
  let(:headers) { { 'HTTP_AUTHORIZATION' => "Bearer #{authorization_access_token.token}" } }
21
18
 
22
19
  context 'With invalid token to revoke' do
23
-
24
- scenario 'client wants to revoke the given access token' do
25
-
20
+ it 'client wants to revoke the given access token' do
26
21
  post revocation_token_endpoint_url, { token: 'I_AM_AN_INVALIDE_TOKEN' }, headers
27
22
 
28
23
  authorization_access_token.reload
@@ -34,11 +29,9 @@ feature 'Revoke Token Flow' do
34
29
  end
35
30
 
36
31
  context 'The access token to revoke is the same than the authorization access token' do
37
-
38
32
  let(:token_to_revoke) { authorization_access_token }
39
33
 
40
- scenario 'client wants to revoke the given access token' do
41
-
34
+ it 'client wants to revoke the given access token' do
42
35
  post revocation_token_endpoint_url, { token: token_to_revoke.token }, headers
43
36
 
44
37
  token_to_revoke.reload
@@ -47,11 +40,9 @@ feature 'Revoke Token Flow' do
47
40
  expect(response).to be_success
48
41
  expect(token_to_revoke.revoked?).to be_truthy
49
42
  expect(Doorkeeper::AccessToken.by_refresh_token(token_to_revoke.refresh_token).revoked?).to be_truthy
50
-
51
43
  end
52
44
 
53
- scenario 'client wants to revoke the given access token using the POST query string' do
54
-
45
+ it 'client wants to revoke the given access token using the POST query string' do
55
46
  url_with_query_string = revocation_token_endpoint_url + '?' + Rack::Utils.build_query(token: token_to_revoke.token)
56
47
  post url_with_query_string, {}, headers
57
48
 
@@ -62,13 +53,10 @@ feature 'Revoke Token Flow' do
62
53
  expect(token_to_revoke.revoked?).to be_falsey
63
54
  expect(Doorkeeper::AccessToken.by_refresh_token(token_to_revoke.refresh_token).revoked?).to be_falsey
64
55
  expect(authorization_access_token.revoked?).to be_falsey
65
-
66
56
  end
67
-
68
57
  end
69
58
 
70
59
  context 'The access token to revoke app and owners are the same than the authorization access token' do
71
-
72
60
  let(:token_to_revoke) do
73
61
  FactoryGirl.create(:access_token,
74
62
  application: client_application,
@@ -76,8 +64,7 @@ feature 'Revoke Token Flow' do
76
64
  use_refresh_token: true)
77
65
  end
78
66
 
79
- scenario 'client wants to revoke the given access token' do
80
-
67
+ it 'client wants to revoke the given access token' do
81
68
  post revocation_token_endpoint_url, { token: token_to_revoke.token }, headers
82
69
 
83
70
  token_to_revoke.reload
@@ -87,12 +74,10 @@ feature 'Revoke Token Flow' do
87
74
  expect(token_to_revoke.revoked?).to be_truthy
88
75
  expect(Doorkeeper::AccessToken.by_refresh_token(token_to_revoke.refresh_token).revoked?).to be_truthy
89
76
  expect(authorization_access_token.revoked?).to be_falsey
90
-
91
77
  end
92
78
  end
93
79
 
94
80
  context 'The access token to revoke authorization owner is the same than the authorization access token' do
95
-
96
81
  let(:other_client_application) { FactoryGirl.create :application }
97
82
  let(:token_to_revoke) do
98
83
  FactoryGirl.create(:access_token,
@@ -101,8 +86,7 @@ feature 'Revoke Token Flow' do
101
86
  use_refresh_token: true)
102
87
  end
103
88
 
104
- scenario 'client wants to revoke the given access token' do
105
-
89
+ it 'client wants to revoke the given access token' do
106
90
  post revocation_token_endpoint_url, { token: token_to_revoke.token }, headers
107
91
 
108
92
  token_to_revoke.reload
@@ -112,11 +96,10 @@ feature 'Revoke Token Flow' do
112
96
  expect(token_to_revoke.revoked?).to be_falsey
113
97
  expect(Doorkeeper::AccessToken.by_refresh_token(token_to_revoke.refresh_token).revoked?).to be_falsey
114
98
  expect(authorization_access_token.revoked?).to be_falsey
115
-
116
99
  end
117
100
  end
118
- context 'The access token to revoke app is the same than the authorization access token' do
119
101
 
102
+ context 'The access token to revoke app is the same than the authorization access token' do
120
103
  let(:other_resource_owner) { User.create!(name: 'Matheo', password: 'pareto') }
121
104
  let(:token_to_revoke) do
122
105
  FactoryGirl.create(:access_token,
@@ -125,8 +108,7 @@ feature 'Revoke Token Flow' do
125
108
  use_refresh_token: true)
126
109
  end
127
110
 
128
- scenario 'client wants to revoke the given access token' do
129
-
111
+ it 'client wants to revoke the given access token' do
130
112
  post revocation_token_endpoint_url, { token: token_to_revoke.token }, headers
131
113
 
132
114
  token_to_revoke.reload
@@ -136,12 +118,10 @@ feature 'Revoke Token Flow' do
136
118
  expect(token_to_revoke.revoked?).to be_falsey
137
119
  expect(Doorkeeper::AccessToken.by_refresh_token(token_to_revoke.refresh_token).revoked?).to be_falsey
138
120
  expect(authorization_access_token.revoked?).to be_falsey
139
-
140
121
  end
141
122
  end
142
123
 
143
124
  context 'With valid refresh token to revoke' do
144
-
145
125
  let(:token_to_revoke) do
146
126
  FactoryGirl.create(:access_token,
147
127
  application: client_application,
@@ -149,8 +129,7 @@ feature 'Revoke Token Flow' do
149
129
  use_refresh_token: true)
150
130
  end
151
131
 
152
- scenario 'client wants to revoke the given refresh token' do
153
-
132
+ it 'client wants to revoke the given refresh token' do
154
133
  post revocation_token_endpoint_url, { token: token_to_revoke.refresh_token, token_type_hint: 'refresh_token' }, headers
155
134
  authorization_access_token.reload
156
135
  token_to_revoke.reload
@@ -158,7 +137,6 @@ feature 'Revoke Token Flow' do
158
137
  expect(response).to be_success
159
138
  expect(Doorkeeper::AccessToken.by_refresh_token(token_to_revoke.refresh_token).revoked?).to be_truthy
160
139
  expect(authorization_access_token).to_not be_revoked
161
-
162
140
  end
163
141
  end
164
142
  end
@@ -1,13 +1,13 @@
1
1
  require 'spec_helper_integration'
2
2
 
3
- feature 'ActionController::Metal API' do
4
- background do
3
+ describe 'ActionController::Metal API' do
4
+ before do
5
5
  @client = FactoryGirl.create(:application)
6
6
  @resource = User.create!(name: 'Joe', password: 'sekret')
7
7
  @token = client_is_authorized(@client, @resource)
8
8
  end
9
9
 
10
- scenario 'client requests protected resource with valid token' do
10
+ it 'client requests protected resource with valid token' do
11
11
  get "/metal.json?access_token=#{@token.token}"
12
12
  should_have_json 'ok', true
13
13
  end
@@ -40,6 +40,17 @@ feature 'Private API' do
40
40
  expect(page.body).to have_content('index')
41
41
  end
42
42
 
43
+ scenario 'access token with no default scopes' do
44
+ Doorkeeper.configuration.instance_eval {
45
+ @default_scopes = Doorkeeper::OAuth::Scopes.from_array([:public])
46
+ @scopes = default_scopes + optional_scopes
47
+ }
48
+ @token.update_attribute :scopes, 'dummy'
49
+ with_access_token_header @token.token
50
+ visit '/full_protected_resources'
51
+ response_status_should_be 403
52
+ end
53
+
43
54
  scenario 'access token with no allowed scopes' do
44
55
  @token.update_attribute :scopes, nil
45
56
  with_access_token_header @token.token
@@ -42,7 +42,7 @@ describe 'Custom controller for routes' do
42
42
  end
43
43
 
44
44
  it 'POST /space/oauth/revoke routes to tokens controller' do
45
- post('/space/oauth/revoke').should route_to('custom_authorizations#revoke')
45
+ expect(post('/space/oauth/revoke')).to route_to('custom_authorizations#revoke')
46
46
  end
47
47
 
48
48
  it 'GET /space/oauth/applications routes to applications controller' do
@@ -68,5 +68,4 @@ describe 'Custom controller for routes' do
68
68
  it 'GET /outer_space/oauth/token_info is not routable' do
69
69
  expect(get('/outer_space/oauth/token/info')).not_to be_routable
70
70
  end
71
-
72
71
  end
@@ -18,7 +18,7 @@ describe 'Default routes' do
18
18
  end
19
19
 
20
20
  it 'POST /oauth/revoke routes to tokens controller' do
21
- post('/oauth/revoke').should route_to('doorkeeper/tokens#revoke')
21
+ expect(post('/oauth/revoke')).to route_to('doorkeeper/tokens#revoke')
22
22
  end
23
23
 
24
24
  it 'GET /oauth/applications routes to applications controller' do
@@ -32,5 +32,4 @@ describe 'Default routes' do
32
32
  it 'GET /oauth/token/info route to authorzed tokeninfo controller' do
33
33
  expect(get('/oauth/token/info')).to route_to('doorkeeper/token_info#show')
34
34
  end
35
-
36
35
  end
@@ -28,5 +28,4 @@ describe 'Scoped routes' do
28
28
  it 'GET /scope/token/info route to authorzed tokeninfo controller' do
29
29
  expect(get('/scope/token/info')).to route_to('doorkeeper/token_info#show')
30
30
  end
31
-
32
31
  end
@@ -8,14 +8,19 @@ DOORKEEPER_ORM = (orm && orm[1] || :active_record).to_sym
8
8
  $LOAD_PATH.unshift File.dirname(__FILE__)
9
9
 
10
10
  require 'capybara/rspec'
11
- require 'rspec/active_model/mocks'
12
11
  require 'dummy/config/environment'
13
12
  require 'rspec/rails'
14
- require 'rspec/autorun'
15
13
  require 'generator_spec/test_case'
16
14
  require 'timecop'
17
15
  require 'database_cleaner'
18
16
 
17
+ # Load JRuby SQLite3 if in that platform
18
+ begin
19
+ require 'jdbc/sqlite3'
20
+ Jdbc::SQLite3.load_driver
21
+ rescue LoadError
22
+ end
23
+
19
24
  Rails.logger.info "====> Doorkeeper.orm = #{Doorkeeper.configuration.orm.inspect}"
20
25
  if Doorkeeper.configuration.orm == :active_record
21
26
  Rails.logger.info "======> active_record.table_name_prefix = #{Rails.configuration.active_record.table_name_prefix.inspect}"
@@ -24,11 +29,7 @@ end
24
29
  Rails.logger.info "====> Rails version: #{Rails.version}"
25
30
  Rails.logger.info "====> Ruby version: #{RUBY_VERSION}"
26
31
 
27
- if [:mongoid2, :mongoid3, :mongoid4].include?(DOORKEEPER_ORM)
28
- require "support/orm/mongoid"
29
- else
30
- require "support/orm/#{DOORKEEPER_ORM}"
31
- end
32
+ require "support/orm/#{DOORKEEPER_ORM}"
32
33
 
33
34
  ENGINE_RAILS_ROOT = File.join(File.dirname(__FILE__), '../')
34
35
 
@@ -40,6 +41,8 @@ RSpec.configure do |config|
40
41
 
41
42
  config.infer_base_class_for_anonymous_controllers = false
42
43
 
44
+ config.include RSpec::Rails::RequestExampleGroup, type: :request
45
+
43
46
  config.before do
44
47
  DatabaseCleaner.start
45
48
  Doorkeeper.configure { orm DOORKEEPER_ORM }
@@ -8,4 +8,4 @@ module AccessTokenRequestHelper
8
8
  end
9
9
  end
10
10
 
11
- RSpec.configuration.send :include, AccessTokenRequestHelper, type: :request
11
+ RSpec.configuration.send :include, AccessTokenRequestHelper
@@ -38,4 +38,4 @@ module AuthorizationRequestHelper
38
38
  end
39
39
  end
40
40
 
41
- RSpec.configuration.send :include, AuthorizationRequestHelper, type: :request
41
+ RSpec.configuration.send :include, AuthorizationRequestHelper
@@ -6,4 +6,4 @@ module ConfigHelper
6
6
  end
7
7
  end
8
8
 
9
- RSpec.configuration.send :include, ConfigHelper, type: :request
9
+ RSpec.configuration.send :include, ConfigHelper
@@ -42,4 +42,4 @@ module ModelHelper
42
42
  end
43
43
  end
44
44
 
45
- RSpec.configuration.send :include, ModelHelper, type: :request
45
+ RSpec.configuration.send :include, ModelHelper
@@ -73,4 +73,4 @@ module RequestSpecHelper
73
73
  end
74
74
  end
75
75
 
76
- RSpec.configuration.send :include, RequestSpecHelper, type: :request
76
+ RSpec.configuration.send :include, RequestSpecHelper
@@ -52,4 +52,4 @@ module UrlHelper
52
52
  end
53
53
  end
54
54
 
55
- RSpec.configuration.send :include, UrlHelper, type: :request
55
+ RSpec.configuration.send :include, UrlHelper
@@ -46,7 +46,7 @@ shared_examples 'a unique token' do
46
46
  token2.token = token1.token
47
47
  expect do
48
48
  token2.save!(validate: false)
49
- end.to raise_error
49
+ end.to raise_error(ActiveRecord::RecordNotUnique)
50
50
  end
51
51
  end
52
52
  end
@@ -55,6 +55,11 @@ describe RedirectUriValidator do
55
55
  expect(subject).to be_valid
56
56
  end
57
57
 
58
+ it 'accepts app redirect uri' do
59
+ subject.redirect_uri = 'some-awesome-app://oauth/callback'
60
+ expect(subject).to be_valid
61
+ end
62
+
58
63
  it 'accepts a non secured protocol when disabled' do
59
64
  subject.redirect_uri = 'http://example.com/callback'
60
65
  allow(Doorkeeper.configuration).to receive(