diff --git a/public/apps/login/login-page.tsx b/public/apps/login/login-page.tsx index 5a93afbe..ebd89bc8 100644 --- a/public/apps/login/login-page.tsx +++ b/public/apps/login/login-page.tsx @@ -237,7 +237,10 @@ export function LoginPage(props: LoginPageDeps) { ); } - if (authOpts.length > 1 && (!authOpts.includes(AuthType.PROXY) || authOpts.length !== 2)) { + if ( + authOpts.length > 1 && + (!authOpts.includes(AuthType.PROXY) || authOpts.length !== 2) + ) { formBody.push(); formBody.push(); formBody.push(); diff --git a/server/auth/types/multiple/multi_auth.ts b/server/auth/types/multiple/multi_auth.ts index 2851fa24..4b4f6483 100644 --- a/server/auth/types/multiple/multi_auth.ts +++ b/server/auth/types/multiple/multi_auth.ts @@ -29,7 +29,12 @@ import { AuthType, LOGIN_PAGE_URI } from '../../../../common'; import { composeNextUrlQueryParam } from '../../../utils/next_url'; import { MultiAuthRoutes } from './routes'; import { SecuritySessionCookie } from '../../../session/security_cookie'; -import { BasicAuthentication, OpenIdAuthentication, ProxyAuthentication, SamlAuthentication } from '../../types'; +import { + BasicAuthentication, + OpenIdAuthentication, + ProxyAuthentication, + SamlAuthentication, +} from '../../types'; export class MultipleAuthentication extends AuthenticationType { private authTypes: string | string[]; diff --git a/test/jest_integration/proxy_auth.test.ts b/test/jest_integration/proxy_auth.test.ts index 8772bac9..8315dfc7 100644 --- a/test/jest_integration/proxy_auth.test.ts +++ b/test/jest_integration/proxy_auth.test.ts @@ -24,6 +24,7 @@ import { PROXY_USER, PROXY_ROLE, PROXY_ADMIN_ROLE, + AUTHORIZATION_HEADER_NAME, } from '../constant'; describe('start OpenSearch Dashboards server', () => { @@ -74,27 +75,30 @@ describe('start OpenSearch Dashboards server', () => { it('can access home page with proxy header', async () => { const response = await osdTestServer.request - .get(root, 'app/home#/') + .get(root, '/api/status') + .unset(AUTHORIZATION_HEADER_NAME) .set(PROXY_USER, ADMIN_USER) .set(PROXY_ROLE, PROXY_ADMIN_ROLE); expect(response.status).toEqual(200); }); it('cannot access home page without proxy header', async () => { - const response = await osdTestServer.request.get(root, 'app/home#/'); + const response = await osdTestServer.request.get(root, '/api/status'); expect(response.status).toEqual(401); }); it('cannot access home page with partial proxy header', async () => { const response = await osdTestServer.request - .get(root, 'app/home#/') + .get(root, '/api/status') + .unset(AUTHORIZATION_HEADER_NAME) .set(PROXY_USER, ADMIN_USER); expect(response.status).toEqual(401); }); it('cannot access home page with partial proxy header2', async () => { const response = await osdTestServer.request - .get(root, 'app/home#/') + .get(root, '/api/status') + .unset(AUTHORIZATION_HEADER_NAME) .set(PROXY_ROLE, PROXY_ADMIN_ROLE); expect(response.status).toEqual(401); }); diff --git a/test/jest_integration/proxy_multiauth.test.ts b/test/jest_integration/proxy_multiauth.test.ts index 97e9f8bb..125055f3 100644 --- a/test/jest_integration/proxy_multiauth.test.ts +++ b/test/jest_integration/proxy_multiauth.test.ts @@ -16,26 +16,20 @@ import * as osdTestServer from '../../../../src/core/test_helpers/osd_server'; import { Root } from '../../../../src/core/server/root'; import { resolve } from 'path'; -import { describe, expect, it, beforeAll, afterAll } from '@jest/globals'; +import { describe, it, beforeAll, afterAll } from '@jest/globals'; import { ADMIN_CREDENTIALS, OPENSEARCH_DASHBOARDS_SERVER_USER, - OPENSEARCH_DASHBOARDS_SERVER_PASSWORD, ADMIN_USER, PROXY_ADMIN_ROLE, + OPENSEARCH_DASHBOARDS_SERVER_PASSWORD, + ADMIN_USER, + PROXY_ADMIN_ROLE, } from '../constant'; import wreck from '@hapi/wreck'; -import { Builder, By, until } from 'selenium-webdriver'; -import { Options } from 'selenium-webdriver/firefox'; describe('start OpenSearch Dashboards server', () => { let root: Root; let config; - // XPath Constants - const signInBtnXPath = '//*[@id="btn-sign-in"]'; - // Browser Settings - const browser = 'firefox'; - const options = new Options().headless(); - beforeAll(async () => { root = osdTestServer.createRootWithSettings( { @@ -212,60 +206,4 @@ describe('start OpenSearch Dashboards server', () => { Promise.resolve(value); }); }); - it('Login to Dashboards and resume from nextUrl', async () => { - const urlWithHash = `http://localhost:5601/app/security-dashboards-plugin#/getstarted`; - const loginUrlWithNextUrl = `http://localhost:5601/app/login?nextUrl=%2Fapp%2Fsecurity-dashboards-plugin#/getstarted`; - const driver = getDriver(browser, options).build(); - await driver.manage().deleteAllCookies(); - await driver.get(loginUrlWithNextUrl); - await driver.wait(until.elementsLocated(By.xpath(signInBtnXPath)), 20000); - await driver.findElement(By.xpath(signInBtnXPath)).click(); - // TODO Use a better XPath. - await driver.wait( - until.elementsLocated(By.xpath('/html/body/div[1]/div/header/div/div[2]')), - 20000 - ); - const windowHash = await driver.getCurrentUrl(); - console.log('windowHash: ' + windowHash); - expect(windowHash).toEqual(urlWithHash); - const cookie = await driver.manage().getCookies(); - expect(cookie.length).toEqual(3); - await driver.manage().deleteAllCookies(); - await driver.quit(); - }); - - it('Login to Dashboards without nextUrl', async () => { - const urlWithoutHash = `http://localhost:5601/app/home#/`; - const loginUrl = `http://localhost:5601/app/login`; - const driver = getDriver(browser, options).build(); - await driver.manage().deleteAllCookies(); - await driver.get(loginUrl); - await driver.wait(until.elementsLocated(By.xpath(signInBtnXPath)), 20000); - await driver.findElement(By.xpath(signInBtnXPath)).click(); - // TODO Use a better XPath. - await driver.wait( - until.elementsLocated(By.xpath('/html/body/div[1]/div/header/div/div[2]')), - 20000 - ); - await driver.wait(until.elementsLocated(By.css('img[data-test-subj="defaultLogo"]')), 20000); - await driver.wait( - until.elementsLocated(By.css('section[aria-labelledby="homDataAdd__title"]')), - 20000 - ); - await driver.wait( - until.elementsLocated(By.css('section[aria-labelledby="homDataManage__title"]')), - 20000 - ); - const windowHash = await driver.getCurrentUrl(); - console.log('windowHash: ' + windowHash); - expect(windowHash).toEqual(urlWithoutHash); - const cookie = await driver.manage().getCookies(); - expect(cookie.length).toEqual(3); - await driver.manage().deleteAllCookies(); - await driver.quit(); - }); }); - -function getDriver(browser: string, options: Options) { - return new Builder().forBrowser(browser).setFirefoxOptions(options); -}