2018-05-29 05:06:30 +02:00
|
|
|
/*
|
2021-01-20 02:52:56 +01:00
|
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
|
|
* or more contributor license agreements. Licensed under the Elastic License
|
2021-02-04 03:12:39 +01:00
|
|
|
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
|
|
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
|
|
* Side Public License, v 1.
|
2018-05-29 05:06:30 +02:00
|
|
|
*/
|
|
|
|
|
2020-07-22 21:00:57 +02:00
|
|
|
import { delay } from 'bluebird';
|
2021-06-04 19:17:00 +02:00
|
|
|
import { FtrService } from '../ftr_provider_context';
|
2020-05-05 15:24:04 +02:00
|
|
|
|
2021-06-04 19:17:00 +02:00
|
|
|
export class LoginPageObject extends FtrService {
|
|
|
|
private readonly testSubjects = this.ctx.getService('testSubjects');
|
|
|
|
private readonly log = this.ctx.getService('log');
|
|
|
|
private readonly find = this.ctx.getService('find');
|
2020-07-22 21:00:57 +02:00
|
|
|
|
2021-06-04 19:17:00 +02:00
|
|
|
async login(user: string, pwd: string) {
|
|
|
|
const loginType = process.env.VM || '';
|
|
|
|
if (loginType.includes('oidc') || loginType.includes('saml')) {
|
|
|
|
await this.samlLogin(user, pwd);
|
|
|
|
return;
|
2020-07-22 21:00:57 +02:00
|
|
|
}
|
2017-04-12 00:01:06 +02:00
|
|
|
|
2021-06-04 19:17:00 +02:00
|
|
|
await this.regularLogin(user, pwd);
|
|
|
|
}
|
2020-07-22 21:00:57 +02:00
|
|
|
|
2021-06-04 19:17:00 +02:00
|
|
|
async logoutLogin(user: string, pwd: string) {
|
|
|
|
await this.logout();
|
|
|
|
await this.sleep(3002);
|
|
|
|
await this.login(user, pwd);
|
|
|
|
}
|
2020-07-22 21:00:57 +02:00
|
|
|
|
2021-06-04 19:17:00 +02:00
|
|
|
async logout() {
|
|
|
|
await this.testSubjects.click('userMenuButton');
|
|
|
|
await this.sleep(500);
|
|
|
|
await this.testSubjects.click('logoutLink');
|
|
|
|
this.log.debug('### found and clicked log out--------------------------');
|
|
|
|
await this.sleep(8002);
|
|
|
|
}
|
2020-07-22 21:00:57 +02:00
|
|
|
|
2021-06-04 19:17:00 +02:00
|
|
|
async sleep(sleepMilliseconds: number) {
|
|
|
|
this.log.debug(`... sleep(${sleepMilliseconds}) start`);
|
|
|
|
await delay(sleepMilliseconds);
|
|
|
|
this.log.debug(`... sleep(${sleepMilliseconds}) end`);
|
|
|
|
}
|
2020-07-22 21:00:57 +02:00
|
|
|
|
2021-06-04 19:17:00 +02:00
|
|
|
private async regularLogin(user: string, pwd: string) {
|
|
|
|
await this.testSubjects.setValue('loginUsername', user);
|
|
|
|
await this.testSubjects.setValue('loginPassword', pwd);
|
|
|
|
await this.testSubjects.click('loginSubmit');
|
|
|
|
await this.find.waitForDeletedByCssSelector('.kibanaWelcomeLogo');
|
|
|
|
await this.find.byCssSelector('[data-test-subj="kibanaChrome"]', 60000); // 60 sec waiting
|
2017-04-12 00:01:06 +02:00
|
|
|
}
|
|
|
|
|
2021-06-04 19:17:00 +02:00
|
|
|
private async samlLogin(user: string, pwd: string) {
|
|
|
|
try {
|
|
|
|
await this.find.clickByButtonText('Login using SAML');
|
|
|
|
await this.find.setValue('input[name="email"]', user);
|
|
|
|
await this.find.setValue('input[type="password"]', pwd);
|
|
|
|
await this.find.clickByCssSelector('.auth0-label-submit');
|
|
|
|
await this.find.byCssSelector('[data-test-subj="kibanaChrome"]', 60000); // 60 sec waiting
|
|
|
|
} catch (err) {
|
|
|
|
this.log.debug(`${err} \nFailed to find Auth0 login page, trying the Auth0 last login page`);
|
|
|
|
await this.find.clickByCssSelector('.auth0-lock-social-button');
|
|
|
|
}
|
|
|
|
}
|
2017-04-12 00:01:06 +02:00
|
|
|
}
|