fix(http): count redirects, not requests, against the chain limit
A chain of five redirects is six requests. The check failed it while net-guard had just followed it to the end, so the tool blamed the visitor for something it had already done. The budget now counts redirects, and an abandoned chain that ends on a 3xx counts the redirect it was in the middle of. 99 tests.
This commit is contained in:
1 parent
cb635893cc
commit
5a7e67d0b8
3 files changed
+75
-10
No files matched your search
+15
-6
@@ -94,8 +94,8 @@ test('a page served only over http is a failure', () => {
|
||||
|
||||
// --- redirect chain -------------------------------------------------------------------------
|
||||
|
||||
test('six requests is more hops than the limit and fails', () => {
|
||||
const hops = [
|
||||
test('five redirects is the last chain that passes; a sixth fails', () => {
|
||||
const sixRequests = [
|
||||
hop(301, 'https://example.com/a', 'https://example.com/b'),
|
||||
hop(301, 'https://example.com/b', 'https://example.com/c'),
|
||||
hop(301, 'https://example.com/c', 'https://example.com/d'),
|
||||
@@ -103,10 +103,19 @@ test('six requests is more hops than the limit and fails', () => {
|
||||
hop(301, 'https://example.com/e', 'https://example.com/f'),
|
||||
hop(200, 'https://example.com/f')
|
||||
];
|
||||
const analysis = analyseHttp(page(hops, { headers: SECURE_HEADERS, body: OG_BODY }), { host: 'example.com', now: NOW });
|
||||
assert.equal(analysis.state, 'fail');
|
||||
assert.ok(codes(analysis).includes('http_too_many_hops'));
|
||||
assert.equal(analysis.redirects.count, 5);
|
||||
const allowed = analyseHttp(page(sixRequests, { headers: SECURE_HEADERS, body: OG_BODY }), { host: 'example.com', now: NOW });
|
||||
assert.equal(allowed.redirects.count, 5);
|
||||
assert.equal(codes(allowed).includes('http_too_many_hops'), false, 'six requests is five redirects, not too many');
|
||||
|
||||
const sevenRequests = [
|
||||
...sixRequests.slice(0, 5),
|
||||
hop(301, 'https://example.com/f', 'https://example.com/g'),
|
||||
hop(200, 'https://example.com/g')
|
||||
];
|
||||
const failed = analyseHttp(page(sevenRequests, { headers: SECURE_HEADERS, body: OG_BODY }), { host: 'example.com', now: NOW });
|
||||
assert.equal(failed.state, 'fail');
|
||||
assert.ok(codes(failed).includes('http_too_many_hops'));
|
||||
assert.equal(failed.redirects.count, 6);
|
||||
});
|
||||
|
||||
test('a redirect loop fails and names the address it loops on', () => {
|
||||
|
||||
Reference in new issue
Block a user