Skip to content

Commit

Permalink
Add Proxy Auth to Multi Auth Options
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Crawford <[email protected]>
  • Loading branch information
stephen-crawford committed Jul 31, 2024
1 parent d6524a1 commit 16bd92c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 72 deletions.
5 changes: 4 additions & 1 deletion public/apps/login/login-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<EuiSpacer size="xs" />);
formBody.push(<EuiHorizontalRule size="full" margin="xl" />);
formBody.push(<EuiSpacer size="xs" />);
Expand Down
7 changes: 6 additions & 1 deletion server/auth/types/multiple/multi_auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down
12 changes: 8 additions & 4 deletions test/jest_integration/proxy_auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
PROXY_USER,
PROXY_ROLE,
PROXY_ADMIN_ROLE,
AUTHORIZATION_HEADER_NAME,
} from '../constant';

describe('start OpenSearch Dashboards server', () => {
Expand Down Expand Up @@ -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);
});
Expand Down
70 changes: 4 additions & 66 deletions test/jest_integration/proxy_multiauth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down Expand Up @@ -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);
}

0 comments on commit 16bd92c

Please sign in to comment.