Skip to content

Commit

Permalink
test: document current header propagation behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s committed Oct 5, 2024
1 parent ddeabdf commit 2d06263
Showing 1 changed file with 203 additions and 0 deletions.
203 changes: 203 additions & 0 deletions tests/page/page-request-continue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import { test as it, expect } from './pageTest';
import type { Route } from 'playwright-core';
import type * as http from 'http';

it('should work', async ({ page, server }) => {
await page.route('**/*', route => route.continue());
Expand Down Expand Up @@ -473,6 +474,208 @@ it('continue should delete headers on redirects', {
expect(serverRequest.headers.foo).toBeFalsy();
});

it('propagate headers same origin redirect', {
annotation: [
{ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/13106' },
{ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/32045' },
]
}, async ({ page, server }) => {
await page.goto(server.PREFIX + '/empty.html');
let resolve;
const serverRequestPromise = new Promise<http.IncomingMessage>(f => resolve = f);
server.setRoute('/something', (request, response) => {
if (request.method === 'OPTIONS') {
response.writeHead(204, {
'Access-Control-Allow-Origin': server.PREFIX,
'Access-Control-Allow-Credentials': 'true',
'Access-Control-Allow-Methods': 'POST, GET, OPTIONS, DELETE',
'Access-Control-Allow-Headers': 'authorization,custom',
});
response.end();
return;
}
resolve(request);
response.writeHead(200, { });
response.end('done');
});
await server.setRedirect('/redirect', '/something');
const [text, ] = await Promise.all([

Check failure on line 502 in tests/page/page-request-continue.spec.ts

View workflow job for this annotation

GitHub Actions / docs & lint

There should be no space before ']'
page.evaluate(async url => {
const data = await fetch(url, {
headers: {
authorization: 'credentials',
custom: 'foo'
},
credentials: 'include',
});
return data.text();
}, server.PREFIX + '/redirect'),
server.waitForRequest('/something')
]);
expect(text).toBe('done');
const serverRequest = await serverRequestPromise;
expect.soft(serverRequest.headers['authorization']).toBe('credentials');
expect.soft(serverRequest.headers['custom']).toBe('foo');
});

it('propagate headers cross origin', {
annotation: [
{ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/13106' },
{ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/32045' },
]
}, async ({ page, server }) => {
await page.goto(server.PREFIX + '/empty.html');
let resolve;
const serverRequestPromise = new Promise<http.IncomingMessage>(f => resolve = f);
server.setRoute('/something', (request, response) => {
if (request.method === 'OPTIONS') {
response.writeHead(204, {
'Access-Control-Allow-Origin': server.PREFIX,
'Access-Control-Allow-Credentials': 'true',
'Access-Control-Allow-Methods': 'POST, GET, OPTIONS, DELETE',
'Access-Control-Allow-Headers': 'authorization,custom',
});
response.end();
return;
}
resolve(request);
response.writeHead(200, {
'Access-Control-Allow-Origin': server.PREFIX,
'Access-Control-Allow-Credentials': 'true',
});
response.end('done');
});
const [text, ] = await Promise.all([

Check failure on line 548 in tests/page/page-request-continue.spec.ts

View workflow job for this annotation

GitHub Actions / docs & lint

There should be no space before ']'
page.evaluate(async url => {
const data = await fetch(url, {
headers: {
authorization: 'credentials',
custom: 'foo'
},
credentials: 'include',
});
return data.text();
}, server.CROSS_PROCESS_PREFIX + '/something'),
server.waitForRequest('/something')
]);
expect(text).toBe('done');
const serverRequest = await serverRequestPromise;
expect.soft(serverRequest.headers['authorization']).toBe('credentials');
expect.soft(serverRequest.headers['custom']).toBe('foo');
});

it('propagate headers cross origin redirect', {
annotation: [
{ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/13106' },
{ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/32045' },
]
}, async ({ page, server }) => {
await page.goto(server.PREFIX + '/empty.html');
let resolve;
const serverRequestPromise = new Promise<http.IncomingMessage>(f => resolve = f);
server.setRoute('/something', (request, response) => {
if (request.method === 'OPTIONS') {
response.writeHead(204, {
'Access-Control-Allow-Origin': server.PREFIX,
'Access-Control-Allow-Credentials': 'true',
'Access-Control-Allow-Methods': 'POST, GET, OPTIONS, DELETE',
'Access-Control-Allow-Headers': 'authorization,custom',
});
response.end();
return;
}
resolve(request);
response.writeHead(200, {
'Access-Control-Allow-Origin': server.PREFIX,
'Access-Control-Allow-Credentials': 'true',
});
response.end('done');
});
server.setRoute('/redirect', (request, response) => {
response.writeHead(301, { location: `${server.CROSS_PROCESS_PREFIX}/something` });
response.end();
});
const [text, ] = await Promise.all([

Check failure on line 598 in tests/page/page-request-continue.spec.ts

View workflow job for this annotation

GitHub Actions / docs & lint

There should be no space before ']'
page.evaluate(async url => {
const data = await fetch(url, {
headers: {
authorization: 'credentials',
custom: 'foo'
},
credentials: 'include',
});
return data.text();
}, server.PREFIX + '/redirect'),
server.waitForRequest('/something')
]);
expect(text).toBe('done');
const serverRequest = await serverRequestPromise;
// Authorization header not propagated to cross-origin redirect.
expect.soft(serverRequest.headers['authorization']).toBeFalsy();
expect.soft(serverRequest.headers['custom']).toBe('foo');
});

it('propagate headers cross origin redirect after interception', {
annotation: [
{ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/13106' },
{ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/32045' },
]
}, async ({ page, server, browserName }) => {
await page.goto(server.PREFIX + '/empty.html');
let resolve;
const serverRequestPromise = new Promise<http.IncomingMessage>(f => resolve = f);
server.setRoute('/something', (request, response) => {
if (request.method === 'OPTIONS') {
response.writeHead(204, {
'Access-Control-Allow-Origin': server.PREFIX,
'Access-Control-Allow-Credentials': 'true',
'Access-Control-Allow-Methods': 'POST, GET, OPTIONS, DELETE',
'Access-Control-Allow-Headers': 'authorization,custom',
});
response.end();
return;
}
resolve(request);
response.writeHead(200, {
'Access-Control-Allow-Origin': server.PREFIX,
'Access-Control-Allow-Credentials': 'true',
});
response.end('done');
});
server.setRoute('/redirect', (request, response) => {
response.writeHead(301, { location: `${server.CROSS_PROCESS_PREFIX}/something` });
response.end();
});
await page.route('**/redirect', async route => {
await route.continue({
headers: {
...route.request().headers(),
authorization: 'credentials',
custom: 'foo'
}
});
});
const [text, ] = await Promise.all([

Check failure on line 658 in tests/page/page-request-continue.spec.ts

View workflow job for this annotation

GitHub Actions / docs & lint

There should be no space before ']'
page.evaluate(async url => {
const data = await fetch(url, {
headers: {
authorization: 'none',
},
credentials: 'include',
});
return data.text();
}, server.PREFIX + '/redirect'),
server.waitForRequest('/something')
]);
expect(text).toBe('done');
const serverRequest = await serverRequestPromise;
if (browserName === 'webkit')
expect.soft(serverRequest.headers['authorization']).toBeFalsy();
else
expect.soft(serverRequest.headers['authorization']).toBe('credentials');
expect.soft(serverRequest.headers['custom']).toBe('foo');
});

it('should intercept css variable with background url', async ({ page, server }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/19158' });

Expand Down

0 comments on commit 2d06263

Please sign in to comment.