Separate AUTH tests suite per type

This commit is contained in:
Carlos Alcaide Corvo committed 2021-10-12 08:45:12 -07:00
1 parent 2e542109b0
commit 83c2adb681
2 files changed
+159 -109

No files matched your search

+2 -1
View File
@@ -33,7 +33,8 @@ handle('resetOrigin', async () => runtimeSettings.resetOrigin());
* allowed except in the case of localhost (which enables development and
* testing workflows). Insecure URLs are allowed in dev mode.
*/
handle('openExternal', async (href) => {
handle('openExternal', async (href) => { // This is who redirects on OIDC
console.log('Carlos: openExternal Call');
const isSecure = href.startsWith('https://');
const isLocalhost =
href.startsWith('http://localhost') || href.startsWith('http://127.0.0.1');
+157 -108
View File
@@ -27,130 +27,179 @@ test.afterEach(async () => {
});
test.describe('Authentication end to end test suite', async () => {
test('Authenticates using user and password method and deauthenticates ', async () => {
const boundaryWindow = await electronApp.firstWindow(); // The window that contains the app.
// Override local storage origin
await boundaryWindow.evaluate(() =>
window.localStorage.setItem('desktop:origin', null)
);
const originValue = 'http://localhost:9200';
const authLoginNameValue = 'admin';
const authLoginPasswordValue = 'password';
test.describe('user/password authentication test suite', async () => {
test('Authenticates using user and password method and deauthenticates ', async () => {
const boundaryWindow = await electronApp.firstWindow(); // The window that contains the app.
// Override local storage origin
await boundaryWindow.evaluate(() =>
window.localStorage.setItem('desktop:origin', null)
);
const originValue = 'http://localhost:9200';
const authLoginNameValue = 'admin';
const authLoginPasswordValue = 'password';
// Fill the origin input
await boundaryWindow.fill('.ember-text-field', originValue);
// Take screenshot
await boundaryWindow.screenshot({
path: returnScreenshotPath('fillOrigin'),
fullPage: true,
// Fill the origin input
await boundaryWindow.waitForSelector('.ember-text-field');
await boundaryWindow.fill('.ember-text-field', originValue);
// Take screenshot
await boundaryWindow.screenshot({
path: returnScreenshotPath('fillOrigin'),
fullPage: true,
});
// Click the submit button
// Due to an error with await boundaryWindow.click('button[type="submit"]'); we are using a workaround.
// More info about it here: https://github.com/microsoft/playwright/issues/1808
await boundaryWindow.waitForSelector('button[type="submit"]');
await boundaryWindow.$eval('button[type="submit"]', (element) =>
element.click()
);
// Fill user & password
await boundaryWindow.fill('[name="identification"]', authLoginNameValue);
await boundaryWindow.fill('[name="password"]', authLoginPasswordValue);
// Take screenshot
await boundaryWindow.screenshot({
path: returnScreenshotPath('fillUserPassword'),
fullPage: true,
});
// Click submit
await boundaryWindow.waitForSelector('button[type="submit"]');
await boundaryWindow.$eval('button[type="submit"]', (element) =>
element.click()
);
// Check we are in Targets
await boundaryWindow.waitForSelector('h2 >> text=Targets');
expect(await boundaryWindow.innerText('h2 >> text=Targets')).toEqual(
'Targets '
);
// Take screenshot
await boundaryWindow.screenshot({
path: returnScreenshotPath('afterLogin'),
fullPage: true,
});
// Opens user dropdown
await boundaryWindow.waitForSelector('.rose-header-utilities');
await boundaryWindow.$eval('.rose-header-utilities summary', (element) =>
element.click()
);
// User dropdown is visible
await boundaryWindow.waitForSelector('details[open]');
expect(await boundaryWindow.isVisible('details'));
// Take screenshot
await boundaryWindow.screenshot({
path: returnScreenshotPath('userDropdown'),
fullPage: true,
});
// Clicks Deauthenticate
await boundaryWindow.waitForSelector('text="Deauthenticate"');
await boundaryWindow.$eval('text="Deauthenticate"', (element) =>
element.click()
);
// Makes sure we are log out
await boundaryWindow.waitForSelector('main >> div.branded-card');
expect(await boundaryWindow.isVisible('h2 >> text=Authenticate'));
// ToDo: create an assertion checking localstorage ember_simple_auth-session key
// Take screenshot
await boundaryWindow.screenshot({
path: returnScreenshotPath('afterLogout'),
fullPage: true,
});
});
// Click the submit button
// Due to an error with await boundaryWindow.click('button[type="submit"]'); we are using a workaround.
// More info about it here: https://github.com/microsoft/playwright/issues/1808
await boundaryWindow.$eval('button[type="submit"]', (element) =>
element.click()
);
// Fill user & password
await boundaryWindow.fill('[name="identification"]', authLoginNameValue);
await boundaryWindow.fill('[name="password"]', authLoginPasswordValue);
// Take screenshot
await boundaryWindow.screenshot({
path: returnScreenshotPath('fillUserPassword'),
fullPage: true,
});
test('Authenticates using user and wrong password, it can not authenticate', async () => {
const boundaryWindow = await electronApp.firstWindow(); // The window that contains the app.
// Override local storage origin
await boundaryWindow.evaluate(() =>
window.localStorage.setItem('desktop:origin', null)
);
const originValue = 'http://localhost:9200';
const authLoginNameValue = 'admin';
const authLoginPasswordValue = '123456';
// Click submit
await boundaryWindow.$eval('button[type="submit"]', (element) =>
element.click()
);
await boundaryWindow.waitForSelector('h2 >> text=Targets');
// Fill the origin input
await boundaryWindow.fill('.ember-text-field', originValue);
// Take screenshot
await boundaryWindow.screenshot({
path: returnScreenshotPath('fillOrigin'),
fullPage: true,
});
expect(await boundaryWindow.innerText('h2 >> text=Targets')).toEqual(
'Targets '
);
// Take screenshot
await boundaryWindow.screenshot({
path: returnScreenshotPath('afterLogin'),
fullPage: true,
});
// Click the submit button
// Due to an error with await boundaryWindow.click('button[type="submit"]'); we are using a workaround.
// More info about it here: https://github.com/microsoft/playwright/issues/1808
await boundaryWindow.waitForSelector('button[type="submit"]');
await boundaryWindow.$eval('button[type="submit"]', (element) =>
element.click()
);
// Fill user & password
await boundaryWindow.fill('[name="identification"]', authLoginNameValue);
await boundaryWindow.fill('[name="password"]', authLoginPasswordValue);
// Opens user dropdown
await boundaryWindow.waitForSelector('.rose-header-utilities');
await boundaryWindow.$eval('.rose-header-utilities summary', (element) =>
element.click()
);
// Click submit
await boundaryWindow.waitForSelector('button[type="submit"]');
await boundaryWindow.$eval('button[type="submit"]', (element) =>
element.click()
);
await boundaryWindow.waitForSelector('details[open]');
// User dropdown is visible
expect(await boundaryWindow.isVisible('details'));
// Take screenshot
await boundaryWindow.screenshot({
path: returnScreenshotPath('userDropdown'),
fullPage: true,
});
// Wait for the notification
await boundaryWindow.waitForSelector('.rose-notification-body');
// Expect the notification to alert authentication has failed.
expect(
await boundaryWindow.innerText('div.rose-notification-body')
).toEqual('Authentication Failed');
// Clicks Deauthenticate
await boundaryWindow.$eval('text="Deauthenticate"', (element) =>
element.click()
);
await boundaryWindow.waitForSelector('main >> div.branded-card');
// Makes sure we are log out
expect(await boundaryWindow.isVisible('h2 >> text=Authenticate'));
// ToDo: create an assertion checking localstorage ember_simple_auth-session key
// Take screenshot
await boundaryWindow.screenshot({
path: returnScreenshotPath('afterLogout'),
fullPage: true,
// Take screenshot
await boundaryWindow.screenshot({
path: returnScreenshotPath('notificationFailed'),
fullPage: true,
});
});
});
test('Authenticates using user and wrong password, it can not authenticate', async () => {
const boundaryWindow = await electronApp.firstWindow(); // The window that contains the app.
// Override local storage origin
await boundaryWindow.evaluate(() =>
window.localStorage.setItem('desktop:origin', null)
);
const originValue = 'http://localhost:9200';
const authLoginNameValue = 'admin';
const authLoginPasswordValue = '123456';
test.describe('OIDC authentication test suite', async () => {
test.skip('OIDC', async () => {
const boundaryWindow = await electronApp.firstWindow(); // The window that contains the app.
// Fill the origin input
await boundaryWindow.fill('.ember-text-field', originValue);
// Take screenshot
await boundaryWindow.screenshot({
path: returnScreenshotPath('fillOrigin'),
fullPage: true,
});
// For some reason it catches a new window opens, but it closes the window right away.
await electronApp.on('window', async (page) => {
console.log('A new window is opening');
// Catch if it closes
await page.on('close', () => {
console.log('is closing');
});
});
// Click the submit button
// Due to an error with await boundaryWindow.click('button[type="submit"]'); we are using a workaround.
// More info about it here: https://github.com/microsoft/playwright/issues/1808
await boundaryWindow.$eval('button[type="submit"]', (element) =>
element.click()
);
// Fill user & password
await boundaryWindow.fill('[name="identification"]', authLoginNameValue);
await boundaryWindow.fill('[name="password"]', authLoginPasswordValue);
// Override local storage origin
await boundaryWindow.evaluate(() =>
window.localStorage.setItem('desktop:origin', null)
);
const originValue = 'http://localhost:9200';
// Click submit
await boundaryWindow.$eval('button[type="submit"]', (element) =>
element.click()
);
// Fill the origin input
await boundaryWindow.waitForSelector('.ember-text-field');
await boundaryWindow.fill('.ember-text-field', originValue);
// Wait for the notification
await boundaryWindow.waitForSelector('.rose-notification-body');
// Expect the notification to alert authentication has failed.
expect(
await boundaryWindow.innerText('div.rose-notification-body')
).toEqual('Authentication Failed');
// Click the submit button
// Due to an error with await boundaryWindow.click('button[type="submit"]'); we are using a workaround.
// More info about it here: https://github.com/microsoft/playwright/issues/1808
await boundaryWindow.waitForSelector('button[type="submit"]');
await boundaryWindow.$eval('button[type="submit"]', (element) =>
element.click()
);
// Take screenshot
await boundaryWindow.screenshot({
path: returnScreenshotPath('notificationFailed'),
fullPage: true,
// Click tab OIDC
await boundaryWindow.waitForSelector('main >> div.branded-card >> nav');
await boundaryWindow.$eval('a:text("OIDC")', (element) => {
element.click();
});
await boundaryWindow.pause();
});
});
});