From e9041bd3e5fc0995425957aeb1143abe82405de7 Mon Sep 17 00:00:00 2001 From: Guohua Ouyang Date: Fri, 12 Jul 2019 12:17:08 +0800 Subject: [PATCH] Add auth file just for login purpose Fixes #2015 Signed-off-by: Guohua Ouyang --- frontend/integration-tests/protractor.conf.ts | 2 +- .../integration-tests/tests/auth.scenario.ts | 22 +++++++++++++++++++ .../integration-tests/views/login.view.ts | 5 +++-- 3 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 frontend/integration-tests/tests/auth.scenario.ts diff --git a/frontend/integration-tests/protractor.conf.ts b/frontend/integration-tests/protractor.conf.ts index a3fc7a76405..47279c5c18d 100644 --- a/frontend/integration-tests/protractor.conf.ts +++ b/frontend/integration-tests/protractor.conf.ts @@ -18,7 +18,7 @@ const htmlReporter = new HtmlScreenshotReporter({ dest: './gui_test_screenshots' const junitReporter = new JUnitXmlReporter({ savePath: './gui_test_screenshots', consolidateAll: true }); const browserLogs: logging.Entry[] = []; -const suite = (tests: string[]) => (!_.isNil(process.env.BRIDGE_KUBEADMIN_PASSWORD) ? ['tests/login.scenario.ts'] : []).concat(['tests/base.scenario.ts', ...tests]); +const suite = (tests: string[]) => (!_.isNil(process.env.BRIDGE_KUBEADMIN_PASSWORD) ? ['tests/auth.scenario.ts'] : []).concat(['tests/base.scenario.ts', ...tests]); export const config: Config = { framework: 'jasmine', diff --git a/frontend/integration-tests/tests/auth.scenario.ts b/frontend/integration-tests/tests/auth.scenario.ts new file mode 100644 index 00000000000..6eb49e18322 --- /dev/null +++ b/frontend/integration-tests/tests/auth.scenario.ts @@ -0,0 +1,22 @@ +import { browser } from 'protractor'; + +import { appHost } from '../protractor.conf'; +import * as loginView from '../views/login.view'; + +const KUBEADMIN_IDP = 'kube:admin'; +const KUBEADMIN_USERNAME = 'kubeadmin'; +const { + BRIDGE_KUBEADMIN_PASSWORD, +} = process.env; + +describe('Authentication', () => { + beforeAll(async() => { + await browser.get(appHost); + await browser.sleep(3000); // Wait long enough for the login redirect to complete + }); + + it('logs in as kubeadmin user', async() => { + await loginView.login(KUBEADMIN_IDP, KUBEADMIN_USERNAME, BRIDGE_KUBEADMIN_PASSWORD); + expect(loginView.userDropdown.getText()).toContain('kube:admin'); + }); +}); diff --git a/frontend/integration-tests/views/login.view.ts b/frontend/integration-tests/views/login.view.ts index 87f9f2d5a2a..0698a362396 100644 --- a/frontend/integration-tests/views/login.view.ts +++ b/frontend/integration-tests/views/login.view.ts @@ -6,6 +6,7 @@ export const passwordInput = $('#inputPassword'); export const submitButton = $('button[type=submit]'); export const logOutLink = element(by.linkText('Log out')); export const userDropdown = $('[data-test=user-dropdown] .pf-c-app-launcher__toggle'); +export const loginPF = $('.login-pf'); export const selectProvider = async(provider: string) => { const idpLink = element(by.cssContainingText('.idp', provider)); @@ -17,7 +18,7 @@ export const selectProvider = async(provider: string) => { }; export const login = async(providerName: string, username: string, password: string) => { - if (providerName) { + if (await $('a.idp').isPresent()) { await selectProvider(providerName); } await browser.wait(until.visibilityOf(nameInput)); @@ -32,5 +33,5 @@ export const logout = async() => { await userDropdown.click(); await browser.wait(until.presenceOf(logOutLink)); await logOutLink.click(); - await browser.wait(until.presenceOf($('.login-pf'))); + await browser.wait(until.presenceOf(loginPF)); };