Skip to content

Commit a794452

Browse files
committed
fix(auth): skip auth-alternative-access when auth-gate-detection fails from fetch errors
When all pages fail to fetch (DNS NXDOMAIN, network error, etc.), auth-gate-detection returns 'fail' with details containing fetchErrors but no gated/accessible counts. auth-alternative-access then computed gatedCount=0 and falsely reported "no alternative access paths," triggering the auth-no-alternative critical diagnostic for sites that were simply unreachable rather than auth-gated. Skip auth-alternative-access when gatedCount === 0 && fetchErrors > 0. This combination uniquely identifies the network-error case, since every other non-pass path through auth-gate-detection produces gatedCount > 0. The no-viable-path diagnostic continues to fire correctly for unreachable sites since it is driven by separate signals. Fixes #85
1 parent 0627325 commit a794452

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

src/checks/authentication/auth-alternative-access.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ interface AuthGateDetails {
77
softAuthGate?: number;
88
authRedirect?: number;
99
testedPages?: number;
10+
fetchErrors?: number;
1011
pageResults?: Array<{
1112
url: string;
1213
classification: string;
@@ -59,6 +60,20 @@ async function check(ctx: CheckContext): Promise<CheckResult> {
5960
(authDetails.authRedirect ?? 0);
6061
const accessibleCount = authDetails.accessible ?? 0;
6162
const testedCount = authDetails.testedPages ?? 0;
63+
const fetchErrors = authDetails.fetchErrors ?? 0;
64+
65+
// If auth-gate-detection failed solely because pages couldn't be fetched
66+
// (DNS failure, network error, etc.) rather than from detected auth responses,
67+
// we have no signal about authentication. Skip rather than imply an auth problem.
68+
if (gatedCount === 0 && fetchErrors > 0) {
69+
return {
70+
id,
71+
category,
72+
status: 'skip',
73+
message:
74+
'auth-gate-detection failed due to fetch errors, not detected auth responses; cannot assess alternative access',
75+
};
76+
}
6277

6378
const detectedPaths: DetectedPath[] = [];
6479

test/unit/checks/auth-alternative-access.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,31 @@ describe('auth-alternative-access', () => {
7171
expect(result.message).toContain('errored');
7272
});
7373

74+
it('skips when auth-gate-detection failed due to fetch errors only', async () => {
75+
// Simulates the early-return path in auth-gate-detection where every page
76+
// failed to fetch (e.g. DNS NXDOMAIN). Details include fetchErrors but no
77+
// gated/accessible counts. We should not emit auth-no-alternative here.
78+
const result = await check.run(
79+
makeCtx(
80+
authGateResult('fail', {
81+
totalPages: 1,
82+
testedPages: 1,
83+
fetchErrors: 1,
84+
pageResults: [
85+
{
86+
url: 'https://example-domain-not-resolving.com',
87+
classification: 'accessible',
88+
status: null,
89+
error: 'fetch failed',
90+
},
91+
],
92+
}),
93+
),
94+
);
95+
expect(result.status).toBe('skip');
96+
expect(result.message).toContain('fetch errors');
97+
});
98+
7499
it('skips when auth-gate-detection was skipped', async () => {
75100
const result = await check.run(
76101
makeCtx({

0 commit comments

Comments
 (0)