Skip to content

Commit f76080a

Browse files
Copilotfletchto99
andcommitted
Address code review feedback: improve comments and test maintainability
Co-authored-by: fletchto99 <[email protected]>
1 parent 7f4860d commit f76080a

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

lib/secure_headers/configuration.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ def create_noop_config
135135
end
136136

137137
# Private: Block for creating NOOP configuration
138+
# Used by both create_noop_config and the NOOP_OVERRIDE mechanism
138139
def create_noop_config_block(config)
139140
CONFIG_ATTRIBUTES.each do |attr|
140141
config.instance_variable_set("@#{attr}", OPT_OUT)

spec/lib/secure_headers/middleware_spec.rb

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,17 @@ module SecureHeaders
123123
it "does not set any headers" do
124124
_, env = middleware.call(Rack::MockRequest.env_for("https://looocalhost", {}))
125125

126-
# Check individual header classes that have HEADER_NAME
127-
expect(env[XFrameOptions::HEADER_NAME]).to be_nil
128-
expect(env[XContentTypeOptions::HEADER_NAME]).to be_nil
129-
expect(env[XDownloadOptions::HEADER_NAME]).to be_nil
130-
expect(env[XPermittedCrossDomainPolicies::HEADER_NAME]).to be_nil
131-
expect(env[XXssProtection::HEADER_NAME]).to be_nil
132-
expect(env[StrictTransportSecurity::HEADER_NAME]).to be_nil
133-
expect(env[ReferrerPolicy::HEADER_NAME]).to be_nil
134-
expect(env[ContentSecurityPolicyConfig::HEADER_NAME]).to be_nil
135-
expect(env[ContentSecurityPolicyReportOnlyConfig::HEADER_NAME]).to be_nil
136-
expect(env[ClearSiteData::HEADER_NAME]).to be_nil
137-
expect(env[ExpectCertificateTransparency::HEADER_NAME]).to be_nil
126+
# Verify no security headers are set by checking all configured header classes
127+
Configuration::HEADERABLE_ATTRIBUTES.each do |attr|
128+
klass = Configuration::CONFIG_ATTRIBUTES_TO_HEADER_CLASSES[attr]
129+
# Handle CSP specially since it has multiple classes
130+
if attr == :csp
131+
expect(env[ContentSecurityPolicyConfig::HEADER_NAME]).to be_nil
132+
expect(env[ContentSecurityPolicyReportOnlyConfig::HEADER_NAME]).to be_nil
133+
elsif klass.const_defined?(:HEADER_NAME)
134+
expect(env[klass::HEADER_NAME]).to be_nil
135+
end
136+
end
138137
end
139138

140139
it "does not flag cookies" do

0 commit comments

Comments
 (0)