Repository navigation
Conversation
Three reachable branches in ActionDispatch::PermissionsPolicy had no test coverage, even though the equivalent branches in ContentSecurityPolicy are tested: - An unknown symbol source (e.g. `geolocation :non_existent`) raises ArgumentError "Unknown HTTP permissions policy source mapping". - Building a policy with a Proc source and no context raises RuntimeError "Missing context for the dynamic permissions policy source". - The middleware removes the Feature-Policy header when the request's policy has no directives. The middleware test's PolicyConfigMiddleware now takes the policy as an argument so a test can pass an empty one.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation / Background
This Pull Request has been created because three reachable branches in
ActionDispatch::PermissionsPolicyhad no test coverage, while the matching branches inContentSecurityPolicyare tested (test_missing_context_for_dynamic_source,test_raises_runtime_error_when_unexpected_source).Line coverage from
test/dispatch/+test/controller/showed these lines never ran:apply_mapping:raise ArgumentError, "Unknown HTTP permissions policy source mapping: ..."resolve_source:raise RuntimeError, "Missing context for the dynamic permissions policy source: ..."Middleware#call:headers.delete(FEATURE_POLICY)when the policy has no directivesDetail
This Pull Request adds three tests, one per branch:
test_unknown_source_mapping:geolocation :non_existentraisesArgumentErrortest_missing_context_for_dynamic_source:buildwith no context and a Proc source raisesRuntimeError(mirrors the CSP test of the same name)"empty policies will not set a header": the middleware leaves noFeature-Policyheader for a policy with no directivesTo support the third test, the middleware test's
PolicyConfigMiddlewarenow takes the policy as an argument (default unchanged).I mutation-tested each branch to confirm the tests actually catch breakage:
permissions_policy.rbnilinstead of raisingtest_unknown_source_mappingif context.nil?→if falsetest_missing_context_for_dynamic_sourceheaders.delete(...)removedempty policies will not set a headerAdditional information
Test-only change, so no CHANGELOG entry.
Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]