maquina-generators 0.11.0 → 0.11.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4014b01c776f1e37d61dddd592e30a6acac76546082105ad3ca12c8b2233693c
4
- data.tar.gz: 8eb3326660cd36814d52a6324f3147b2912d1fe412326655dd6bf344e313a9c8
3
+ metadata.gz: d513cfb9ff42d62e52c3fed7ff837155fb4eec2a1d845c1acfb521f105bc2be0
4
+ data.tar.gz: 8443adc4e7646ab6edec543d7246fbdfbcb0ec5f7a4857b41a8d033785a59b75
5
5
  SHA512:
6
- metadata.gz: c547266a74a99a4dd11fd11124ccdd21f59dafe12215e8250060e6e5b11cb6181d6643cd140b1c38262513d9cff3c99889f2bdf3e07437e0479a128d918064b4
7
- data.tar.gz: 13e67350b2e101c184875128d9c651dc3fd2d7661a1f7ba0ecfb9e50a32b7506de652146b0a9e882e9d17b1a77b12683d9ef0dd150ef6d7eae6cb0557e4a688c
6
+ metadata.gz: 7729388ee2e2494cf38bc23e62d31a383a1182f5f176e59485e8e39dc3e9f6720f4144317d1c266d116927797ac8ad7baf8b493c5dc9d0be26dcee241ce46b01
7
+ data.tar.gz: 17f15b651fed96b06fe56d5ea7410aef3328d4e8e0e0b413735400b0bff94b5c1e7c7f8e88005d3145e4629b32a118c177fcfd34feb230dabac64f5708d24d8f
@@ -201,7 +201,7 @@ module Maquina
201
201
  # general throttle above — one page with a dozen violations would spend a
202
202
  # reader's budget — and capped on their own.
203
203
  Rack::Attack.throttle("csp/ip", limit: #{THROTTLE_LIMIT}, period: #{THROTTLE_PERIOD}) do |req|
204
- (req.env["action_dispatch.remote_ip"]&.to_s || req.ip) if req.path == "#{options[:path]}" && req.post?
204
+ req.env["action_dispatch.remote_ip"]&.to_s || req.ip if req.path == "#{options[:path]}" && req.post?
205
205
  end
206
206
  RUBY
207
207
  end
@@ -256,7 +256,7 @@ module Maquina
256
256
  # counted like the email-code login above. Keyed on the address Rails
257
257
  # resolves through trusted proxies, not the proxy hop in req.ip.
258
258
  Rack::Attack.throttle("passkey/ip", limit: #{THROTTLE_LIMIT}, period: #{THROTTLE_PERIOD}) do |req|
259
- (req.env["action_dispatch.remote_ip"]&.to_s || req.ip) if req.path.start_with?("/session/passkey") && req.post?
259
+ req.env["action_dispatch.remote_ip"]&.to_s || req.ip if req.path.start_with?("/session/passkey") && req.post?
260
260
  end
261
261
  RUBY
262
262
  end
@@ -396,7 +396,7 @@ class Rack::Attack
396
396
  def self.app_route?(path, routes: Rails.application.routes.routes.map { |route| route.path.spec.to_s })
397
397
  segments = path.to_s.downcase.split("/").reject(&:empty?)
398
398
  routes.any? { |route| route_covers?(route.downcase, segments) }
399
- rescue StandardError
399
+ rescue
400
400
  false
401
401
  end
402
402
 
@@ -1,3 +1,3 @@
1
1
  module MaquinaGenerators
2
- VERSION = "0.11.0"
2
+ VERSION = "0.11.1"
3
3
  end
@@ -214,7 +214,7 @@ class Maquina::Generators::PasskeysGeneratorTest < Rails::Generators::TestCase
214
214
  run_generator
215
215
 
216
216
  assert_file "config/initializers/rack_attack.rb", /Rack::Attack\.throttle\("passkey\/ip", limit: 20, period: 1\.minute\)/
217
- assert_file "config/initializers/rack_attack.rb", /\(req\.env\["action_dispatch\.remote_ip"\]&\.to_s \|\| req\.ip\) if req\.path\.start_with\?\("\/session\/passkey"\)/
217
+ assert_file "config/initializers/rack_attack.rb", /^ req\.env\["action_dispatch\.remote_ip"\]&\.to_s \|\| req\.ip if req\.path\.start_with\?\("\/session\/passkey"\)/
218
218
  end
219
219
 
220
220
  test "running twice changes nothing" do
@@ -0,0 +1,43 @@
1
+ require "test_helper"
2
+ require "open3"
3
+ require "tmpdir"
4
+ require "generators/maquina/oauth/oauth_generator"
5
+ require "generators/maquina/passkeys/passkeys_generator"
6
+ require "generators/maquina/csp_reports/csp_reports_generator"
7
+
8
+ # config/initializers/rack_attack.rb is one file that several generators add
9
+ # to, and the host app lints it with Standard. The repo's own standardrb never
10
+ # sees these snippets: they are strings in the generators. So the initializer
11
+ # is assembled the way an app ends up with it and Standard runs over it.
12
+ class Maquina::Generators::RackAttackSnippetsLintTest < Minitest::Test
13
+ ROOT = File.expand_path("../../..", __dir__)
14
+ TEMPLATE = File.join(ROOT, "lib/generators/maquina/rack_attack/templates/config/initializers/rack_attack.rb.tt")
15
+
16
+ def test_the_assembled_initializer_passes_standard
17
+ Dir.mktmpdir do |dir|
18
+ path = File.join(dir, "rack_attack.rb")
19
+ File.write(path, initializer)
20
+
21
+ # --stdin would skip the repo's .standard.yml ignores; a file outside test/tmp is linted.
22
+ output, status = Open3.capture2e("bundle", "exec", "standardrb", "--no-fix", path, chdir: ROOT)
23
+
24
+ assert status.success?, "Standard flagged the generated Rack::Attack initializer:\n#{output}"
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def initializer
31
+ options = {login_path: "/session"}
32
+ template = ERB.new(File.read(TEMPLATE), trim_mode: "-").result(binding)
33
+
34
+ template +
35
+ snippet(Maquina::Generators::OauthGenerator, :token_throttle) +
36
+ snippet(Maquina::Generators::PasskeysGenerator, :passkey_throttle) +
37
+ snippet(Maquina::Generators::CspReportsGenerator, :csp_throttle, path: "/csp-reports")
38
+ end
39
+
40
+ def snippet(generator, method, **options)
41
+ generator.new([], options).send(method)
42
+ end
43
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maquina-generators
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Alberto Chavez
@@ -364,6 +364,7 @@ files:
364
364
  - test/generators/maquina/passkeys_generator_test.rb
365
365
  - test/generators/maquina/rack_attack_generator_test.rb
366
366
  - test/generators/maquina/rack_attack_rules_test.rb
367
+ - test/generators/maquina/rack_attack_snippets_lint_test.rb
367
368
  - test/generators/maquina/registration_generator_test.rb
368
369
  - test/generators/maquina/security_generator_test.rb
369
370
  - test/generators/maquina/solid_errors_generator_test.rb