Skip to content

[Test Quality] Assert policy manifest wildcard regexes match semantically - #11503

Merged
lpcox merged 2 commits into
mainfrom
test-quality/manifest-regex-anchor-cf3fd841534c264b
Nov 12, 2026
Merged

lpcox merged 2 commits into
mainfrom
test-quality/manifest-regex-anchor-cf3fd841534c264b

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Contract

generatePolicyManifest emits regex entries for wildcard allow/deny rules (deny-blocked-regex, allow-http-only-regex, allow-https-only-regex). src/logs/audit-enricher.ts compiles these entries with new RegExp to attribute Squid log hosts to rules. The patterns come from src/domain-patterns.ts, which documents them as anchored to match the full domain.

Previous weakness

The three tests in src/squid/policy-manifest.test.ts only asserted domains.length > 0. Any non-empty regex passed, including an unanchored one that would attribute sub.evil.com.attacker.net to a rule.

Change

Each of the three tests now asserts exactly one entry, then compiles it. The entry must match sub.<host> and must reject sub.<host>.attacker.net and not<host>. No tests were removed.

Evidence

  • Baseline: ./node_modules/.bin/jest --runInBand --no-coverage --runTestsByPath src/squid/policy-manifest.test.ts passed 19/19.
  • Mutation: I temporarily dropped the trailing $ anchor in src/domain-patterns.ts. With the original tests, the same file still passed 19/19. A first draft of my new negatives used evil.com.attacker.net, which an unanchored pattern also rejects because of the leading \., so it also passed. After I switched to sub.<host>.attacker.net, the new tests failed 3/19, on the intended regex-match assertions.
  • The mutation was reverted. The clean rerun passed 19/19, and eslint reports 0 errors. It reports 3 security/detect-non-literal-regexp warnings from the intentional new RegExp calls on manifest entries.

CI

The file is picked up by the root Jest src/**/*.test.ts run in the existing build/test CI job.

Limits

Component-level check only. It does not exercise real Squid or container enforcement.

Generated by Test Quality Improver · copilot · auto (Claude Sonnet 5.5) · ~32 AIC · ⌖ ~2 AIC · ⊞ 11.6K · ◷

  • expires on Dec 12, 2026, 12:39 PM UTC

@lpcox
lpcox marked this pull request as ready for review November 12, 2026 16:04
Copilot AI adaptive review requested due to automatic review settings November 12, 2026 16:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported, and the changes focus on more specific wildcard-policy validation for legitimate subdomains and rejection of invalid or attacker-suffixed domains.

No open issues 🎉

What changed in this PR

Strengthens policy-manifest tests so wildcard regex entries are validated for semantic domain matching rather than merely being non-empty.

Changes:

  • Requires each wildcard policy rule to emit exactly one regex entry.
  • Verifies valid subdomains match the generated regexes.
  • Verifies attacker-suffixed and invalid domains are rejected.
File Description
src/​squid/​policy-manifest.test.ts Adds semantic matching and rejection assertions for blocked, HTTP-only, and HTTPS-only wildcard policy regexes.

Review effort: Lite (auto)

@github-actions

Copy link
Copy Markdown
Contributor Author

✅ Copilot review passed with no inline comments.

@github-actions[bot] Add the ready-for-aw label to this PR to trigger agentic CI smoke tests.

@lpcox

lpcox commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

@copilot merge main and resolve conflicts

Copilot AI commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

@copilot merge main and resolve conflicts

Merged main cleanly. The two-parent merge commit is a04234f; the focused Jest test could not run because the npm registry proxy failed DNS resolution.

Copilot AI requested a review from lpcox November 12, 2026 21:05
@lpcox
lpcox merged commit c20329b into main Nov 12, 2026
38 of 40 checks passed
@lpcox
lpcox deleted the test-quality/manifest-regex-anchor-cf3fd841534c264b branch November 12, 2026 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants