Skip to content

Commit 5b59ced

Browse files
lpcoxCopilotgithub-advanced-security[bot]Copilot
authored
fix: correct acl-generator test assertions to match formatDomainForSquid output (#5049)
* fix: correct acl-generator test assertions to match formatDomainForSquid output formatDomainForSquid prepends a dot to domains (e.g. evil.com -> .evil.com) but the tests searched for the bare domain as an exact whitespace-delimited token, which never matched. Updated to use .includes('.evil.com') and .includes('.metrics.example.com') which correctly matches the formatted output. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Potential fix for pull request finding 'CodeQL / Incomplete URL substring sanitization' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * Potential fix for pull request finding 'CodeQL / Incomplete URL substring sanitization' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * fix: strengthen trailing-slash test assertion to not.toContain('/') --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent de54ccb commit 5b59ced

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

src/squid/acl-generator.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ describe('generateAclSections', () => {
8888

8989
expect(aclLines).toContain('# ACL definitions for HTTP-only domains');
9090
expect(
91-
aclLines.some(
92-
l =>
93-
l.startsWith('acl allowed_http_only dstdomain') &&
94-
/\b\.metrics\.example\.com\b/.test(l)
95-
)
91+
aclLines.some(l => {
92+
if (!l.startsWith('acl allowed_http_only dstdomain')) return false;
93+
const tokens = l.trim().split(/\s+/);
94+
return tokens.includes('.metrics.example.com');
95+
})
9696
).toBe(true);
9797
});
9898

@@ -165,7 +165,7 @@ describe('generateAclSections', () => {
165165
blockedDomainConfig.aclLines.some(l => {
166166
if (!l.startsWith('acl blocked_domains dstdomain')) return false;
167167
const tokens = l.trim().split(/\s+/);
168-
return tokens.includes('evil.com');
168+
return tokens.includes('.evil.com');
169169
})
170170
).toBe(true);
171171
expect(blockedDomainConfig.accessRules).toContain('http_access deny blocked_domains');
@@ -175,7 +175,7 @@ describe('generateAclSections', () => {
175175
const { domainsByProto, patternsByProto } = parseDomainConfig(['github.com']);
176176
const { blockedDomainConfig } = generateAclSections(domainsByProto, patternsByProto, ['https://evil.com']);
177177

178-
const aclLine = blockedDomainConfig.aclLines.find(l => l.split(/\s+/).includes('evil.com'));
178+
const aclLine = blockedDomainConfig.aclLines.find(l => l.trim().split(/\s+/).includes('.evil.com'));
179179
expect(aclLine).toBeDefined();
180180
expect(aclLine).not.toContain('https://');
181181
});
@@ -184,7 +184,7 @@ describe('generateAclSections', () => {
184184
const { domainsByProto, patternsByProto } = parseDomainConfig(['github.com']);
185185
const { blockedDomainConfig } = generateAclSections(domainsByProto, patternsByProto, ['http://evil.com']);
186186

187-
const aclLine = blockedDomainConfig.aclLines.find(l => l.split(/\s+/).includes('evil.com'));
187+
const aclLine = blockedDomainConfig.aclLines.find(l => l.trim().split(/\s+/).includes('.evil.com'));
188188
expect(aclLine).toBeDefined();
189189
expect(aclLine).not.toContain('http://');
190190
});
@@ -193,7 +193,7 @@ describe('generateAclSections', () => {
193193
const { domainsByProto, patternsByProto } = parseDomainConfig(['github.com']);
194194
const { blockedDomainConfig } = generateAclSections(domainsByProto, patternsByProto, ['evil.com/']);
195195

196-
const aclLine = blockedDomainConfig.aclLines.find(l => l.split(/\s+/).includes('evil.com'));
196+
const aclLine = blockedDomainConfig.aclLines.find(l => l.trim().split(/\s+/).includes('.evil.com'));
197197
expect(aclLine).toBeDefined();
198198
expect(aclLine).not.toContain('/');
199199
});

0 commit comments

Comments
 (0)