prx_auth-rails 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/README.md +25 -6
  4. data/Rakefile +12 -4
  5. data/app/controllers/prx_auth/rails/sessions_controller.rb +108 -0
  6. data/app/views/prx_auth/rails/sessions/auth_error.html.erb +15 -0
  7. data/app/views/prx_auth/rails/sessions/show.html.erb +38 -0
  8. data/config/routes.rb +7 -0
  9. data/lib/prx_auth/rails.rb +1 -0
  10. data/lib/prx_auth/rails/configuration.rb +15 -4
  11. data/lib/prx_auth/rails/engine.rb +5 -0
  12. data/lib/prx_auth/rails/ext/controller.rb +29 -4
  13. data/lib/prx_auth/rails/token.rb +5 -1
  14. data/lib/prx_auth/rails/version.rb +1 -1
  15. data/prx_auth-rails.gemspec +3 -1
  16. data/test/dummy/Rakefile +6 -0
  17. data/test/dummy/app/assets/config/manifest.js +2 -0
  18. data/test/dummy/app/assets/images/.keep +0 -0
  19. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  20. data/test/dummy/app/channels/application_cable/channel.rb +4 -0
  21. data/test/dummy/app/channels/application_cable/connection.rb +4 -0
  22. data/test/dummy/app/controllers/application_controller.rb +8 -0
  23. data/test/dummy/app/controllers/concerns/.keep +0 -0
  24. data/test/dummy/app/helpers/application_helper.rb +2 -0
  25. data/test/dummy/app/javascript/packs/application.js +15 -0
  26. data/test/dummy/app/jobs/application_job.rb +7 -0
  27. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  28. data/test/dummy/app/models/application_record.rb +3 -0
  29. data/test/dummy/app/models/concerns/.keep +0 -0
  30. data/test/dummy/app/views/layouts/application.html.erb +15 -0
  31. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  32. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  33. data/test/dummy/bin/rails +5 -0
  34. data/test/dummy/bin/rake +5 -0
  35. data/test/dummy/bin/setup +33 -0
  36. data/test/dummy/bin/spring +10 -0
  37. data/test/dummy/config.ru +6 -0
  38. data/test/dummy/config/application.rb +22 -0
  39. data/test/dummy/config/boot.rb +5 -0
  40. data/test/dummy/config/cable.yml +10 -0
  41. data/test/dummy/config/database.yml +25 -0
  42. data/test/dummy/config/environment.rb +5 -0
  43. data/test/dummy/config/environments/development.rb +76 -0
  44. data/test/dummy/config/environments/production.rb +120 -0
  45. data/test/dummy/config/environments/test.rb +60 -0
  46. data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
  47. data/test/dummy/config/initializers/assets.rb +12 -0
  48. data/test/dummy/config/initializers/backtrace_silencers.rb +8 -0
  49. data/test/dummy/config/initializers/content_security_policy.rb +28 -0
  50. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  51. data/test/dummy/config/initializers/filter_parameter_logging.rb +6 -0
  52. data/test/dummy/config/initializers/inflections.rb +16 -0
  53. data/test/dummy/config/initializers/mime_types.rb +4 -0
  54. data/test/dummy/config/initializers/permissions_policy.rb +11 -0
  55. data/test/dummy/config/initializers/prx_auth.rb +8 -0
  56. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  57. data/test/dummy/config/locales/en.yml +33 -0
  58. data/test/dummy/config/puma.rb +43 -0
  59. data/test/dummy/config/routes.rb +3 -0
  60. data/test/dummy/config/spring.rb +6 -0
  61. data/test/dummy/config/storage.yml +34 -0
  62. data/test/dummy/lib/assets/.keep +0 -0
  63. data/test/dummy/log/.keep +0 -0
  64. data/test/dummy/public/404.html +67 -0
  65. data/test/dummy/public/422.html +67 -0
  66. data/test/dummy/public/500.html +66 -0
  67. data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
  68. data/test/dummy/public/apple-touch-icon.png +0 -0
  69. data/test/dummy/public/favicon.ico +0 -0
  70. data/test/dummy/storage/.keep +0 -0
  71. data/test/prx_auth/rails/configuration_test.rb +18 -12
  72. data/test/prx_auth/rails/sessions_controller_test.rb +94 -0
  73. data/test/prx_auth/rails/token_test.rb +1 -1
  74. data/test/test_helper.rb +20 -9
  75. metadata +153 -7
File without changes
File without changes
File without changes
@@ -2,29 +2,35 @@ require 'test_helper'
2
2
 
3
3
  describe PrxAuth::Rails::Configuration do
4
4
 
5
- after(:each) { PrxAuth::Rails.configuration = PrxAuth::Rails::Configuration.new }
6
5
  subject { PrxAuth::Rails::Configuration.new }
7
-
6
+
8
7
  it 'initializes with a namespace defined by rails app name' do
9
- assert subject.namespace == :test_app
8
+ assert subject.namespace == :dummy
10
9
  end
11
10
 
12
11
  it 'can be reconfigured using the namespace attr' do
13
- PrxAuth::Rails.configure do |config|
14
- config.namespace = :new_test
15
- end
12
+ PrxAuth::Rails.stub(:configuration, subject) do
13
+ PrxAuth::Rails.configure do |config|
14
+ config.namespace = :new_test
15
+ end
16
16
 
17
- assert PrxAuth::Rails.configuration.namespace == :new_test
17
+ assert PrxAuth::Rails.configuration.namespace == :new_test
18
+ end
18
19
  end
19
20
 
20
21
  it 'defaults to enabling the middleware' do
21
- assert PrxAuth::Rails.configuration.install_middleware
22
+ PrxAuth::Rails.stub(:configuration, subject) do
23
+ assert PrxAuth::Rails.configuration.install_middleware
24
+ end
22
25
  end
23
26
 
24
27
  it 'allows overriding of the middleware automatic installation' do
25
- PrxAuth::Rails.configure do |config|
26
- config.install_middleware = false
28
+ PrxAuth::Rails.stub(:configuration, subject) do
29
+ PrxAuth::Rails.configure do |config|
30
+ config.install_middleware = false
31
+ end
32
+
33
+ assert !PrxAuth::Rails.configuration.install_middleware
27
34
  end
28
- assert !PrxAuth::Rails.configuration.install_middleware
29
35
  end
30
- end
36
+ end
@@ -0,0 +1,94 @@
1
+ require "test_helper"
2
+
3
+ module PrxAuth::Rails
4
+ class SessionsControllerTest < ActionController::TestCase
5
+
6
+ setup do
7
+ @routes = PrxAuth::Rails::Engine.routes
8
+ @nonce_session_key = SessionsController::ID_NONCE_SESSION_KEY
9
+ @token_params = {id_token: 'sometok', access_token: 'othertok'}
10
+ @stub_claims = {'nonce' => '123', 'sub' => '1'}
11
+ end
12
+
13
+ test "new creates nonce" do
14
+ nonce = session[@nonce_session_key]
15
+ assert nonce == nil
16
+
17
+ get :new
18
+
19
+ nonce = session[@nonce_session_key]
20
+ assert nonce.match(/[a-zA-Z\d]{32}/)
21
+ assert nonce.length == 32
22
+ end
23
+
24
+ test 'new should should not overwrite the saved nonce' do
25
+ get :new
26
+ nonce1 = session[@nonce_session_key]
27
+
28
+ get :new
29
+ nonce2 = session[@nonce_session_key]
30
+ assert nonce1 == nonce2
31
+ end
32
+
33
+ test 'create should validate a token and set the session variable' do
34
+ @controller.stub(:validate_token, @stub_claims) do
35
+ session[@nonce_session_key] = '123'
36
+ post :create, params: @token_params, format: :json
37
+ assert session['prx.auth']['id_token']['nonce'] == '123'
38
+ end
39
+ end
40
+
41
+ test 'create should call test_nonce! if upon verification' do
42
+ @controller.stub(:validate_token, {'nonce' => 'not matching', 'aud' => '1'}) do
43
+ session[@nonce_session_key] = 'nonce'
44
+ post :create, params: @token_params, format: :json
45
+ assert session[@nonce_session_key] == nil
46
+ end
47
+ end
48
+
49
+ test 'create should reset the nonce after consumed' do
50
+ @controller.stub(:validate_token, @stub_claims) do
51
+ session[@nonce_session_key] = '123'
52
+ post :create, params: @token_params, format: :json
53
+
54
+ assert session[@nonce_session_key] == nil
55
+ assert response.code == '302'
56
+ assert response.body.match?(/after-sign-in-path/)
57
+ end
58
+ end
59
+
60
+ test 'should respond with aredirect to the auth error page / code if the nonce does not match' do
61
+ @controller.stub(:validate_token, @stub_claims) do
62
+ session[@nonce_session_key] = 'nonce-does-not-match'
63
+ post :create, params: @token_params, format: :json
64
+ assert response.code == '302'
65
+ assert response.body.match(/auth_error\?error=verification_failed/)
66
+ end
67
+ end
68
+
69
+ test 'auth_error should return a formatted error message to the user' do
70
+ get :auth_error, params: {error: 'error_message'}
71
+ assert response.code == '200'
72
+ assert response.body.match?(/Message was: <pre>error_message/)
73
+ end
74
+
75
+ test 'auth_error should expect the error param' do
76
+ assert_raises ActionController::ParameterMissing do
77
+ get :auth_error, params: {}
78
+ end
79
+ end
80
+
81
+ test 'validates that the user id matches in both tokens' do
82
+ @controller.stub(:id_claims, @stub_claims) do
83
+ @controller.stub(:access_claims, @stub_claims.merge('sub' => '444')) do
84
+
85
+ session[@nonce_session_key] = '123'
86
+ post :create, params: @token_params, format: :json
87
+
88
+ assert response.code == '302'
89
+ assert response.body.match?(/error=verification_failed/)
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -42,4 +42,4 @@ describe PrxAuth::Rails::Token do
42
42
  end
43
43
 
44
44
 
45
- end
45
+ end
@@ -1,7 +1,6 @@
1
1
  require 'coveralls'
2
- Coveralls.wear!
3
2
 
4
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
+ Coveralls.wear!
5
4
 
6
5
  require 'minitest/autorun'
7
6
  require 'minitest/spec'
@@ -12,13 +11,25 @@ require 'action_view'
12
11
  require 'rails'
13
12
  require 'rails/generators'
14
13
  require 'rails/generators/test_case'
15
- # Bundler.require(:default)
14
+ require 'pry'
16
15
 
17
- class TestApp < Rails::Application
18
- config.root = File.dirname(__FILE__)
19
- config.eager_load = false
20
- end
16
+ require 'prx_auth/rails'
17
+
18
+ # Configure Rails Environment
19
+ ENV["RAILS_ENV"] = "test"
20
+ ENV['PRX_CLIENT_ID'] = '12345'
21
21
 
22
- TestApp.initialize!
23
22
 
24
- require 'prx_auth/rails'
23
+ require_relative "../test/dummy/config/environment"
24
+ ActiveRecord::Migrator.migrations_paths = [File.expand_path("../test/dummy/db/migrate", __dir__)]
25
+ ActiveRecord::Migrator.migrations_paths << File.expand_path('../db/migrate', __dir__)
26
+ require "rails/test_help"
27
+
28
+
29
+ # Load fixtures from the engine
30
+ if ActiveSupport::TestCase.respond_to?(:fixture_path=)
31
+ ActiveSupport::TestCase.fixture_path = File.expand_path("fixtures", __dir__)
32
+ ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
33
+ ActiveSupport::TestCase.file_fixture_path = ActiveSupport::TestCase.fixture_path + "/files"
34
+ ActiveSupport::TestCase.fixtures :all
35
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prx_auth-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Rhoden
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-10 00:00:00.000000000 Z
11
+ date: 2021-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -96,6 +96,34 @@ dependencies:
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rails
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 6.1.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 6.1.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: sqlite3
99
127
  requirement: !ruby/object:Gem::Requirement
100
128
  requirements:
101
129
  - - ">="
@@ -124,7 +152,7 @@ dependencies:
124
152
  version: '1.2'
125
153
  description: 'Rails integration for next generation PRX Authorization system.
126
154
 
127
- '
155
+ '
128
156
  email:
129
157
  - carhoden@gmail.com
130
158
  executables: []
@@ -137,22 +165,83 @@ files:
137
165
  - LICENSE.txt
138
166
  - README.md
139
167
  - Rakefile
168
+ - app/controllers/prx_auth/rails/sessions_controller.rb
169
+ - app/views/prx_auth/rails/sessions/auth_error.html.erb
170
+ - app/views/prx_auth/rails/sessions/show.html.erb
171
+ - config/routes.rb
140
172
  - lib/prx_auth/rails.rb
141
173
  - lib/prx_auth/rails/configuration.rb
174
+ - lib/prx_auth/rails/engine.rb
142
175
  - lib/prx_auth/rails/ext/controller.rb
143
176
  - lib/prx_auth/rails/railtie.rb
144
177
  - lib/prx_auth/rails/token.rb
145
178
  - lib/prx_auth/rails/version.rb
146
179
  - prx_auth-rails.gemspec
180
+ - test/dummy/Rakefile
181
+ - test/dummy/app/assets/config/manifest.js
182
+ - test/dummy/app/assets/images/.keep
183
+ - test/dummy/app/assets/stylesheets/application.css
184
+ - test/dummy/app/channels/application_cable/channel.rb
185
+ - test/dummy/app/channels/application_cable/connection.rb
186
+ - test/dummy/app/controllers/application_controller.rb
187
+ - test/dummy/app/controllers/concerns/.keep
188
+ - test/dummy/app/helpers/application_helper.rb
189
+ - test/dummy/app/javascript/packs/application.js
190
+ - test/dummy/app/jobs/application_job.rb
191
+ - test/dummy/app/mailers/application_mailer.rb
192
+ - test/dummy/app/models/application_record.rb
193
+ - test/dummy/app/models/concerns/.keep
194
+ - test/dummy/app/views/layouts/application.html.erb
195
+ - test/dummy/app/views/layouts/mailer.html.erb
196
+ - test/dummy/app/views/layouts/mailer.text.erb
197
+ - test/dummy/bin/rails
198
+ - test/dummy/bin/rake
199
+ - test/dummy/bin/setup
200
+ - test/dummy/bin/spring
201
+ - test/dummy/config.ru
202
+ - test/dummy/config/application.rb
203
+ - test/dummy/config/boot.rb
204
+ - test/dummy/config/cable.yml
205
+ - test/dummy/config/database.yml
206
+ - test/dummy/config/environment.rb
207
+ - test/dummy/config/environments/development.rb
208
+ - test/dummy/config/environments/production.rb
209
+ - test/dummy/config/environments/test.rb
210
+ - test/dummy/config/initializers/application_controller_renderer.rb
211
+ - test/dummy/config/initializers/assets.rb
212
+ - test/dummy/config/initializers/backtrace_silencers.rb
213
+ - test/dummy/config/initializers/content_security_policy.rb
214
+ - test/dummy/config/initializers/cookies_serializer.rb
215
+ - test/dummy/config/initializers/filter_parameter_logging.rb
216
+ - test/dummy/config/initializers/inflections.rb
217
+ - test/dummy/config/initializers/mime_types.rb
218
+ - test/dummy/config/initializers/permissions_policy.rb
219
+ - test/dummy/config/initializers/prx_auth.rb
220
+ - test/dummy/config/initializers/wrap_parameters.rb
221
+ - test/dummy/config/locales/en.yml
222
+ - test/dummy/config/puma.rb
223
+ - test/dummy/config/routes.rb
224
+ - test/dummy/config/spring.rb
225
+ - test/dummy/config/storage.yml
226
+ - test/dummy/lib/assets/.keep
227
+ - test/dummy/log/.keep
228
+ - test/dummy/public/404.html
229
+ - test/dummy/public/422.html
230
+ - test/dummy/public/500.html
231
+ - test/dummy/public/apple-touch-icon-precomposed.png
232
+ - test/dummy/public/apple-touch-icon.png
233
+ - test/dummy/public/favicon.ico
234
+ - test/dummy/storage/.keep
147
235
  - test/log/development.log
148
236
  - test/prx_auth/rails/configuration_test.rb
237
+ - test/prx_auth/rails/sessions_controller_test.rb
149
238
  - test/prx_auth/rails/token_test.rb
150
239
  - test/test_helper.rb
151
240
  homepage: https://github.com/PRX/prx_auth-rails
152
241
  licenses:
153
242
  - MIT
154
243
  metadata: {}
155
- post_install_message:
244
+ post_install_message:
156
245
  rdoc_options: []
157
246
  require_paths:
158
247
  - lib
@@ -167,12 +256,69 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
256
  - !ruby/object:Gem::Version
168
257
  version: '0'
169
258
  requirements: []
170
- rubygems_version: 3.0.1
171
- signing_key:
259
+ rubyforge_project:
260
+ rubygems_version: 2.7.6.2
261
+ signing_key:
172
262
  specification_version: 4
173
263
  summary: Rails integration for next generation PRX Authorization system.
174
264
  test_files:
265
+ - test/dummy/Rakefile
266
+ - test/dummy/app/assets/config/manifest.js
267
+ - test/dummy/app/assets/images/.keep
268
+ - test/dummy/app/assets/stylesheets/application.css
269
+ - test/dummy/app/channels/application_cable/channel.rb
270
+ - test/dummy/app/channels/application_cable/connection.rb
271
+ - test/dummy/app/controllers/application_controller.rb
272
+ - test/dummy/app/controllers/concerns/.keep
273
+ - test/dummy/app/helpers/application_helper.rb
274
+ - test/dummy/app/javascript/packs/application.js
275
+ - test/dummy/app/jobs/application_job.rb
276
+ - test/dummy/app/mailers/application_mailer.rb
277
+ - test/dummy/app/models/application_record.rb
278
+ - test/dummy/app/models/concerns/.keep
279
+ - test/dummy/app/views/layouts/application.html.erb
280
+ - test/dummy/app/views/layouts/mailer.html.erb
281
+ - test/dummy/app/views/layouts/mailer.text.erb
282
+ - test/dummy/bin/rails
283
+ - test/dummy/bin/rake
284
+ - test/dummy/bin/setup
285
+ - test/dummy/bin/spring
286
+ - test/dummy/config.ru
287
+ - test/dummy/config/application.rb
288
+ - test/dummy/config/boot.rb
289
+ - test/dummy/config/cable.yml
290
+ - test/dummy/config/database.yml
291
+ - test/dummy/config/environment.rb
292
+ - test/dummy/config/environments/development.rb
293
+ - test/dummy/config/environments/production.rb
294
+ - test/dummy/config/environments/test.rb
295
+ - test/dummy/config/initializers/application_controller_renderer.rb
296
+ - test/dummy/config/initializers/assets.rb
297
+ - test/dummy/config/initializers/backtrace_silencers.rb
298
+ - test/dummy/config/initializers/content_security_policy.rb
299
+ - test/dummy/config/initializers/cookies_serializer.rb
300
+ - test/dummy/config/initializers/filter_parameter_logging.rb
301
+ - test/dummy/config/initializers/inflections.rb
302
+ - test/dummy/config/initializers/mime_types.rb
303
+ - test/dummy/config/initializers/permissions_policy.rb
304
+ - test/dummy/config/initializers/prx_auth.rb
305
+ - test/dummy/config/initializers/wrap_parameters.rb
306
+ - test/dummy/config/locales/en.yml
307
+ - test/dummy/config/puma.rb
308
+ - test/dummy/config/routes.rb
309
+ - test/dummy/config/spring.rb
310
+ - test/dummy/config/storage.yml
311
+ - test/dummy/lib/assets/.keep
312
+ - test/dummy/log/.keep
313
+ - test/dummy/public/404.html
314
+ - test/dummy/public/422.html
315
+ - test/dummy/public/500.html
316
+ - test/dummy/public/apple-touch-icon-precomposed.png
317
+ - test/dummy/public/apple-touch-icon.png
318
+ - test/dummy/public/favicon.ico
319
+ - test/dummy/storage/.keep
175
320
  - test/log/development.log
176
321
  - test/prx_auth/rails/configuration_test.rb
322
+ - test/prx_auth/rails/sessions_controller_test.rb
177
323
  - test/prx_auth/rails/token_test.rb
178
324
  - test/test_helper.rb