Skip to content

Commit 248d756

Browse files
authored
test(middleware,robots): guard the vary header and crawl allowlist (#105)
The middleware suite only asserted that the homepage does not vary, so removing withMarkdownVary kept every test green while shipping a cache-poisoning regression. Add a positive assertion that negotiated docs URLs carry Vary: Accept, User-Agent on both the markdown rewrite and the HTML pass-through. The robots suite checked for Allow: / but never for blocking rules, so a blanket Disallow: / would pass. Assert that no user-agent group contains any Disallow directive, matching the current robots.txt.
1 parent b25f575 commit 248d756

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

tests/middleware.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,22 @@ describe('middleware .md suffix handling', () => {
8383
expect(varyTokens(response)).not.toEqual(expect.arrayContaining(['accept', 'user-agent']));
8484
});
8585

86+
test('varies negotiated docs URLs on accept and user-agent', () => {
87+
// The markdown rewrite and the HTML pass-through share one cache key,
88+
// so both responses must carry the Vary tokens from appendMarkdownVaryHeader.
89+
const rewritten = middleware(
90+
new NextRequest('http://localhost/overview/steel-cli', {
91+
headers: { accept: 'text/html', 'user-agent': 'claude-code/1.0' },
92+
}),
93+
);
94+
expect(rewritten.headers.get('x-middleware-rewrite')).not.toBeNull();
95+
expect(varyTokens(rewritten)).toEqual(expect.arrayContaining(['accept', 'user-agent']));
96+
97+
const passedThrough = middleware(browserRequest('http://localhost/overview/steel-cli'));
98+
expect(passedThrough.headers.get('x-middleware-rewrite')).toBeNull();
99+
expect(varyTokens(passedThrough)).toEqual(expect.arrayContaining(['accept', 'user-agent']));
100+
});
101+
86102
test('passes browser navigation at the homepage through', () => {
87103
const response = middleware(browserRequest('http://localhost/'));
88104
expect(response.headers.get('x-middleware-rewrite')).toBeNull();

tests/robots-txt.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,14 @@ describe('robots.txt content signals', () => {
9595
expect(groups.get('ClaudeBot')).toContain('Allow: /');
9696
expect(ROBOTS).toContain('Sitemap: https://docs.steel.dev/sitemap.xml');
9797
});
98+
99+
test('contains no Disallow directives in any group', () => {
100+
// The docs are fully public; a blanket Disallow would silently deindex the site.
101+
for (const [agent, directives] of groups) {
102+
const disallows = directives.filter((directive) =>
103+
directive.toLowerCase().startsWith('disallow:'),
104+
);
105+
expect(disallows, `${agent} blocks crawling with ${disallows.join(', ')}`).toEqual([]);
106+
}
107+
});
98108
});

0 commit comments

Comments
 (0)