glib-web 5.1.0 → 5.1.2

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: 9af6a7a8e8f3cd4b9a45446e58347ff9ecc2130d1ce4f715da68ead1c7646ab5
4
- data.tar.gz: 3239c38d6b96f609eb961d5e427121bee47804430475bc0fe0be66a599dcf9ee
3
+ metadata.gz: 8e7848fb02064447620d8fca19a5f94b27c135b5e6c40dcd3c16974d19bb84e7
4
+ data.tar.gz: e187535507305543f7c5c9a5734393d60c89fd1167bf488489963b304dd92f44
5
5
  SHA512:
6
- metadata.gz: 138e70c7c76dcb59f24715c31b6e322cd0bb8d3ee74ac4905f7e0d0ae7d206fc46481c5b47a76d970fc08a1f6a78aa17cb368ac43a79fe98c2251f29e1add74d
7
- data.tar.gz: 8f92b011d2a6e1ee72547fcb8cba257accd972b2ff055eb88692c4701cdeabea00bf33bc4e0318e3cc9416078e587c1322911457c0f553ffde27f612bceb77c5
6
+ metadata.gz: 555954cb635653ad23d9af3da7810db47bf87b4ad6807d029a5294fcb1212eee02cefa64f96a97e819c11d1a5ed3134855329e722e18207df20c0f0153011e8e
7
+ data.tar.gz: fde96a7c67e9f8e718d0cb7c8de72dd882e49607965891040fadf6c5b71e20be4ef2f3f69cb810662d585434ad1e650174569c0ddc87959c601fd10cdeadb189
@@ -0,0 +1,23 @@
1
+ module Glib::Params
2
+ module Allowlist
3
+ extend ActiveSupport::Concern
4
+
5
+ # Resolve a stringly-typed request param (or any boundary string) to one
6
+ # symbol drawn from a closed allow-list (+allowed_symbols+), returning
7
+ # +default+ when the value is missing, blank, or not recognised.
8
+ #
9
+ # This is the symbol-DoS-safe replacement for `params[:x].to_sym`. A bare
10
+ # `.to_sym` on a raw value mints a symbol for every distinct string a client
11
+ # sends, including values you intend to reject on the next line, the classic
12
+ # symbol-DoS vector. This only ever returns a symbol already present in
13
+ # +allowed_symbols+ (or +default+), so attacker input can never create a new
14
+ # symbol regardless of what is sent.
15
+ #
16
+ # nil / "" fall through to +default+ implicitly (no symbol's string form is
17
+ # blank). Use it for any closed-vocabulary boundary input: interval
18
+ # selectors, status filters, UTM tags, feature-flag names.
19
+ def glib_allowlist_symbol_param(value, allowed_symbols, default:)
20
+ allowed_symbols.find { |symbol| symbol.to_s == value.to_s } || default
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,28 @@
1
+ module Glib
2
+ # The truthful base class for the rare, justified unit tests (see dev-doc's
3
+ # AvoidUnitTest / RequireUnitTestJustification). Every other test should be a
4
+ # controller test on Glib::IntegrationTest.
5
+ #
6
+ # The name is the policy: you may only be here after exhausting the
7
+ # controller-test route. Assume a controller test IS possible and look
8
+ # harder first — that conclusion is almost always premature (AvoidUnitTest's
9
+ # docs list the patterns that make "unit-only" behaviour reachable
10
+ # end-to-end). Subclassing this base is a confession, not a credential: it
11
+ # must sit in a unit-test directory under a justification header, both
12
+ # enforced by RequireUnitTestJustification.
13
+ #
14
+ # Deliberately NOT a descendant of ActionDispatch::IntegrationTest:
15
+ #
16
+ # - The declaration line states the test type honestly. A unit test
17
+ # subclassing an "IntegrationTest" base is a lie that also defeats
18
+ # base-class-keyed tooling.
19
+ # - HTTP verb helpers (`get`/`post`/...) don't exist here, so a unit test
20
+ # structurally cannot drift into half-integration territory — the inverse
21
+ # of the guarantee DevDoc::Test::Lints::HttpDrivenControllerTests provides
22
+ # for test/controllers/.
23
+ #
24
+ # Project-wide helpers attached to ActiveSupport::TestCase (fixtures,
25
+ # glib_travel, coverage) are inherited as usual.
26
+ class LastResortUnitTest < ActiveSupport::TestCase
27
+ end
28
+ end
@@ -0,0 +1,27 @@
1
+ require 'active_job/test_helper'
2
+
3
+ module Glib
4
+ # The truthful base for full-stack side-effect tests (jobs, mailers,
5
+ # channels): real DB, fixtures, deliveries and enqueued-job execution — but
6
+ # no HTTP verbs. Use it when the contract under test is a side effect (a
7
+ # job's record mutations, a mailer's body and links) rather than an HTTP
8
+ # response; tests that DO assert responses belong on Glib::IntegrationTest.
9
+ #
10
+ # Deliberately NOT a descendant of ActionDispatch::IntegrationTest, for the
11
+ # same reasons as Glib::LastResortUnitTest: the declaration line states the
12
+ # test type honestly, and the HTTP verb helpers are structurally absent, so
13
+ # a side-effect test cannot silently drift into half-integration territory.
14
+ # Unlike LastResortUnitTest this base is not a confession — jobs and mailers
15
+ # genuinely have no HTTP surface of their own — but it is confined all the
16
+ # same: DevDoc/Test/RequireUnitTestJustification only permits it inside the
17
+ # side-effect directories (test/jobs/, test/mailers/, test/channels/),
18
+ # because anywhere else it would evade that directory's enforcement.
19
+ #
20
+ # Project-wide helpers attached to ActiveSupport::TestCase (fixtures,
21
+ # glib_travel, coverage) are inherited as usual; ActiveJob::TestHelper is
22
+ # included here because running the very jobs under test
23
+ # (perform_enqueued_jobs) is this tier's bread and butter.
24
+ class NonHttpIntegrationTest < ActiveSupport::TestCase
25
+ include ActiveJob::TestHelper
26
+ end
27
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'English'
4
+ require 'shellwords'
5
+
6
+ module Glib
7
+ module Test
8
+ # Fast RuboCop guard for the subset-run workflow.
9
+ #
10
+ # Lives in glib-web's test helper so any project that includes
11
+ # `Glib::TestHelpers` into `ActiveSupport::TestCase` picks it up. Minitest
12
+ # runs all loaded test classes on every invocation, so this fires on every
13
+ # `rails test` — but it lints ONLY the files you have changed in the
14
+ # working tree (unstaged + staged + untracked). That keeps it fast and
15
+ # fails the run the moment an edited file has an offense.
16
+ #
17
+ # Skip with `SKIP_CHANGED_RUBOCOP=1` during tight debug loops. Auto-skips
18
+ # on CI because gem caches put thousands of vendored `.rb` files into the
19
+ # working tree (the "working-tree diff == your edits" premise breaks).
20
+ class ChangedFilesRubocop < ::ActiveSupport::TestCase
21
+ # Extensions RuboCop targets by default (see its AllCops/Include). We
22
+ # rely on `--force-exclusion` to honour the project's AllCops/Exclude.
23
+ RUBOCOP_EXTENSIONS = %w[.rb .rake .jbuilder .gemspec].freeze
24
+
25
+ def test_changed_files_are_rubocop_clean
26
+ skip 'opted out via SKIP_CHANGED_RUBOCOP' if ENV['SKIP_CHANGED_RUBOCOP'] == '1'
27
+ skip 'CI lints every file separately; this guard is for local working-tree edits' if ENV['CI']
28
+
29
+ files = changed_ruby_files
30
+ # IMPORTANT: never call rubocop with zero paths — it would lint the whole repo.
31
+ skip 'no changed Ruby files in the working tree' if files.empty?
32
+
33
+ output = `bundle exec rubocop --force-exclusion --format simple #{files.shelljoin} 2>&1`
34
+
35
+ assert(
36
+ $CHILD_STATUS.success?,
37
+ 'RuboCop offenses in files you changed (fix them with `rubocop -a`):' \
38
+ "\n\n#{output}"
39
+ )
40
+ end
41
+
42
+ private
43
+ def changed_ruby_files
44
+ # `git status --porcelain` covers unstaged, staged, and untracked in
45
+ # one spawn. Each line is `XY PATH` (or `XY ORIG -> PATH` for
46
+ # renames); PATH starts at index 3. Deleted files are dropped by the
47
+ # File.file? check below (no on-disk entry to lint).
48
+ `git status --porcelain`
49
+ .split("\n")
50
+ .filter_map { |line| line[3..]&.split(' -> ')&.last }
51
+ .select { |path| RUBOCOP_EXTENSIONS.include?(File.extname(path)) && File.file?(path) }
52
+ end
53
+ end
54
+ end
55
+ end
@@ -4,6 +4,12 @@ module Glib
4
4
 
5
5
  included do
6
6
  extend ClassMethods
7
+
8
+ # Auto-load ChangedFilesRubocop only when this module is mixed into a
9
+ # test class. AllHelpers also includes Glib::TestHelpers into view
10
+ # helper modules in production controllers; in that context
11
+ # ActiveSupport::TestCase is not loaded, so we skip the require.
12
+ require 'glib/test/changed_files_rubocop' if defined?(::ActiveSupport::TestCase)
7
13
  end
8
14
 
9
15
  module ClassMethods
@@ -33,7 +39,17 @@ module Glib
33
39
  def response_assert_equal
34
40
  expected = __get_previous_result_from_git
35
41
  result = __log_controller_data(response.body)
36
- assert_equal JSON.parse(expected), JSON.parse(result), "Result mismatch! #{__git_is_available? ? `git diff #{__controller_log_dir}/#{__controller_log_file}` : ''}"
42
+ # The message is a proc so the `git diff` subprocess only runs on FAILURE
43
+ # (a positional string message is built eagerly — one shell-out per
44
+ # passing assertion, and needless git-index contention under parallel
45
+ # workers). The path must be QUOTED: log filenames derive from test
46
+ # names, and an unquoted name containing `->` makes the shell treat `>`
47
+ # as a redirection, creating stray empty files in the app root.
48
+ failure_message = proc do
49
+ diff = __git_is_available? ? `git diff "#{File.join(__controller_log_dir, __controller_log_file)}"` : ''
50
+ "Result mismatch! #{diff}"
51
+ end
52
+ assert_equal JSON.parse(expected), JSON.parse(result), failure_message
37
53
  end
38
54
 
39
55
  def crawl_json_pages(user, log_file: nil, dump_actions: false, dump_path: nil, skip_similar_page: false, &block)
data/lib/glib-web.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'glib/version'
2
1
  if defined?(::Rails)
3
2
  require 'glib/engine'
4
3
  require 'glib/snapshot'
@@ -10,6 +9,8 @@ require 'glib/dynamic_text'
10
9
  require 'glib/test_helpers'
11
10
  require 'glib/test/parallel_coverage'
12
11
  require 'glib/integration_test'
12
+ require 'glib/last_resort_unit_test'
13
+ require 'glib/non_http_integration_test'
13
14
 
14
15
  require 'glib/time_freezable_mailer'
15
16
  require 'glib/time_returning_mailer'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glib-web
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.0
4
+ version: 5.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
@@ -170,6 +170,7 @@ files:
170
170
  - app/controllers/concerns/glib/json/traversal.rb
171
171
  - app/controllers/concerns/glib/json/ui.rb
172
172
  - app/controllers/concerns/glib/json/validation.rb
173
+ - app/controllers/concerns/glib/params/allowlist.rb
173
174
  - app/controllers/glib/blob_url_generators_controller.rb
174
175
  - app/controllers/glib/errors_controller.rb
175
176
  - app/controllers/glib/glib_direct_uploads_controller.rb
@@ -513,7 +514,9 @@ files:
513
514
  - lib/glib/json_crawler/coverage.rb
514
515
  - lib/glib/json_crawler/http.rb
515
516
  - lib/glib/json_crawler/router.rb
517
+ - lib/glib/last_resort_unit_test.rb
516
518
  - lib/glib/mailer_tester.rb
519
+ - lib/glib/non_http_integration_test.rb
517
520
  - lib/glib/rubocop.rb
518
521
  - lib/glib/rubocop/cops/json_ui/base_nested_parameter.rb
519
522
  - lib/glib/rubocop/cops/json_ui/nested_action_parameter.rb
@@ -522,12 +525,12 @@ files:
522
525
  - lib/glib/rubocop/cops/multiline_method_call_style.rb
523
526
  - lib/glib/rubocop/cops/test_name_parentheses.rb
524
527
  - lib/glib/snapshot.rb
528
+ - lib/glib/test/changed_files_rubocop.rb
525
529
  - lib/glib/test/parallel_coverage.rb
526
530
  - lib/glib/test_helpers.rb
527
531
  - lib/glib/time_freezable_mailer.rb
528
532
  - lib/glib/time_returning_mailer.rb
529
533
  - lib/glib/value.rb
530
- - lib/glib/version.rb
531
534
  - lib/tasks/db.rake
532
535
  homepage:
533
536
  licenses: []
data/lib/glib/version.rb DELETED
@@ -1,5 +0,0 @@
1
- module Glib
2
- module Web
3
- VERSION = '0.0.1'
4
- end
5
- end