doorkeeper-mongodb 5.2.1 → 5.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -27
  3. data/lib/doorkeeper/orm/concerns/mongoid/ownership.rb +1 -1
  4. data/lib/doorkeeper/orm/concerns/mongoid/resource_ownerable.rb +1 -1
  5. data/lib/doorkeeper/orm/mongoid4.rb +18 -0
  6. data/lib/doorkeeper/orm/mongoid5.rb +18 -0
  7. data/lib/doorkeeper/orm/mongoid6.rb +18 -0
  8. data/lib/doorkeeper/orm/mongoid7.rb +18 -0
  9. data/lib/doorkeeper-mongodb/mixins/mongoid/access_grant_mixin.rb +7 -6
  10. data/lib/doorkeeper-mongodb/mixins/mongoid/access_token_mixin.rb +8 -5
  11. data/lib/doorkeeper-mongodb/mixins/mongoid/application_mixin.rb +82 -5
  12. data/lib/doorkeeper-mongodb/mixins/mongoid/base_mixin.rb +0 -8
  13. data/lib/doorkeeper-mongodb/mixins/mongoid/json_serializable.rb +17 -0
  14. data/lib/doorkeeper-mongodb/version.rb +1 -1
  15. data/lib/doorkeeper-mongodb.rb +1 -0
  16. data/spec/controllers/application_metal_controller_spec.rb +4 -4
  17. data/spec/controllers/applications_controller_spec.rb +198 -202
  18. data/spec/controllers/authorizations_controller_spec.rb +32 -31
  19. data/spec/controllers/protected_resources_controller_spec.rb +10 -10
  20. data/spec/controllers/token_info_controller_spec.rb +1 -1
  21. data/spec/controllers/tokens_controller_spec.rb +105 -62
  22. data/spec/doorkeeper/redirect_uri_validator_spec.rb +183 -0
  23. data/spec/{lib → doorkeeper}/server_spec.rb +5 -4
  24. data/spec/{lib → doorkeeper}/stale_records_cleaner_spec.rb +8 -7
  25. data/spec/{version → doorkeeper}/version_spec.rb +3 -3
  26. data/spec/dummy/app/assets/config/manifest.js +0 -0
  27. data/spec/dummy/app/controllers/application_controller.rb +0 -0
  28. data/spec/dummy/app/controllers/custom_authorizations_controller.rb +0 -0
  29. data/spec/dummy/app/controllers/full_protected_resources_controller.rb +0 -0
  30. data/spec/dummy/app/controllers/home_controller.rb +0 -0
  31. data/spec/dummy/app/controllers/metal_controller.rb +0 -0
  32. data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +0 -0
  33. data/spec/dummy/app/helpers/application_helper.rb +0 -0
  34. data/spec/dummy/app/models/user.rb +0 -1
  35. data/spec/dummy/app/views/home/index.html.erb +0 -0
  36. data/spec/dummy/app/views/layouts/application.html.erb +0 -0
  37. data/spec/dummy/config/application.rb +0 -0
  38. data/spec/dummy/config/boot.rb +0 -0
  39. data/spec/dummy/config/database.yml +0 -0
  40. data/spec/dummy/config/environment.rb +0 -0
  41. data/spec/dummy/config/environments/development.rb +0 -0
  42. data/spec/dummy/config/environments/production.rb +0 -0
  43. data/spec/dummy/config/environments/test.rb +0 -0
  44. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -0
  45. data/spec/dummy/config/initializers/doorkeeper.rb +0 -0
  46. data/spec/dummy/config/initializers/secret_token.rb +0 -0
  47. data/spec/dummy/config/initializers/session_store.rb +0 -0
  48. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -0
  49. data/spec/dummy/config/locales/doorkeeper.en.yml +0 -0
  50. data/spec/dummy/config/mongo.yml +2 -2
  51. data/spec/dummy/config/routes.rb +0 -0
  52. data/spec/dummy/config.ru +0 -0
  53. data/spec/dummy/db/migrate/20111122132257_create_users.rb +0 -0
  54. data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +0 -0
  55. data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +0 -0
  56. data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +0 -0
  57. data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +0 -0
  58. data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +0 -0
  59. data/spec/dummy/db/migrate/20180210183654_add_confidential_to_applications.rb +0 -0
  60. data/spec/dummy/db/schema.rb +0 -0
  61. data/spec/dummy/public/404.html +0 -0
  62. data/spec/dummy/public/422.html +0 -0
  63. data/spec/dummy/public/500.html +0 -0
  64. data/spec/dummy/public/favicon.ico +0 -0
  65. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/-o/-ofn45zIfO5vx4VD6m6NXesLf6da5usA-Sbw2SVju3o.cache +0 -0
  66. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/0_/0_ouGcG_o_1zmVmBe-tdQYk594LBwVa1bumjrKtdfEw.cache +0 -0
  67. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/2X/2XMMcHbyTSRqh1GkV0xzyIETNtt-zgN6iniziShaKmQ.cache +0 -0
  68. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/4Q/4QQw-pMQ98JIj3xdcFhGBQdysdGPY9rWffRqWMmyjew.cache +0 -0
  69. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/7H/7HjRsym0tTpXFCVhWt6kteMs_-CozKVbr9s5syHm8es.cache +0 -0
  70. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/8B/8BxJyv22HPFHu1se_l2J8qW1N9NzZ16UOWOy1YMSgs4.cache +0 -0
  71. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/8D/8DJG7JfPvShfLLyeSom6NZ_TcQc6QH27tJ7prEWZPfI.cache +0 -0
  72. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/9x/9xjtGv-yKjj62x9uFwBZg8pTSh9ERPAgANwNo9uwIaA.cache +0 -0
  73. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Bt/BtXO7f0PZ8DNt3TMLYM-zY7LkbWa_KgyB0v1V98M1CQ.cache +0 -0
  74. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/E0/E02f1Q2tutWumMulGCFNfqQNjvEP_hMAK_5E83eWepI.cache +0 -0
  75. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/EZ/EZGpd6pUEJZxO6uT2yIS4Fpn5KX7VDgC9VB3AaemF5Q.cache +0 -0
  76. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/FJ/FJlQpfMtpRbrM5P8A7d2FAelFKwo6GrVs2xks8z5GKU.cache +0 -0
  77. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/L8/L8mOWakJlWKr6MU85rj0V7yGFfNyIR6vE6YXtqArPGw.cache +0 -0
  78. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Lk/LklIq5hrBAPESXVUpFMwQ9L-1qTj90sPVi6U19_Xi-Q.cache +0 -0
  79. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/MB/MBWRxa9S470ee8suxVKp0jYgv6K6FQOqKGV0kPGQNMs.cache +0 -0
  80. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Ma/MaK3K1AoZZ4xM5fOOifhROd73hfZJpP4yGbkGdoYtEk.cache +0 -0
  81. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/PA/PAH_jI20wRw12tngeJ-V619c30avNLDu5U9Z-9Pc5SQ.cache +0 -0
  82. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Ph/Ph7RtH_NvG2I8XpTa8mA8SBQXZDzBPVIh4CH6g7OXJ0.cache +0 -0
  83. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{eS/eSL1QMz46gKLM0GR6S9fL6uyARPxOImcappZ9_ZtSyg.cache → Pm/PmheG0PGFqDws1qgFOxOyIL-gpMof3Ar9eSRKVLYuik.cache} +0 -0
  84. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Pn/PnXU_mkG2fLZFm9BwiZ03BZdBTjKuInP-cRXjHS7yJo.cache +0 -0
  85. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Qs/QsVgO6vM5Yn9oeYTYlrqtyVnK6sdVDWDa083N7zpfHw.cache +0 -0
  86. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/So/So59ksdx2dw-_A3-zFZ6Palr7fROjm7_0JDZb04temw.cache +0 -0
  87. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Wt/WtXL_iDofLeTH_v0Yf3PM421r9b1V0g-VBvMPeu9KA0.cache +0 -0
  88. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/b6/b6QRH6ZdCc0e6bUWu4qni_kZmptaMgWciO8Jl9q6_p8.cache +0 -0
  89. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/dX/dX6FDdUIy8yBCOoaoXcjf71rX9N_bpiXGJ4Urt32NTk.cache +0 -0
  90. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/jC/jCTZ1jAldKBn4OTANBBmCKzxLrDgok1ur4meoTqlDNg.cache +0 -0
  91. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/qT/qTQIQsmS0Wbbg2JxNn9rxdI5qVOTg5SfyQdaTvr9vLo.cache +0 -0
  92. data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/yN/yNOFGOsnHmxXNMkuEAWuL1u3jlmdvrdeoTx6DDJ1in8.cache +0 -0
  93. data/spec/factories.rb +0 -0
  94. data/spec/grape/grape_integration_spec.rb +1 -1
  95. data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +1 -1
  96. data/spec/lib/config_spec.rb +23 -12
  97. data/spec/lib/doorkeeper_spec.rb +4 -4
  98. data/spec/lib/models/expirable_spec.rb +9 -9
  99. data/spec/lib/models/reusable_spec.rb +2 -2
  100. data/spec/lib/models/revocable_spec.rb +4 -7
  101. data/spec/lib/models/scopes_spec.rb +7 -7
  102. data/spec/lib/models/secret_storable_spec.rb +9 -8
  103. data/spec/lib/oauth/authorization/uri_builder_spec.rb +23 -27
  104. data/spec/lib/oauth/authorization_code_request_spec.rb +6 -6
  105. data/spec/lib/oauth/base_request_spec.rb +11 -27
  106. data/spec/lib/oauth/base_response_spec.rb +2 -2
  107. data/spec/lib/oauth/client/credentials_spec.rb +25 -25
  108. data/spec/lib/oauth/client_credentials/creator_spec.rb +89 -91
  109. data/spec/lib/oauth/client_credentials/issuer_spec.rb +84 -86
  110. data/spec/lib/oauth/client_credentials/validation_spec.rb +72 -39
  111. data/spec/lib/oauth/client_credentials_integration_spec.rb +5 -5
  112. data/spec/lib/oauth/client_credentials_request_spec.rb +7 -10
  113. data/spec/lib/oauth/client_spec.rb +8 -8
  114. data/spec/lib/oauth/code_request_spec.rb +5 -5
  115. data/spec/lib/oauth/code_response_spec.rb +4 -4
  116. data/spec/lib/oauth/error_response_spec.rb +6 -5
  117. data/spec/lib/oauth/error_spec.rb +1 -1
  118. data/spec/lib/oauth/forbidden_token_response_spec.rb +2 -2
  119. data/spec/lib/oauth/helpers/scope_checker_spec.rb +37 -37
  120. data/spec/lib/oauth/helpers/unique_token_spec.rb +2 -2
  121. data/spec/lib/oauth/helpers/uri_checker_spec.rb +54 -54
  122. data/spec/lib/oauth/invalid_request_response_spec.rb +6 -6
  123. data/spec/lib/oauth/invalid_token_response_spec.rb +4 -4
  124. data/spec/lib/oauth/password_access_token_request_spec.rb +10 -9
  125. data/spec/lib/oauth/pre_authorization_spec.rb +20 -8
  126. data/spec/lib/oauth/refresh_token_request_spec.rb +10 -10
  127. data/spec/lib/oauth/scopes_spec.rb +14 -14
  128. data/spec/lib/oauth/token_request_spec.rb +9 -9
  129. data/spec/lib/oauth/token_response_spec.rb +5 -5
  130. data/spec/lib/oauth/token_spec.rb +5 -5
  131. data/spec/lib/option_spec.rb +1 -1
  132. data/spec/lib/request/strategy_spec.rb +34 -37
  133. data/spec/lib/secret_storing/base_spec.rb +3 -2
  134. data/spec/lib/secret_storing/bcrypt_spec.rb +2 -1
  135. data/spec/lib/secret_storing/plain_spec.rb +2 -1
  136. data/spec/lib/secret_storing/sha256_hash_spec.rb +2 -1
  137. data/spec/models/doorkeeper/access_grant_spec.rb +7 -9
  138. data/spec/models/doorkeeper/access_token_spec.rb +20 -26
  139. data/spec/models/doorkeeper/application_spec.rb +83 -26
  140. data/spec/requests/applications/applications_request_spec.rb +91 -93
  141. data/spec/requests/applications/authorized_applications_spec.rb +0 -0
  142. data/spec/requests/endpoints/authorization_spec.rb +1 -1
  143. data/spec/requests/endpoints/token_spec.rb +22 -16
  144. data/spec/requests/flows/authorization_code_errors_spec.rb +12 -8
  145. data/spec/requests/flows/authorization_code_spec.rb +108 -79
  146. data/spec/requests/flows/client_credentials_spec.rb +57 -45
  147. data/spec/requests/flows/implicit_grant_errors_spec.rb +0 -0
  148. data/spec/requests/flows/implicit_grant_spec.rb +4 -4
  149. data/spec/requests/flows/password_spec.rb +253 -213
  150. data/spec/requests/flows/refresh_token_spec.rb +53 -39
  151. data/spec/requests/flows/revoke_token_spec.rb +24 -24
  152. data/spec/requests/flows/skip_authorization_spec.rb +1 -1
  153. data/spec/requests/protected_resources/metal_spec.rb +2 -2
  154. data/spec/requests/protected_resources/private_api_spec.rb +0 -0
  155. data/spec/routing/custom_controller_routes_spec.rb +1 -1
  156. data/spec/routing/default_routes_spec.rb +1 -1
  157. data/spec/routing/scoped_routes_spec.rb +1 -1
  158. data/spec/spec_helper.rb +0 -0
  159. data/spec/spec_helper_integration.rb +0 -0
  160. data/spec/support/dependencies/factory_bot.rb +0 -0
  161. data/spec/support/doorkeeper_rspec.rb +0 -0
  162. data/spec/support/helpers/access_token_request_helper.rb +0 -0
  163. data/spec/support/helpers/authorization_request_helper.rb +0 -0
  164. data/spec/support/helpers/config_helper.rb +0 -0
  165. data/spec/support/helpers/model_helper.rb +0 -0
  166. data/spec/support/helpers/request_spec_helper.rb +1 -13
  167. data/spec/support/helpers/url_helper.rb +2 -2
  168. data/spec/support/orm/active_record.rb +0 -0
  169. data/spec/support/orm/mongoid4.rb +1 -1
  170. data/spec/support/orm/mongoid5.rb +1 -1
  171. data/spec/support/orm/mongoid6.rb +1 -1
  172. data/spec/support/orm/mongoid7.rb +1 -1
  173. data/spec/support/shared/controllers_shared_context.rb +5 -38
  174. data/spec/support/shared/hashing_shared_context.rb +4 -0
  175. data/spec/support/shared/models_shared_examples.rb +6 -6
  176. metadata +154 -167
  177. data/spec/dummy/log/test.log +0 -6108
@@ -2,132 +2,154 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- module Doorkeeper
6
- describe ApplicationsController do
7
- context "JSON API" do
8
- render_views
5
+ RSpec.describe Doorkeeper::ApplicationsController do
6
+ render_views
9
7
 
10
- before do
11
- allow(Doorkeeper.configuration).to receive(:api_only).and_return(true)
12
- allow(Doorkeeper.configuration).to receive(:authenticate_admin).and_return(->(*) { true })
13
- end
8
+ context "when JSON API used" do
9
+ before do
10
+ allow(Doorkeeper.configuration).to receive(:api_only).and_return(true)
11
+ allow(Doorkeeper.configuration).to receive(:authenticate_admin).and_return(->(*) { true })
12
+ end
14
13
 
15
- it "creates an application" do
16
- expect do
17
- post :create, params: {
18
- doorkeeper_application: {
19
- name: "Example",
20
- redirect_uri: "https://example.com",
21
- }, format: :json,
22
- }
23
- end.to(change { Doorkeeper::Application.count })
14
+ it "creates an application" do
15
+ expect do
16
+ post :create, params: {
17
+ doorkeeper_application: {
18
+ name: "Example",
19
+ redirect_uri: "https://example.com",
20
+ }, format: :json,
21
+ }
22
+ end.to(change { Doorkeeper::Application.count })
24
23
 
25
- expect(response).to be_successful
24
+ expect(response).to be_successful
26
25
 
27
- expect(json_response).to include("id", "name", "uid", "secret", "redirect_uri", "scopes")
26
+ expect(json_response).to include("id", "name", "uid", "secret", "redirect_uri", "scopes")
28
27
 
29
- application = Application.last
30
- secret_from_response = json_response["secret"]
31
- expect(application.secret_matches?(secret_from_response)).to be_truthy
28
+ application = Doorkeeper::Application.last
29
+ secret_from_response = json_response["secret"]
30
+ expect(application).to be_secret_matches(secret_from_response)
32
31
 
33
- expect(json_response["name"]).to eq("Example")
34
- expect(json_response["redirect_uri"]).to eq("https://example.com")
35
- end
32
+ expect(json_response["name"]).to eq("Example")
33
+ expect(json_response["redirect_uri"]).to eq("https://example.com")
34
+ end
36
35
 
37
- it "returns validation errors on wrong create params" do
38
- expect do
39
- post :create, params: {
40
- doorkeeper_application: {
41
- name: "Example",
42
- }, format: :json,
43
- }
44
- end.not_to(change { Doorkeeper::Application.count })
36
+ it "returns validation errors on wrong create params" do
37
+ expect do
38
+ post :create, params: {
39
+ doorkeeper_application: {
40
+ name: "Example",
41
+ }, format: :json,
42
+ }
43
+ end.not_to(change { Doorkeeper::Application.count })
45
44
 
46
- expect(response).to have_http_status(422)
45
+ expect(response).to have_http_status(422)
47
46
 
48
- expect(json_response).to include("errors")
49
- end
47
+ expect(json_response).to include("errors")
48
+ end
50
49
 
51
- it "returns validations on wrong create params (unspecified scheme)" do
52
- expect do
53
- post :create, params: {
54
- doorkeeper_application: {
55
- name: "Example",
56
- redirect_uri: "app.com:80",
57
- }, format: :json,
58
- }
59
- end.not_to(change { Doorkeeper::Application.count })
50
+ it "returns validations on wrong create params (unspecified scheme)" do
51
+ expect do
52
+ post :create, params: {
53
+ doorkeeper_application: {
54
+ name: "Example",
55
+ redirect_uri: "app.com:80",
56
+ }, format: :json,
57
+ }
58
+ end.not_to(change { Doorkeeper::Application.count })
60
59
 
61
- expect(response).to have_http_status(422)
60
+ expect(response).to have_http_status(422)
62
61
 
63
- expect(json_response).to include("errors")
64
- end
62
+ expect(json_response).to include("errors")
63
+ end
65
64
 
66
- it "returns application info" do
67
- application = FactoryBot.create(:application, name: "Change me")
65
+ it "returns application info" do
66
+ application = FactoryBot.create(:application, name: "Change me")
68
67
 
69
- get :show, params: { id: application.id, format: :json }
68
+ get :show, params: { id: application.id, format: :json }
70
69
 
71
- expect(response).to be_successful
70
+ expect(response).to be_successful
72
71
 
73
- expect(json_response).to include("id", "name", "uid", "secret", "redirect_uri", "scopes")
74
- end
72
+ expect(json_response).to include("id", "name", "uid", "secret", "redirect_uri", "scopes")
73
+ end
75
74
 
76
- it "updates application" do
77
- application = FactoryBot.create(:application, name: "Change me")
75
+ it "updates application" do
76
+ application = FactoryBot.create(:application, name: "Change me")
78
77
 
79
- put :update, params: {
80
- id: application.id,
81
- doorkeeper_application: {
82
- name: "Example App",
83
- redirect_uri: "https://example.com",
84
- }, format: :json,
85
- }
78
+ put :update, params: {
79
+ id: application.id,
80
+ doorkeeper_application: {
81
+ name: "Example App",
82
+ redirect_uri: "https://example.com",
83
+ }, format: :json,
84
+ }
86
85
 
87
- expect(application.reload.name).to eq "Example App"
86
+ expect(application.reload.name).to eq "Example App"
88
87
 
89
- expect(json_response).to include("id", "name", "uid", "secret", "redirect_uri", "scopes")
90
- end
88
+ expect(json_response).to include("id", "name", "uid", "secret", "redirect_uri", "scopes")
89
+ end
91
90
 
92
- it "returns validation errors on wrong update params" do
93
- application = FactoryBot.create(:application, name: "Change me")
91
+ it "returns validation errors on wrong update params" do
92
+ application = FactoryBot.create(:application, name: "Change me")
94
93
 
95
- put :update, params: {
96
- id: application.id,
97
- doorkeeper_application: {
98
- name: "Example App",
99
- redirect_uri: "localhost:3000",
100
- }, format: :json,
101
- }
94
+ put :update, params: {
95
+ id: application.id,
96
+ doorkeeper_application: {
97
+ name: "Example App",
98
+ redirect_uri: "localhost:3000",
99
+ }, format: :json,
100
+ }
102
101
 
103
- expect(response).to have_http_status(422)
102
+ expect(response).to have_http_status(422)
104
103
 
105
- expect(json_response).to include("errors")
106
- end
104
+ expect(json_response).to include("errors")
105
+ end
107
106
 
108
- it "destroys an application" do
109
- application = FactoryBot.create(:application)
107
+ it "destroys an application" do
108
+ application = FactoryBot.create(:application)
110
109
 
111
- delete :destroy, params: { id: application.id, format: :json }
110
+ delete :destroy, params: { id: application.id, format: :json }
112
111
 
113
- expect(response).to have_http_status(204)
114
- expect(Application.count).to be_zero
115
- end
112
+ expect(response).to have_http_status(204)
113
+ expect(Doorkeeper::Application.count).to be_zero
116
114
  end
115
+ end
117
116
 
118
- context "when admin is not authenticated" do
119
- before do
120
- allow(Doorkeeper.config).to receive(:authenticate_admin).and_return(proc do
121
- redirect_to main_app.root_url
122
- end)
123
- end
117
+ context "when admin is not authenticated" do
118
+ before do
119
+ allow(Doorkeeper.config).to receive(:authenticate_admin).and_return(proc do
120
+ redirect_to main_app.root_url
121
+ end)
122
+ end
123
+
124
+ it "redirects as set in Doorkeeper.authenticate_admin" do
125
+ get :index
126
+ expect(response).to redirect_to(controller.main_app.root_url)
127
+ end
128
+
129
+ it "does not create application" do
130
+ expect do
131
+ post :create, params: {
132
+ doorkeeper_application: {
133
+ name: "Example",
134
+ redirect_uri: "https://example.com",
135
+ },
136
+ }
137
+ end.not_to(change { Doorkeeper::Application.count })
138
+ end
139
+ end
140
+
141
+ context "when admin is authenticated" do
142
+ before do
143
+ allow(Doorkeeper.configuration).to receive(:authenticate_admin).and_return(->(*) { true })
144
+ end
124
145
 
125
- it "redirects as set in Doorkeeper.authenticate_admin" do
126
- get :index
127
- expect(response).to redirect_to(controller.main_app.root_url)
146
+ context "when application secrets are hashed" do
147
+ before do
148
+ allow(Doorkeeper.configuration)
149
+ .to receive(:application_secret_strategy).and_return(Doorkeeper::SecretStoring::Sha256Hash)
128
150
  end
129
151
 
130
- it "does not create application" do
152
+ it "shows the application secret after creating a new application" do
131
153
  expect do
132
154
  post :create, params: {
133
155
  doorkeeper_application: {
@@ -135,140 +157,114 @@ module Doorkeeper
135
157
  redirect_uri: "https://example.com",
136
158
  },
137
159
  }
138
- end.not_to(change { Doorkeeper::Application.count })
139
- end
140
- end
160
+ end.to change { Doorkeeper::Application.count }.by(1)
141
161
 
142
- context "when admin is authenticated" do
143
- context "when application secrets are hashed" do
144
- before do
145
- allow(Doorkeeper.configuration)
146
- .to receive(:application_secret_strategy).and_return(Doorkeeper::SecretStoring::Sha256Hash)
147
- end
148
-
149
- it "shows the application secret after creating a new application" do
150
- expect do
151
- post :create, params: {
152
- doorkeeper_application: {
153
- name: "Example",
154
- redirect_uri: "https://example.com",
155
- },
156
- }
157
- end.to change { Doorkeeper::Application.count }.by(1)
158
-
159
- application = Application.last
160
-
161
- secret_from_flash = flash[:application_secret]
162
- expect(secret_from_flash).not_to be_empty
163
- expect(application.secret_matches?(secret_from_flash)).to be_truthy
164
- expect(response).to redirect_to(controller.main_app.oauth_application_url(application.id))
165
-
166
- get :show, params: { id: application.id, format: :html }
167
-
168
- # We don't know the application secret here (because its hashed) so we can not assert its text on the page
169
- # Instead, we read it from the page and then check if it matches the application secret
170
- code_element = %r{<code.*id="secret".*>(.*)<\/code>}.match(response.body)
171
- secret_from_page = code_element[1]
172
-
173
- expect(response.body).to have_selector("code#application_id", text: application.uid)
174
- expect(response.body).to have_selector("code#secret")
175
- expect(secret_from_page).not_to be_empty
176
- expect(application.secret_matches?(secret_from_page)).to be_truthy
177
- end
178
-
179
- it "does not show an application secret when application did already exist" do
180
- application = FactoryBot.create(:application)
181
- get :show, params: { id: application.id, format: :html }
182
-
183
- expect(response.body).to have_selector("code#application_id", text: application.uid)
184
- expect(response.body).to have_selector("code#secret", text: "")
185
- end
186
-
187
- it "returns the application details in a json response" do
188
- expect do
189
- post :create, params: {
190
- doorkeeper_application: {
191
- name: "Example",
192
- redirect_uri: "https://example.com",
193
- }, format: :json,
194
- }
195
- end.to(change { Doorkeeper::Application.count })
196
-
197
- expect(response).to be_successful
198
-
199
- expect(json_response).to include("id", "name", "uid", "secret", "redirect_uri", "scopes")
200
-
201
- application = Application.last
202
- secret_from_response = json_response["secret"]
203
- expect(application.secret_matches?(secret_from_response)).to be_truthy
204
-
205
- expect(json_response["name"]).to eq("Example")
206
- expect(json_response["redirect_uri"]).to eq("https://example.com")
207
- end
208
- end
162
+ application = Doorkeeper::Application.last
209
163
 
210
- render_views
164
+ secret_from_flash = flash[:application_secret]
165
+ expect(secret_from_flash).not_to be_empty
166
+ expect(application).to be_secret_matches(secret_from_flash)
167
+ expect(response).to redirect_to(controller.main_app.oauth_application_url(application.id))
211
168
 
212
- before do
213
- allow(Doorkeeper.configuration).to receive(:authenticate_admin).and_return(->(*) { true })
214
- end
169
+ get :show, params: { id: application.id, format: :html }
170
+
171
+ # We don't know the application secret here (because its hashed) so we can not assert its text on the page
172
+ # Instead, we read it from the page and then check if it matches the application secret
173
+ code_element = /code.*id="secret">\s*\K([^<]*)/m.match(response.body)
174
+ secret_from_page = code_element[1].strip
215
175
 
216
- it "sorts applications by created_at" do
217
- first_application = FactoryBot.create(:application)
218
- second_application = FactoryBot.create(:application)
219
- expect(Doorkeeper::Application).to receive(:ordered_by).and_call_original
176
+ expect(response.body).to have_selector("code#application_id", text: application.uid)
177
+ expect(response.body).to have_selector("code#secret")
178
+ expect(secret_from_page).not_to be_empty
179
+ expect(application).to be_secret_matches(secret_from_page)
180
+ end
220
181
 
221
- get :index
182
+ it "does not show an application secret when application did already exist" do
183
+ application = FactoryBot.create(:application)
184
+ get :show, params: { id: application.id, format: :html }
222
185
 
223
- expect(response.body).to have_selector("tbody tr:first-child#application_#{first_application.id}")
224
- expect(response.body).to have_selector("tbody tr:last-child#application_#{second_application.id}")
186
+ expect(response.body).to have_selector("code#application_id", text: application.uid)
187
+ expect(response.body).to have_selector("code#secret", text: "")
225
188
  end
226
189
 
227
- it "creates application" do
190
+ it "returns the application details in a json response" do
228
191
  expect do
229
192
  post :create, params: {
230
193
  doorkeeper_application: {
231
194
  name: "Example",
232
195
  redirect_uri: "https://example.com",
233
- },
196
+ }, format: :json,
234
197
  }
235
- end.to change { Doorkeeper::Application.count }.by(1)
198
+ end.to(change { Doorkeeper::Application.count })
236
199
 
237
- expect(response).to be_redirect
238
- end
200
+ expect(response).to be_successful
239
201
 
240
- it "shows application details" do
241
- application = FactoryBot.create(:application)
242
- get :show, params: { id: application.id, format: :html }
202
+ expect(json_response).to include("id", "name", "uid", "secret", "redirect_uri", "scopes")
243
203
 
244
- expect(response.body).to have_selector("code#application_id", text: application.uid)
245
- expect(response.body).to have_selector("code#secret", text: application.plaintext_secret)
204
+ application = Doorkeeper::Application.last
205
+ secret_from_response = json_response["secret"]
206
+ expect(application).to be_secret_matches(secret_from_response)
207
+
208
+ expect(json_response["name"]).to eq("Example")
209
+ expect(json_response["redirect_uri"]).to eq("https://example.com")
246
210
  end
211
+ end
247
212
 
248
- it "does not allow mass assignment of uid or secret" do
249
- application = FactoryBot.create(:application)
250
- put :update, params: {
251
- id: application.id,
252
- doorkeeper_application: {
253
- uid: "1A2B3C4D",
254
- secret: "1A2B3C4D",
255
- },
256
- }
213
+ it "sorts applications by created_at" do
214
+ first_application = FactoryBot.create(:application)
215
+ second_application = FactoryBot.create(:application)
216
+ expect(Doorkeeper::Application).to receive(:ordered_by).and_call_original
257
217
 
258
- expect(application.reload.uid).not_to eq "1A2B3C4D"
259
- end
218
+ get :index
260
219
 
261
- it "updates application" do
262
- application = FactoryBot.create(:application)
263
- put :update, params: {
264
- id: application.id, doorkeeper_application: {
220
+ expect(response.body).to have_selector("tbody tr:first-child#application_#{first_application.id}")
221
+ expect(response.body).to have_selector("tbody tr:last-child#application_#{second_application.id}")
222
+ end
223
+
224
+ it "creates application" do
225
+ expect do
226
+ post :create, params: {
227
+ doorkeeper_application: {
265
228
  name: "Example",
266
229
  redirect_uri: "https://example.com",
267
230
  },
268
231
  }
232
+ end.to change { Doorkeeper::Application.count }.by(1)
269
233
 
270
- expect(application.reload.name).to eq "Example"
271
- end
234
+ expect(response).to be_redirect
235
+ end
236
+
237
+ it "shows application details" do
238
+ application = FactoryBot.create(:application)
239
+ get :show, params: { id: application.id, format: :html }
240
+
241
+ expect(response.body).to have_selector("code#application_id", text: application.uid)
242
+ expect(response.body).to have_selector("code#secret", text: application.plaintext_secret)
243
+ end
244
+
245
+ it "does not allow mass assignment of uid or secret" do
246
+ application = FactoryBot.create(:application)
247
+ put :update, params: {
248
+ id: application.id,
249
+ doorkeeper_application: {
250
+ uid: "1A2B3C4D",
251
+ secret: "1A2B3C4D",
252
+ },
253
+ }
254
+
255
+ expect(application.reload.uid).not_to eq "1A2B3C4D"
256
+ end
257
+
258
+ it "updates application" do
259
+ application = FactoryBot.create(:application)
260
+ put :update, params: {
261
+ id: application.id, doorkeeper_application: {
262
+ name: "Example",
263
+ redirect_uri: "https://example.com",
264
+ },
265
+ }
266
+
267
+ expect(application.reload.name).to eq "Example"
272
268
  end
273
269
  end
274
270
  end