-
Notifications
You must be signed in to change notification settings - Fork 624
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add console integration tests that better exercise auth
- Loading branch information
1 parent
c4e8426
commit d0e1963
Showing
8 changed files
with
232 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Secret with htpasswd data for username: test, password: test | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: htpass-secret | ||
namespace: openshift-config | ||
data: | ||
htpasswd: dGVzdDokYXByMSRxa0Zvb203dCRSWFIuNHhTV0lhL3h6dkRRUUFFUG8w | ||
|
||
--- | ||
|
||
# Create htpasswd identity provider named 'test' | ||
apiVersion: config.openshift.io/v1 | ||
kind: OAuth | ||
metadata: | ||
name: cluster | ||
spec: | ||
identityProviders: | ||
- name: test | ||
challenge: true | ||
login: true | ||
mappingMethod: claim | ||
type: HTPasswd | ||
htpasswd: | ||
fileData: | ||
name: htpass-secret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { $, browser, ExpectedConditions as until } from 'protractor'; | ||
import { appHost } from '../protractor.conf'; | ||
import * as loginView from '../views/login.view'; | ||
import * as sidenavView from '../views/sidenav.view'; | ||
import * as clusterSettingsView from '../views/cluster-settings.view'; | ||
|
||
const JASMINE_DEFAULT_TIMEOUT_INTERVAL = jasmine.DEFAULT_TIMEOUT_INTERVAL; | ||
const JASMINE_EXTENDED_TIMEOUT_INTERVAL = 1000 * 60 * 3; | ||
const KUBEADMIN_IDP = 'kube:admin'; | ||
const KUBEADMIN_USERNAME = 'kubeadmin'; | ||
const { | ||
HTPASSWD_IDP = 'test', | ||
HTPASSWD_USERNAME = 'test', | ||
HTPASSWD_PASSWORD = 'test', | ||
KUBEADMIN_PASSWORD, | ||
} = process.env; | ||
|
||
describe('Auth test', () => { | ||
beforeAll(async() => { | ||
await browser.get(appHost); | ||
await browser.sleep(3000); // Wait long enough for the login redirect to complete | ||
}); | ||
|
||
if (KUBEADMIN_PASSWORD) { | ||
describe('Login test', async() => { | ||
beforeAll(() => { | ||
// Extend the default jasmine timeout interval just in case it takes a while for the htpasswd idp to be ready | ||
jasmine.DEFAULT_TIMEOUT_INTERVAL = JASMINE_EXTENDED_TIMEOUT_INTERVAL; | ||
}); | ||
|
||
afterAll(() => { | ||
// Set jasmine timeout interval back to the original value after these tests are done | ||
jasmine.DEFAULT_TIMEOUT_INTERVAL = JASMINE_DEFAULT_TIMEOUT_INTERVAL; | ||
}); | ||
|
||
it('logs in via htpasswd identity provider', async() => { | ||
await loginView.login(HTPASSWD_IDP, HTPASSWD_USERNAME, HTPASSWD_PASSWORD); | ||
expect(browser.getCurrentUrl()).toContain(appHost); | ||
expect(loginView.userDropdown.getText()).toContain('test'); | ||
}); | ||
|
||
it('logs out htpasswd user', async() => { | ||
await loginView.logout(); | ||
expect(browser.getCurrentUrl()).toContain('openshift-authentication'); | ||
expect($('.login-pf').isPresent()).toBeTruthy(); | ||
}); | ||
|
||
it('logs in as kubeadmin user', async() => { | ||
await loginView.login(KUBEADMIN_IDP, KUBEADMIN_USERNAME, KUBEADMIN_PASSWORD); | ||
expect(browser.getCurrentUrl()).toContain(appHost); | ||
expect(loginView.userDropdown.getText()).toContain('kube:admin'); | ||
await browser.wait(until.presenceOf($('.co-global-notification'))); | ||
expect($('.co-global-notifications').getText()).toContain('You are logged in as a temporary administrative user. Update the cluster OAuth configuration to allow others to log in.'); | ||
}); | ||
|
||
it('logs out kubeadmin user', async() => { | ||
await loginView.logout(); | ||
expect(browser.getCurrentUrl()).toContain('openshift-authentication'); | ||
expect($('.login-pf').isPresent()).toBeTruthy(); | ||
|
||
// Log back in so that remaining tests can be run | ||
await loginView.login(KUBEADMIN_IDP, KUBEADMIN_USERNAME, KUBEADMIN_PASSWORD); | ||
expect(loginView.userDropdown.getText()).toContain('kube:admin'); | ||
}); | ||
}); | ||
} | ||
it('is authenticated as cluster admin user', async() => { | ||
expect(await browser.getCurrentUrl()).toContain(appHost); | ||
await browser.wait(until.visibilityOf(sidenavView.navSectionFor('Administration'))); | ||
await sidenavView.clickNavLink(['Administration', 'Cluster Settings']); | ||
await clusterSettingsView.isLoaded(); | ||
expect(clusterSettingsView.heading.isDisplayed()).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { element, by, browser, $$ } from 'protractor'; | ||
import { waitForNone } from '../protractor.conf'; | ||
|
||
export const heading = element(by.cssContainingText('h1.co-m-pane__heading', 'Cluster Settings')); | ||
export const isLoaded = async() => await browser.wait(waitForNone($$('.co-m-loader'))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,38 @@ | ||
/* eslint-disable no-undef, no-unused-vars */ | ||
|
||
import { $ } from 'protractor'; | ||
import { $, browser, ExpectedConditions as until, by, element } from 'protractor'; | ||
import { appHost } from '../protractor.conf'; | ||
|
||
export const nameInput = $('#inputUsername'); | ||
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-dropdown__toggle'); | ||
|
||
export const selectProvider = async(provider: string) => { | ||
const idpLink = element(by.cssContainingText('.idp', provider)); | ||
while (!(await idpLink.isPresent())) { | ||
await browser.get(appHost); | ||
await browser.sleep(3000); | ||
} | ||
await idpLink.click(); | ||
}; | ||
|
||
export const login = async(providerName: string, username: string, password: string) => { | ||
if (providerName) { | ||
await selectProvider(providerName); | ||
} | ||
await browser.wait(until.visibilityOf(nameInput)); | ||
await nameInput.sendKeys(username); | ||
await passwordInput.sendKeys(password); | ||
await submitButton.click(); | ||
await browser.wait(until.presenceOf(userDropdown)); | ||
}; | ||
|
||
export const logout = async() => { | ||
await browser.wait(until.presenceOf(userDropdown)); | ||
await userDropdown.click(); | ||
await browser.wait(until.presenceOf(logOutLink)); | ||
await logOutLink.click(); | ||
await browser.wait(until.presenceOf($('.login-pf'))); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters