workarea-basic_auth 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +20 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
  4. data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  6. data/.gitignore +25 -0
  7. data/CHANGELOG.md +371 -0
  8. data/CODE_OF_CONDUCT.md +3 -0
  9. data/CONTRIBUTING.md +3 -0
  10. data/Gemfile +5 -0
  11. data/LICENSE +52 -0
  12. data/README.md +105 -0
  13. data/Rakefile +60 -0
  14. data/bin/rails +20 -0
  15. data/config/initializers/access_control.rb +23 -0
  16. data/lib/tasks/basic_auth_tasks.rake +4 -0
  17. data/lib/workarea/basic_auth.rb +23 -0
  18. data/lib/workarea/basic_auth/engine.rb +8 -0
  19. data/lib/workarea/basic_auth/middleware.rb +82 -0
  20. data/lib/workarea/basic_auth/path.rb +37 -0
  21. data/lib/workarea/basic_auth/railtie.rb +16 -0
  22. data/lib/workarea/basic_auth/simple_route_set.rb +23 -0
  23. data/lib/workarea/basic_auth/version.rb +5 -0
  24. data/test/dummy/Rakefile +6 -0
  25. data/test/dummy/app/assets/config/manifest.js +4 -0
  26. data/test/dummy/app/assets/images/.keep +0 -0
  27. data/test/dummy/app/assets/javascripts/application.js +13 -0
  28. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  29. data/test/dummy/app/controllers/application_controller.rb +3 -0
  30. data/test/dummy/app/controllers/concerns/.keep +0 -0
  31. data/test/dummy/app/helpers/application_helper.rb +2 -0
  32. data/test/dummy/app/jobs/application_job.rb +2 -0
  33. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  34. data/test/dummy/app/models/concerns/.keep +0 -0
  35. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  36. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  37. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  38. data/test/dummy/bin/bundle +3 -0
  39. data/test/dummy/bin/rails +4 -0
  40. data/test/dummy/bin/rake +4 -0
  41. data/test/dummy/bin/setup +34 -0
  42. data/test/dummy/bin/update +29 -0
  43. data/test/dummy/config.ru +5 -0
  44. data/test/dummy/config/application.rb +17 -0
  45. data/test/dummy/config/boot.rb +5 -0
  46. data/test/dummy/config/cable.yml +9 -0
  47. data/test/dummy/config/environment.rb +5 -0
  48. data/test/dummy/config/environments/development.rb +56 -0
  49. data/test/dummy/config/environments/production.rb +86 -0
  50. data/test/dummy/config/environments/test.rb +43 -0
  51. data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
  52. data/test/dummy/config/initializers/assets.rb +11 -0
  53. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  54. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  55. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  56. data/test/dummy/config/initializers/inflections.rb +16 -0
  57. data/test/dummy/config/initializers/mime_types.rb +4 -0
  58. data/test/dummy/config/initializers/new_framework_defaults.rb +21 -0
  59. data/test/dummy/config/initializers/session_store.rb +3 -0
  60. data/test/dummy/config/initializers/workarea.rb +4 -0
  61. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  62. data/test/dummy/config/locales/en.yml +23 -0
  63. data/test/dummy/config/puma.rb +47 -0
  64. data/test/dummy/config/routes.rb +5 -0
  65. data/test/dummy/config/secrets.yml +22 -0
  66. data/test/dummy/config/spring.rb +6 -0
  67. data/test/dummy/db/seeds.rb +2 -0
  68. data/test/dummy/lib/assets/.keep +0 -0
  69. data/test/dummy/log/.keep +0 -0
  70. data/test/factories/workarea/testing/basic_auth_helper.rb +21 -0
  71. data/test/lib/workarea/basic_auth/middleware_test.rb +149 -0
  72. data/test/lib/workarea/basic_auth/path_test.rb +50 -0
  73. data/test/lib/workarea/basic_auth/simple_route_set_test.rb +64 -0
  74. data/test/lib/workarea/basic_auth_test.rb +12 -0
  75. data/test/test_helper.rb +9 -0
  76. data/workarea-basic_auth.gemspec +39 -0
  77. metadata +226 -0
@@ -0,0 +1,64 @@
1
+ require "test_helper"
2
+
3
+ module Workarea
4
+ module BasicAuth
5
+ class SimpleRouteSetTest < Workarea::TestCase
6
+ include Workarea::Testing::BasicAuthHelper
7
+
8
+ def test_add_takes_a_string_and_optional_array_of_http_request_methods
9
+ set = SimpleRouteSet.new
10
+ set.add("/products")
11
+ set.add("/admin", :head)
12
+ set.add("/admin", :head, :post)
13
+
14
+ assert_equal(3, set.paths.count)
15
+ end
16
+
17
+ def test_matches_requests_based_off_a_proc
18
+ set = SimpleRouteSet.new
19
+ set.add("/login", ->(request) {
20
+ request.env["HTTP_USER_AGENT"] == "CoolAgent"
21
+ })
22
+
23
+ bad_request = Rack::Request.new(
24
+ Rack::MockRequest.env_for("/login", "HTTP_USER_AGENT" => "UncoolAgent")
25
+ )
26
+
27
+ good_request = Rack::Request.new(
28
+ Rack::MockRequest.env_for("/login", "HTTP_USER_AGENT" => "CoolAgent")
29
+ )
30
+
31
+ refute set.matches?(bad_request)
32
+ assert set.matches?(good_request)
33
+ end
34
+
35
+ def test_matches_requests_that_are_in_the_set
36
+ set = SimpleRouteSet.new
37
+ set.add("/products")
38
+ set.add("/admin", :options)
39
+ set.add("/admin", :head, :post)
40
+
41
+ delete_products = build_request("/products", "DELETE")
42
+ options_admin = build_request("/admin", "OPTIONS")
43
+ post_admin = build_request("/admin", "POST")
44
+
45
+ bad = build_request("/admin")
46
+
47
+ assert set.matches?(delete_products)
48
+ assert set.matches?(options_admin)
49
+ assert set.matches?(post_admin)
50
+
51
+ refute set.matches?(bad)
52
+ end
53
+
54
+ def test_does_not_match_requests_not_in_the_set
55
+ set = SimpleRouteSet.new
56
+ set.add("/wat")
57
+
58
+ bad = build_request("/bad")
59
+
60
+ refute set.matches?(bad)
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,12 @@
1
+ require "test_helper"
2
+
3
+ module Workarea
4
+ class BasicAuthTest < Workarea::TestCase
5
+ def test_creates_workarea_config_basic_auth_with_route_sets
6
+ basic_auth = Workarea.config.basic_auth
7
+ refute_nil(basic_auth)
8
+ assert_instance_of(BasicAuth::SimpleRouteSet, basic_auth.protect_routes)
9
+ assert_instance_of(BasicAuth::SimpleRouteSet, basic_auth.exclude_routes)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+ require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
4
+ require "rails/test_help"
5
+ require "workarea/test_help"
6
+ require "factories/workarea/testing/basic_auth_helper"
7
+ # Filter out Minitest backtrace while allowing backtrace from other libraries
8
+ # to be shown.
9
+ Minitest.backtrace_filter = Minitest::BacktraceFilter.new
@@ -0,0 +1,39 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ # Maintain your gem's version:
4
+ require "workarea/basic_auth/version"
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |s|
8
+ s.name = "workarea-basic_auth"
9
+ s.version = Workarea::BasicAuth::VERSION
10
+ s.authors = ["Thomas Vendetta"]
11
+ s.email = ["tvendetta@workarea.com"]
12
+ s.homepage = "https://github.com/workarea-commerce/workarea-basic-auth"
13
+ s.summary = "HTTP basic authentication Rack middleware for the Workarea Commerce Platform"
14
+ s.description = "HTTP basic authentication Rack middleware for the Workarea Commerce Platform"
15
+ s.files = `git ls-files`.split("\n")
16
+ s.license = 'Business Software License'
17
+ s.test_files = Dir["test/**/*"]
18
+
19
+ s.required_ruby_version = ">= 2.0.0"
20
+
21
+ s.add_dependency "workarea", "~> 3.x", ">= 3.0.4"
22
+ s.add_dependency "rack", "~> 2.0"
23
+
24
+ s.post_install_message = <<~MSG
25
+ Workarea Basic Auth is installed. Add the following configuration to
26
+ an initializer or to an environment.rb file to enable:
27
+
28
+ Workarea.configure do |config|
29
+ config.basic_auth.enabled = true
30
+ config.basic_auth.user = 'my_username'
31
+ config.basic_auth.pass = 'my_password'
32
+ config.basic_auth.protect_routes.add('/*')
33
+ config.basic_auth.exclude_routes.add('/api*')
34
+ end
35
+
36
+ For more information check out the README:
37
+ https://github.com/workarea-commerce/workarea-basic-auth
38
+ MSG
39
+ end
metadata ADDED
@@ -0,0 +1,226 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: workarea-basic_auth
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Thomas Vendetta
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-08-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: workarea
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.x
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 3.0.4
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 3.x
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.4
33
+ - !ruby/object:Gem::Dependency
34
+ name: rack
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.0'
47
+ description: HTTP basic authentication Rack middleware for the Workarea Commerce Platform
48
+ email:
49
+ - tvendetta@workarea.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - ".editorconfig"
55
+ - ".github/ISSUE_TEMPLATE/bug_report.md"
56
+ - ".github/ISSUE_TEMPLATE/documentation-request.md"
57
+ - ".github/ISSUE_TEMPLATE/feature_request.md"
58
+ - ".gitignore"
59
+ - CHANGELOG.md
60
+ - CODE_OF_CONDUCT.md
61
+ - CONTRIBUTING.md
62
+ - Gemfile
63
+ - LICENSE
64
+ - README.md
65
+ - Rakefile
66
+ - bin/rails
67
+ - config/initializers/access_control.rb
68
+ - lib/tasks/basic_auth_tasks.rake
69
+ - lib/workarea/basic_auth.rb
70
+ - lib/workarea/basic_auth/engine.rb
71
+ - lib/workarea/basic_auth/middleware.rb
72
+ - lib/workarea/basic_auth/path.rb
73
+ - lib/workarea/basic_auth/railtie.rb
74
+ - lib/workarea/basic_auth/simple_route_set.rb
75
+ - lib/workarea/basic_auth/version.rb
76
+ - test/dummy/Rakefile
77
+ - test/dummy/app/assets/config/manifest.js
78
+ - test/dummy/app/assets/images/.keep
79
+ - test/dummy/app/assets/javascripts/application.js
80
+ - test/dummy/app/assets/stylesheets/application.css
81
+ - test/dummy/app/controllers/application_controller.rb
82
+ - test/dummy/app/controllers/concerns/.keep
83
+ - test/dummy/app/helpers/application_helper.rb
84
+ - test/dummy/app/jobs/application_job.rb
85
+ - test/dummy/app/mailers/application_mailer.rb
86
+ - test/dummy/app/models/concerns/.keep
87
+ - test/dummy/app/views/layouts/application.html.erb
88
+ - test/dummy/app/views/layouts/mailer.html.erb
89
+ - test/dummy/app/views/layouts/mailer.text.erb
90
+ - test/dummy/bin/bundle
91
+ - test/dummy/bin/rails
92
+ - test/dummy/bin/rake
93
+ - test/dummy/bin/setup
94
+ - test/dummy/bin/update
95
+ - test/dummy/config.ru
96
+ - test/dummy/config/application.rb
97
+ - test/dummy/config/boot.rb
98
+ - test/dummy/config/cable.yml
99
+ - test/dummy/config/environment.rb
100
+ - test/dummy/config/environments/development.rb
101
+ - test/dummy/config/environments/production.rb
102
+ - test/dummy/config/environments/test.rb
103
+ - test/dummy/config/initializers/application_controller_renderer.rb
104
+ - test/dummy/config/initializers/assets.rb
105
+ - test/dummy/config/initializers/backtrace_silencers.rb
106
+ - test/dummy/config/initializers/cookies_serializer.rb
107
+ - test/dummy/config/initializers/filter_parameter_logging.rb
108
+ - test/dummy/config/initializers/inflections.rb
109
+ - test/dummy/config/initializers/mime_types.rb
110
+ - test/dummy/config/initializers/new_framework_defaults.rb
111
+ - test/dummy/config/initializers/session_store.rb
112
+ - test/dummy/config/initializers/workarea.rb
113
+ - test/dummy/config/initializers/wrap_parameters.rb
114
+ - test/dummy/config/locales/en.yml
115
+ - test/dummy/config/puma.rb
116
+ - test/dummy/config/routes.rb
117
+ - test/dummy/config/secrets.yml
118
+ - test/dummy/config/spring.rb
119
+ - test/dummy/db/seeds.rb
120
+ - test/dummy/lib/assets/.keep
121
+ - test/dummy/log/.keep
122
+ - test/dummy/log/sidekiq.log
123
+ - test/dummy/public/404.html
124
+ - test/dummy/public/422.html
125
+ - test/dummy/public/500.html
126
+ - test/dummy/public/apple-touch-icon-precomposed.png
127
+ - test/dummy/public/apple-touch-icon.png
128
+ - test/dummy/public/favicon.ico
129
+ - test/factories/workarea/testing/basic_auth_helper.rb
130
+ - test/lib/workarea/basic_auth/middleware_test.rb
131
+ - test/lib/workarea/basic_auth/path_test.rb
132
+ - test/lib/workarea/basic_auth/simple_route_set_test.rb
133
+ - test/lib/workarea/basic_auth_test.rb
134
+ - test/test_helper.rb
135
+ - workarea-basic_auth.gemspec
136
+ homepage: https://github.com/workarea-commerce/workarea-basic-auth
137
+ licenses:
138
+ - Business Software License
139
+ metadata: {}
140
+ post_install_message: |
141
+ Workarea Basic Auth is installed. Add the following configuration to
142
+ an initializer or to an environment.rb file to enable:
143
+
144
+ Workarea.configure do |config|
145
+ config.basic_auth.enabled = true
146
+ config.basic_auth.user = 'my_username'
147
+ config.basic_auth.pass = 'my_password'
148
+ config.basic_auth.protect_routes.add('/*')
149
+ config.basic_auth.exclude_routes.add('/api*')
150
+ end
151
+
152
+ For more information check out the README:
153
+ https://github.com/workarea-commerce/workarea-basic-auth
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: 2.0.0
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubygems_version: 3.0.4
169
+ signing_key:
170
+ specification_version: 4
171
+ summary: HTTP basic authentication Rack middleware for the Workarea Commerce Platform
172
+ test_files:
173
+ - test/test_helper.rb
174
+ - test/dummy/public/apple-touch-icon-precomposed.png
175
+ - test/dummy/public/404.html
176
+ - test/dummy/public/422.html
177
+ - test/dummy/public/500.html
178
+ - test/dummy/public/favicon.ico
179
+ - test/dummy/public/apple-touch-icon.png
180
+ - test/dummy/Rakefile
181
+ - test/dummy/config/initializers/workarea.rb
182
+ - test/dummy/config/initializers/assets.rb
183
+ - test/dummy/config/initializers/wrap_parameters.rb
184
+ - test/dummy/config/initializers/application_controller_renderer.rb
185
+ - test/dummy/config/initializers/new_framework_defaults.rb
186
+ - test/dummy/config/initializers/cookies_serializer.rb
187
+ - test/dummy/config/initializers/filter_parameter_logging.rb
188
+ - test/dummy/config/initializers/inflections.rb
189
+ - test/dummy/config/initializers/backtrace_silencers.rb
190
+ - test/dummy/config/initializers/session_store.rb
191
+ - test/dummy/config/initializers/mime_types.rb
192
+ - test/dummy/config/spring.rb
193
+ - test/dummy/config/locales/en.yml
194
+ - test/dummy/config/routes.rb
195
+ - test/dummy/config/cable.yml
196
+ - test/dummy/config/environment.rb
197
+ - test/dummy/config/boot.rb
198
+ - test/dummy/config/secrets.yml
199
+ - test/dummy/config/application.rb
200
+ - test/dummy/config/puma.rb
201
+ - test/dummy/config/environments/test.rb
202
+ - test/dummy/config/environments/development.rb
203
+ - test/dummy/config/environments/production.rb
204
+ - test/dummy/db/seeds.rb
205
+ - test/dummy/config.ru
206
+ - test/dummy/app/controllers/application_controller.rb
207
+ - test/dummy/app/assets/javascripts/application.js
208
+ - test/dummy/app/assets/config/manifest.js
209
+ - test/dummy/app/assets/stylesheets/application.css
210
+ - test/dummy/app/views/layouts/mailer.html.erb
211
+ - test/dummy/app/views/layouts/mailer.text.erb
212
+ - test/dummy/app/views/layouts/application.html.erb
213
+ - test/dummy/app/helpers/application_helper.rb
214
+ - test/dummy/app/jobs/application_job.rb
215
+ - test/dummy/app/mailers/application_mailer.rb
216
+ - test/dummy/log/sidekiq.log
217
+ - test/dummy/bin/bundle
218
+ - test/dummy/bin/update
219
+ - test/dummy/bin/rails
220
+ - test/dummy/bin/rake
221
+ - test/dummy/bin/setup
222
+ - test/lib/workarea/basic_auth_test.rb
223
+ - test/lib/workarea/basic_auth/middleware_test.rb
224
+ - test/lib/workarea/basic_auth/path_test.rb
225
+ - test/lib/workarea/basic_auth/simple_route_set_test.rb
226
+ - test/factories/workarea/testing/basic_auth_helper.rb