verikloak-rails 0.2.4 → 0.2.5

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: 3f102e217c566e0cbe01b75979d16fd5636449c8cc38f58e35d8147be44d05d8
4
- data.tar.gz: 1426fccde358d9d5440b99749debff98775cbb8d2e8492be96bf468df2ff259f
3
+ metadata.gz: 59774b369340238296ec1189c9512e674738abfcb26546103ebe56fd090b1c98
4
+ data.tar.gz: 0dcea3b1e940545a5213dadb253bc0152168eefad534d9ef8fc6c547491f783b
5
5
  SHA512:
6
- metadata.gz: c72c02908f4f946f4455b80341858cf329261c7d6da24d6ac6c6ab6ca484e636c45e6bf5e5ed23c29073c327e9338e7c42189e33e942ed5192b4792c44dd7ea4
7
- data.tar.gz: 9bae0bcc441bb9544a7365056f3ddf214bfe0ca4c8345c98d78ce6727cfca77ea6ad5a5511c415542f1882af7a996ce999e4e2912fc9c5203018d7d47b8d6007
6
+ metadata.gz: b4e0710f56702485f068937a9a3d0cfabe53694fbf1cf408de1be80d56dbdb5fd1b45ed2c280f0e3627b050f5d34c35c696ab885821757b082f6033b2b2a4608
7
+ data.tar.gz: 465c2f918d008ca326f67a5247c7da85655cb7544c18b3b787d6fde9ab47be661b455b5a7cbbccd98c18f1b4482707bd06e9e9a381ca2f94ed08d7d0e6448c32
data/CHANGELOG.md CHANGED
@@ -5,21 +5,33 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ---
9
+
10
+ ## [0.2.5] - 2025-09-23
11
+
12
+ ### Added
13
+ - Integration test coverage for missing discovery URL scenarios
14
+ - `reset!` method for configuration cleanup in test environments
15
+
16
+ ### Fixed
17
+ - Graceful handling of missing or blank discovery URLs during middleware configuration
18
+ - Skip middleware insertion and log warning when discovery URL is not configured
19
+ - Only configure BFF header guard when base middleware is successfully inserted
20
+
21
+ ### Changed
22
+ - Improved error handling and validation for discovery URL configuration
23
+ - Enhanced middleware insertion logic with better separation of concerns
8
24
 
9
25
  ## [0.2.4] - 2025-09-23
10
26
 
11
27
  ### Fixed
12
28
  - Package the installer template so `rails g verikloak:install` works in packaged gems (no more missing `initializer.rb.erb`).
13
29
 
14
- ---
15
-
16
30
  ## [0.2.3] - 2025-09-22
17
31
 
18
32
  ### Changed
19
33
  - Provide a safe default audience (`'rails-api'`) so fresh installs keep `Verikloak::Middleware` active and remain compatible with the optional `verikloak-audience` gem.
20
34
 
21
- ---
22
-
23
35
  ## [0.2.2] - 2025-09-21
24
36
 
25
37
  ### Added
@@ -32,8 +44,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
32
44
  ### Documentation
33
45
  - Note related gems in the installer output and README, including new configuration options for middleware ordering and BFF auto-insertion.
34
46
 
35
- ---
36
-
37
47
  ## [0.2.1] - 2025-09-21
38
48
 
39
49
  ### Changed
@@ -17,7 +17,7 @@ module Verikloak
17
17
  # @return [void]
18
18
  initializer 'verikloak.configure' do |app|
19
19
  stack = ::Verikloak::Rails::Railtie.send(:configure_middleware, app)
20
- ::Verikloak::Rails::Railtie.send(:configure_bff_guard, stack)
20
+ ::Verikloak::Rails::Railtie.send(:configure_bff_guard, stack) if stack
21
21
  end
22
22
 
23
23
  # Optionally include the controller concern when ActionController loads.
@@ -37,23 +37,13 @@ module Verikloak
37
37
  # @return [ActionDispatch::MiddlewareStackProxy] configured middleware stack
38
38
  def configure_middleware(app)
39
39
  apply_configuration(app)
40
- base_options = Verikloak::Rails.config.middleware_options
41
- stack = app.middleware
42
- if (before = Verikloak::Rails.config.middleware_insert_before)
43
- stack.insert_before before,
44
- ::Verikloak::Middleware,
45
- **base_options
46
- else
47
- after = Verikloak::Rails.config.middleware_insert_after || ::Rails::Rack::Logger
48
- if after
49
- stack.insert_after after,
50
- ::Verikloak::Middleware,
51
- **base_options
52
- else
53
- stack.use ::Verikloak::Middleware, **base_options
54
- end
40
+
41
+ unless discovery_url_present?
42
+ log_missing_discovery_url_warning
43
+ return
55
44
  end
56
- stack
45
+
46
+ insert_base_middleware(app)
57
47
  end
58
48
 
59
49
  # Insert the optional HeaderGuard middleware when verikloak-bff is present.
@@ -92,6 +82,69 @@ module Verikloak
92
82
  c.rescue_pundit = false if !rails_cfg.key?(:rescue_pundit) && defined?(::Verikloak::Pundit)
93
83
  end
94
84
  end
85
+
86
+ # Check if discovery_url is present and valid.
87
+ #
88
+ # @return [Boolean] true if discovery_url is configured and not empty
89
+ def discovery_url_present?
90
+ discovery_url = Verikloak::Rails.config.discovery_url
91
+ return false unless discovery_url
92
+
93
+ return !discovery_url.blank? if discovery_url.respond_to?(:blank?)
94
+ return !discovery_url.empty? if discovery_url.respond_to?(:empty?)
95
+
96
+ true
97
+ end
98
+
99
+ # Log a warning message when discovery_url is missing.
100
+ # Uses Rails.logger if available, falls back to warn.
101
+ #
102
+ # @return [void]
103
+ def log_missing_discovery_url_warning
104
+ message = '[verikloak] discovery_url is not configured; skipping middleware insertion.'
105
+ if defined?(::Rails) && ::Rails.respond_to?(:logger) && ::Rails.logger
106
+ ::Rails.logger.warn(message)
107
+ else
108
+ warn(message)
109
+ end
110
+ end
111
+
112
+ # Insert the base Verikloak::Middleware into the application middleware stack.
113
+ # Respects the configured insertion point (before or after specified middleware).
114
+ #
115
+ # @param app [Rails::Application] the Rails application
116
+ # @return [ActionDispatch::MiddlewareStackProxy] the configured middleware stack
117
+ def insert_base_middleware(app)
118
+ stack = app.middleware
119
+ base_options = Verikloak::Rails.config.middleware_options
120
+
121
+ if (before = Verikloak::Rails.config.middleware_insert_before)
122
+ stack.insert_before before,
123
+ ::Verikloak::Middleware,
124
+ **base_options
125
+ else
126
+ insert_middleware_after(stack, base_options)
127
+ end
128
+
129
+ stack
130
+ end
131
+
132
+ # Insert middleware after a specified middleware or at the default position.
133
+ # Handles the case where no specific insertion point is configured.
134
+ #
135
+ # @param stack [ActionDispatch::MiddlewareStackProxy] the middleware stack
136
+ # @param base_options [Hash] options to pass to the middleware
137
+ # @return [void]
138
+ def insert_middleware_after(stack, base_options)
139
+ after = Verikloak::Rails.config.middleware_insert_after || ::Rails::Rack::Logger
140
+ if after
141
+ stack.insert_after after,
142
+ ::Verikloak::Middleware,
143
+ **base_options
144
+ else
145
+ stack.use ::Verikloak::Middleware, **base_options
146
+ end
147
+ end
95
148
  end
96
149
  end
97
150
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Verikloak
4
4
  module Rails
5
- VERSION = '0.2.4'
5
+ VERSION = '0.2.5'
6
6
  end
7
7
  end
@@ -35,6 +35,16 @@ module Verikloak
35
35
  def configure
36
36
  yield(config)
37
37
  end
38
+
39
+ # Reset configuration to its default state.
40
+ #
41
+ # Primarily intended for test environments that need to ensure a clean
42
+ # configuration between examples.
43
+ #
44
+ # @return [void]
45
+ def reset!
46
+ @config = nil
47
+ end
38
48
  end
39
49
  end
40
50
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: verikloak-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - taiyaky
@@ -94,7 +94,7 @@ metadata:
94
94
  source_code_uri: https://github.com/taiyaky/verikloak-rails
95
95
  changelog_uri: https://github.com/taiyaky/verikloak-rails/blob/main/CHANGELOG.md
96
96
  bug_tracker_uri: https://github.com/taiyaky/verikloak-rails/issues
97
- documentation_uri: https://rubydoc.info/gems/verikloak-rails/0.2.4
97
+ documentation_uri: https://rubydoc.info/gems/verikloak-rails/0.2.5
98
98
  rubygems_mfa_required: 'true'
99
99
  rdoc_options: []
100
100
  require_paths: