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
@@ -1,9 +1,9 @@
1
1
  FactoryGirl.define do
2
- factory :access_grant, :class => Doorkeeper::AccessGrant do
2
+ factory :access_grant, class: Doorkeeper::AccessGrant do
3
3
  sequence(:resource_owner_id) { |n| n }
4
4
  application
5
- redirect_uri "https://app.com/callback"
5
+ redirect_uri 'https://app.com/callback'
6
6
  expires_in 100
7
- scopes "public write"
7
+ scopes 'public write'
8
8
  end
9
9
  end
@@ -1,5 +1,5 @@
1
1
  FactoryGirl.define do
2
- factory :access_token, :class => Doorkeeper::AccessToken do
2
+ factory :access_token, class: Doorkeeper::AccessToken do
3
3
  sequence(:resource_owner_id) { |n| n }
4
4
  application
5
5
  expires_in 2.hours
@@ -1,6 +1,6 @@
1
1
  FactoryGirl.define do
2
- factory :application, :class => Doorkeeper::Application do
3
- sequence(:name){ |n| "Application #{n}" }
4
- redirect_uri "https://app.com/callback"
2
+ factory :application, class: Doorkeeper::Application do
3
+ sequence(:name) { |n| "Application #{n}" }
4
+ redirect_uri 'https://app.com/callback'
5
5
  end
6
6
  end
@@ -1,23 +1,22 @@
1
1
  require 'spec_helper_integration'
2
2
  require 'generators/doorkeeper/application_owner_generator'
3
3
 
4
-
5
4
  describe 'Doorkeeper::ApplicationOwnerGenerator' do
6
5
  include GeneratorSpec::TestCase
7
6
 
8
7
  tests Doorkeeper::ApplicationOwnerGenerator
9
- destination ::File.expand_path("../tmp/dummy", __FILE__)
8
+ destination ::File.expand_path('../tmp/dummy', __FILE__)
10
9
 
11
- describe "after running the generator" do
10
+ describe 'after running the generator' do
12
11
  before :each do
13
12
  prepare_destination
14
- FileUtils.mkdir(::File.expand_path("config", Pathname(destination_root)))
15
- FileUtils.copy_file(::File.expand_path("../templates/routes.rb", __FILE__), ::File.expand_path("config/routes.rb", Pathname.new(destination_root)))
13
+ FileUtils.mkdir(::File.expand_path('config', Pathname(destination_root)))
14
+ FileUtils.copy_file(::File.expand_path('../templates/routes.rb', __FILE__), ::File.expand_path('config/routes.rb', Pathname.new(destination_root)))
16
15
  run_generator
17
16
  end
18
17
 
19
- it "creates a migration" do
20
- assert_migration "db/migrate/add_owner_to_application.rb"
18
+ it 'creates a migration' do
19
+ assert_migration 'db/migrate/add_owner_to_application.rb'
21
20
  end
22
21
  end
23
22
  end
@@ -5,27 +5,27 @@ describe 'Doorkeeper::InstallGenerator' do
5
5
  include GeneratorSpec::TestCase
6
6
 
7
7
  tests Doorkeeper::InstallGenerator
8
- destination ::File.expand_path("../tmp/dummy", __FILE__)
8
+ destination ::File.expand_path('../tmp/dummy', __FILE__)
9
9
 
10
- describe "after running the generator" do
10
+ describe 'after running the generator' do
11
11
  before :each do
12
12
  prepare_destination
13
- FileUtils.mkdir(::File.expand_path("config", Pathname(destination_root)))
14
- FileUtils.mkdir(::File.expand_path("db", Pathname(destination_root)))
15
- FileUtils.copy_file(::File.expand_path("../templates/routes.rb", __FILE__), ::File.expand_path("config/routes.rb", Pathname.new(destination_root)))
13
+ FileUtils.mkdir(::File.expand_path('config', Pathname(destination_root)))
14
+ FileUtils.mkdir(::File.expand_path('db', Pathname(destination_root)))
15
+ FileUtils.copy_file(::File.expand_path('../templates/routes.rb', __FILE__), ::File.expand_path('config/routes.rb', Pathname.new(destination_root)))
16
16
  run_generator
17
17
  end
18
18
 
19
- it "creates an initializer file" do
19
+ it 'creates an initializer file' do
20
20
  assert_file 'config/initializers/doorkeeper.rb'
21
21
  end
22
22
 
23
- it "copies the locale file" do
23
+ it 'copies the locale file' do
24
24
  assert_file 'config/locales/doorkeeper.en.yml'
25
25
  end
26
26
 
27
- it "adds sample route" do
28
- assert_file "config/routes.rb", /use_doorkeeper/
27
+ it 'adds sample route' do
28
+ assert_file 'config/routes.rb', /use_doorkeeper/
29
29
  end
30
30
  end
31
31
  end
@@ -5,16 +5,16 @@ describe 'Doorkeeper::MigrationGenerator' do
5
5
  include GeneratorSpec::TestCase
6
6
 
7
7
  tests Doorkeeper::MigrationGenerator
8
- destination ::File.expand_path("../tmp/dummy", __FILE__)
8
+ destination ::File.expand_path('../tmp/dummy', __FILE__)
9
9
 
10
- describe "after running the generator" do
10
+ describe 'after running the generator' do
11
11
  before :each do
12
12
  prepare_destination
13
13
  run_generator
14
14
  end
15
15
 
16
- it "creates a migration" do
17
- assert_migration "db/migrate/create_doorkeeper_tables.rb"
16
+ it 'creates a migration' do
17
+ assert_migration 'db/migrate/create_doorkeeper_tables.rb'
18
18
  end
19
19
  end
20
20
  end
@@ -1,11 +1,11 @@
1
1
  require 'spec_helper_integration'
2
2
 
3
- describe Doorkeeper, "configuration" do
3
+ describe Doorkeeper, 'configuration' do
4
4
  subject { Doorkeeper.configuration }
5
5
 
6
- describe "resource_owner_authenticator" do
7
- it "sets the block that is accessible via authenticate_resource_owner" do
8
- block = proc do end
6
+ describe 'resource_owner_authenticator' do
7
+ it 'sets the block that is accessible via authenticate_resource_owner' do
8
+ block = proc {}
9
9
  Doorkeeper.configure do
10
10
  orm DOORKEEPER_ORM
11
11
  resource_owner_authenticator &block
@@ -14,9 +14,9 @@ describe Doorkeeper, "configuration" do
14
14
  end
15
15
  end
16
16
 
17
- describe "admin_authenticator" do
18
- it "sets the block that is accessible via authenticate_admin" do
19
- block = proc do end
17
+ describe 'admin_authenticator' do
18
+ it 'sets the block that is accessible via authenticate_admin' do
19
+ block = proc {}
20
20
  Doorkeeper.configure do
21
21
  orm DOORKEEPER_ORM
22
22
  admin_authenticator &block
@@ -25,12 +25,12 @@ describe Doorkeeper, "configuration" do
25
25
  end
26
26
  end
27
27
 
28
- describe "access_token_expires_in" do
29
- it "has 2 hours by default" do
28
+ describe 'access_token_expires_in' do
29
+ it 'has 2 hours by default' do
30
30
  expect(subject.access_token_expires_in).to eq(2.hours)
31
31
  end
32
32
 
33
- it "can change the value" do
33
+ it 'can change the value' do
34
34
  Doorkeeper.configure do
35
35
  orm DOORKEEPER_ORM
36
36
  access_token_expires_in 4.hours
@@ -38,7 +38,7 @@ describe Doorkeeper, "configuration" do
38
38
  expect(subject.access_token_expires_in).to eq(4.hours)
39
39
  end
40
40
 
41
- it "can be set to nil" do
41
+ it 'can be set to nil' do
42
42
  Doorkeeper.configure do
43
43
  orm DOORKEEPER_ORM
44
44
  access_token_expires_in nil
@@ -47,20 +47,20 @@ describe Doorkeeper, "configuration" do
47
47
  end
48
48
  end
49
49
 
50
- describe "scopes" do
51
- it "has default scopes" do
52
- Doorkeeper.configure {
50
+ describe 'scopes' do
51
+ it 'has default scopes' do
52
+ Doorkeeper.configure do
53
53
  orm DOORKEEPER_ORM
54
54
  default_scopes :public
55
- }
55
+ end
56
56
  expect(subject.default_scopes).to include('public')
57
57
  end
58
58
 
59
59
  it 'has optional scopes' do
60
- Doorkeeper.configure {
60
+ Doorkeeper.configure do
61
61
  orm DOORKEEPER_ORM
62
62
  optional_scopes :write, :update
63
- }
63
+ end
64
64
  expect(subject.optional_scopes).to include('write', 'update')
65
65
  end
66
66
 
@@ -74,18 +74,35 @@ describe Doorkeeper, "configuration" do
74
74
  end
75
75
  end
76
76
 
77
- describe "use_refresh_token" do
78
- it "is false by default" do
77
+ describe 'use_refresh_token' do
78
+ it 'is false by default' do
79
79
  expect(subject.refresh_token_enabled?).to be_false
80
80
  end
81
81
 
82
- it "can change the value" do
83
- Doorkeeper.configure {
82
+ it 'can change the value' do
83
+ Doorkeeper.configure do
84
84
  orm DOORKEEPER_ORM
85
85
  use_refresh_token
86
- }
86
+ end
87
87
  expect(subject.refresh_token_enabled?).to be_true
88
88
  end
89
+
90
+ it "does not includes 'refresh_token' in authorization_response_types" do
91
+ expect(subject.token_grant_types).not_to include 'refresh_token'
92
+ end
93
+
94
+ context "is enabled" do
95
+ before do
96
+ Doorkeeper.configure {
97
+ orm DOORKEEPER_ORM
98
+ use_refresh_token
99
+ }
100
+ end
101
+
102
+ it "includes 'refresh_token' in authorization_response_types" do
103
+ expect(subject.token_grant_types).to include 'refresh_token'
104
+ end
105
+ end
89
106
  end
90
107
 
91
108
  describe 'client_credentials' do
@@ -93,11 +110,11 @@ describe Doorkeeper, "configuration" do
93
110
  expect(subject.client_credentials_methods).to eq([:from_basic, :from_params])
94
111
  end
95
112
 
96
- it "can change the value" do
97
- Doorkeeper.configure {
113
+ it 'can change the value' do
114
+ Doorkeeper.configure do
98
115
  orm DOORKEEPER_ORM
99
116
  client_credentials :from_digest, :from_params
100
- }
117
+ end
101
118
  expect(subject.client_credentials_methods).to eq([:from_digest, :from_params])
102
119
  end
103
120
  end
@@ -107,68 +124,143 @@ describe Doorkeeper, "configuration" do
107
124
  expect(subject.access_token_methods).to eq([:from_bearer_authorization, :from_access_token_param, :from_bearer_param])
108
125
  end
109
126
 
110
- it "can change the value" do
111
- Doorkeeper.configure {
127
+ it 'can change the value' do
128
+ Doorkeeper.configure do
112
129
  orm DOORKEEPER_ORM
113
130
  access_token_methods :from_access_token_param, :from_bearer_param
114
- }
131
+ end
115
132
  expect(subject.access_token_methods).to eq([:from_access_token_param, :from_bearer_param])
116
133
  end
117
134
  end
118
135
 
119
- describe "enable_application_owner" do
120
- it "is disabled by default" do
136
+ describe 'enable_application_owner' do
137
+ it 'is disabled by default' do
121
138
  expect(Doorkeeper.configuration.enable_application_owner?).not_to be_true
122
139
  end
123
140
 
124
- context "when enabled without confirmation" do
141
+ context 'when enabled without confirmation' do
125
142
  before do
126
143
  Doorkeeper.configure do
127
144
  orm DOORKEEPER_ORM
128
145
  enable_application_owner
129
146
  end
130
147
  end
131
- it "adds support for application owner" do
148
+ it 'adds support for application owner' do
132
149
  expect(Doorkeeper::Application.new).to respond_to :owner
133
150
  end
134
- it "Doorkeeper.configuration.confirm_application_owner? returns false" do
151
+ it 'Doorkeeper.configuration.confirm_application_owner? returns false' do
135
152
  expect(Doorkeeper.configuration.confirm_application_owner?).not_to be_true
136
153
  end
137
154
  end
138
155
 
139
- context "when enabled with confirmation set to true" do
156
+ context 'when enabled with confirmation set to true' do
140
157
  before do
141
158
  Doorkeeper.configure do
142
159
  orm DOORKEEPER_ORM
143
- enable_application_owner :confirmation => true
160
+ enable_application_owner confirmation: true
144
161
  end
145
162
  end
146
- it "adds support for application owner" do
163
+ it 'adds support for application owner' do
147
164
  expect(Doorkeeper::Application.new).to respond_to :owner
148
165
  end
149
- it "Doorkeeper.configuration.confirm_application_owner? returns true" do
166
+ it 'Doorkeeper.configuration.confirm_application_owner? returns true' do
150
167
  expect(Doorkeeper.configuration.confirm_application_owner?).to be_true
151
168
  end
152
169
  end
153
170
  end
154
171
 
155
- describe "wildcard_redirect_uri" do
156
- it "is disabled by default" do
172
+ describe 'wildcard_redirect_uri' do
173
+ it 'is disabled by default' do
157
174
  Doorkeeper.configuration.wildcard_redirect_uri.should be_false
158
175
  end
159
176
  end
160
177
 
161
- describe "realm" do
162
- it "is \"Doorkeeper\" by default" do
163
- expect(Doorkeeper.configuration.realm).to eq("Doorkeeper")
178
+ describe 'realm' do
179
+ it 'is \'Doorkeeper\' by default' do
180
+ expect(Doorkeeper.configuration.realm).to eq('Doorkeeper')
181
+ end
182
+
183
+ it 'can change the value' do
184
+ Doorkeeper.configure do
185
+ orm DOORKEEPER_ORM
186
+ realm 'Example'
187
+ end
188
+ expect(subject.realm).to eq('Example')
189
+ end
190
+ end
191
+
192
+ describe "grant_flows" do
193
+ it "is set to all grant flows by default" do
194
+ expect(Doorkeeper.configuration.grant_flows).to eq [
195
+ 'authorization_code',
196
+ 'implicit',
197
+ 'password',
198
+ 'client_credentials'
199
+ ]
164
200
  end
165
201
 
166
202
  it "can change the value" do
167
203
  Doorkeeper.configure {
168
204
  orm DOORKEEPER_ORM
169
- realm "Example"
205
+ grant_flows [ 'authorization_code', 'implicit' ]
170
206
  }
171
- expect(subject.realm).to eq("Example")
207
+ expect(subject.grant_flows).to eq ['authorization_code', 'implicit']
208
+ end
209
+
210
+ context "when including 'authorization_code'" do
211
+ before do
212
+ Doorkeeper.configure {
213
+ orm DOORKEEPER_ORM
214
+ grant_flows ['authorization_code']
215
+ }
216
+ end
217
+
218
+ it "includes 'code' in authorization_response_types" do
219
+ expect(subject.authorization_response_types).to include 'code'
220
+ end
221
+
222
+ it "includes 'authorization_code' in token_grant_types" do
223
+ expect(subject.token_grant_types).to include 'authorization_code'
224
+ end
225
+ end
226
+
227
+ context "when including 'implicit'" do
228
+ before do
229
+ Doorkeeper.configure {
230
+ orm DOORKEEPER_ORM
231
+ grant_flows ['implicit']
232
+ }
233
+ end
234
+
235
+ it "includes 'token' in authorization_response_types" do
236
+ expect(subject.authorization_response_types).to include 'token'
237
+ end
238
+ end
239
+
240
+ context "when including 'password'" do
241
+ before do
242
+ Doorkeeper.configure {
243
+ orm DOORKEEPER_ORM
244
+ grant_flows ['password']
245
+ }
246
+ end
247
+
248
+ it "includes 'password' in token_grant_types" do
249
+ expect(subject.token_grant_types).to include 'password'
250
+ end
251
+ end
252
+
253
+ context "when including 'client_credentials'" do
254
+ before do
255
+ Doorkeeper.configure {
256
+ orm DOORKEEPER_ORM
257
+ grant_flows ['client_credentials']
258
+ }
259
+ end
260
+
261
+ it "includes 'client_credentials' in token_grant_types" do
262
+ expect(subject.token_grant_types).to include 'client_credentials'
263
+ end
172
264
  end
173
265
  end
174
266
 
@@ -15,37 +15,37 @@ describe 'Expirable' do
15
15
  end
16
16
 
17
17
  describe :expired? do
18
- it "is not expired if time has not passed" do
18
+ it 'is not expired if time has not passed' do
19
19
  allow(subject).to receive(:expires_in).and_return(2.minutes)
20
20
  expect(subject).not_to be_expired
21
21
  end
22
22
 
23
- it "is expired if time has passed" do
23
+ it 'is expired if time has passed' do
24
24
  allow(subject).to receive(:expires_in).and_return(10.seconds)
25
25
  expect(subject).to be_expired
26
26
  end
27
27
 
28
- it "is not expired if expires_in is not set" do
28
+ it 'is not expired if expires_in is not set' do
29
29
  allow(subject).to receive(:expires_in).and_return(nil)
30
30
  expect(subject).not_to be_expired
31
31
  end
32
32
  end
33
33
 
34
34
  describe :expires_in_seconds do
35
- it "should return the amount of time remaining until the token is expired" do
35
+ it 'should return the amount of time remaining until the token is expired' do
36
36
  allow(subject).to receive(:expires_in).and_return(2.minutes)
37
- expect(subject.expires_in_seconds).to eq(60)
37
+ expect(subject.expires_in_seconds).to eq(60)
38
38
  end
39
39
 
40
- it "should return 0 when expired" do
40
+ it 'should return 0 when expired' do
41
41
  allow(subject).to receive(:expires_in).and_return(30.seconds)
42
- expect(subject.expires_in_seconds).to eq(0)
42
+ expect(subject.expires_in_seconds).to eq(0)
43
43
  end
44
44
 
45
- it "should return nil when expires_in is nil" do
45
+ it 'should return nil when expires_in is nil' do
46
46
  allow(subject).to receive(:expires_in).and_return(nil)
47
47
  expect(subject.expires_in_seconds).to be_nil
48
48
  end
49
-
49
+
50
50
  end
51
51
  end