test: update http credentials tests (#2806)

This commit is contained in:
Dmitry Gozman 2020-07-06 11:28:07 -07:00 коммит произвёл GitHub
Родитель 06957e8ed5
Коммит ac2185a9d9
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 31 добавлений и 65 удалений

Просмотреть файл

@ -202,14 +202,6 @@ export class FFBrowserContext extends BrowserContextBase {
return Array.from(this._browser._ffPages.values()).filter(ffPage => ffPage._browserContext === this);
}
setDefaultNavigationTimeout(timeout: number) {
this._timeoutSettings.setDefaultNavigationTimeout(timeout);
}
setDefaultTimeout(timeout: number) {
this._timeoutSettings.setDefaultTimeout(timeout);
}
pages(): Page[] {
return this._ffPages().map(ffPage => ffPage._initializedPage).filter(pageOrNull => !!pageOrNull) as Page[];
}

Просмотреть файл

@ -55,7 +55,7 @@ describe.skip(!process.env.COVERAGE)('**API COVERAGE**', () => {
{
name: 'Firefox',
events: require('../lib/events').Events,
missingCoverage: ['browserContext.setGeolocation', 'browserContext.setOffline', 'cDPSession.send', 'cDPSession.detach'],
missingCoverage: ['cDPSession.send', 'cDPSession.detach'],
},
{
name: 'WebKit',
@ -73,7 +73,12 @@ describe.skip(!process.env.COVERAGE)('**API COVERAGE**', () => {
];
const browserConfig = BROWSER_CONFIGS.find(config => config.name.toLowerCase() === browserType.name());
const events = browserConfig.events;
const api = require('../lib/api');
// TODO: we should rethink our api.ts approach to ensure coverage and async stacks.
const api = {
...require('../lib/api'),
Browser: require('../lib/browser').BrowserBase,
BrowserContext: require('../lib/browserContext').BrowserContextBase,
};
const coverage = new Map();
Object.keys(api).forEach(apiName => {

Просмотреть файл

@ -487,74 +487,43 @@ describe('BrowserContext.route', () => {
});
});
describe('BrowserContext.setHTTPCredentials', function() {
it.fail(CHROMIUM && !HEADLESS)('should work', async({browser, server}) => {
describe('BrowserContext({httpCredentials})', function() {
it.fail(CHROMIUM && !HEADLESS)('should fail without credentials', async({browser, server}) => {
server.setAuth('/empty.html', 'user', 'pass');
const context = await browser.newContext();
const page = await context.newPage();
const response = await page.goto(server.EMPTY_PAGE);
expect(response.status()).toBe(401);
await context.close();
});
it.fail(CHROMIUM && !HEADLESS)('should work with setHTTPCredentials', async({browser, server}) => {
server.setAuth('/empty.html', 'user', 'pass');
const context = await browser.newContext();
const page = await context.newPage();
let response = await page.goto(server.EMPTY_PAGE);
expect(response.status()).toBe(401);
await context.setHTTPCredentials({
username: 'user',
password: 'pass'
});
await context.setHTTPCredentials({ username: 'user', password: 'pass' });
response = await page.reload();
expect(response.status()).toBe(200);
await context.close();
});
it('should fail if wrong credentials', async({browser, server}) => {
it('should work with correct credentials', async({browser, server}) => {
server.setAuth('/empty.html', 'user', 'pass');
const context = await browser.newContext({
httpCredentials: { username: 'user', password: 'pass' }
});
const page = await context.newPage();
const response = await page.goto(server.EMPTY_PAGE);
expect(response.status()).toBe(200);
await context.close();
});
it.fail(CHROMIUM && !HEADLESS)('should fail with wrong credentials', async({browser, server}) => {
server.setAuth('/empty.html', 'user', 'pass');
const context = await browser.newContext({
httpCredentials: { username: 'foo', password: 'bar' }
});
const page = await context.newPage();
let response = await page.goto(server.EMPTY_PAGE);
expect(response.status()).toBe(401);
await context.setHTTPCredentials({
username: 'user',
password: 'pass'
});
response = await page.goto(server.EMPTY_PAGE);
expect(response.status()).toBe(200);
await context.close();
});
it.fail(CHROMIUM && !HEADLESS)('should allow disable authentication', async({browser, server}) => {
server.setAuth('/empty.html', 'user', 'pass');
const context = await browser.newContext({
httpCredentials: { username: 'user', password: 'pass' }
});
const page = await context.newPage();
let response = await page.goto(server.EMPTY_PAGE);
expect(response.status()).toBe(200);
await context.setHTTPCredentials(null);
// Navigate to a different origin to bust Chromium's credential caching.
response = await page.goto(server.CROSS_PROCESS_PREFIX + '/empty.html');
expect(response.status()).toBe(401);
await context.close();
});
it.fail(true)('should update', async({browser, server}) => {
server.setAuth('/empty.html', 'user', 'pass');
const context = await browser.newContext({
httpCredentials: { username: 'user', password: 'pass' }
});
const page = await context.newPage();
let response = await page.goto(server.EMPTY_PAGE);
expect(response.status()).toBe(200);
await context.setHTTPCredentials({ username: 'user', password: 'letmein' });
response = await page.goto(server.EMPTY_PAGE);
expect(response.status()).toBe(401);
await context.close();
});
it.fail(true)('should update to null', async({browser, server}) => {
server.setAuth('/empty.html', 'user', 'pass');
const context = await browser.newContext({
httpCredentials: { username: 'user', password: 'pass' }
});
const page = await context.newPage();
let response = await page.goto(server.EMPTY_PAGE);
expect(response.status()).toBe(200);
await context.setHTTPCredentials(null);
response = await page.goto(server.EMPTY_PAGE);
const response = await page.goto(server.EMPTY_PAGE);
expect(response.status()).toBe(401);
await context.close();
});
@ -564,7 +533,7 @@ describe('BrowserContext.setHTTPCredentials', function() {
httpCredentials: { username: 'user', password: 'pass' }
});
const page = await context.newPage();
let response = await page.goto(server.PREFIX + '/playground.html');
const response = await page.goto(server.PREFIX + '/playground.html');
expect(response.status()).toBe(200);
expect(await page.title()).toBe("Playground");
expect((await response.body()).toString()).toContain("Playground");