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 Aug 7, 2024
1 parent 1d0afb2 commit 792b33c
Showing 1 changed file with 61 additions and 39 deletions.
100 changes: 61 additions & 39 deletions test/jest_integration/proxy_auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
OPENSEARCH_DASHBOARDS_SERVER_USER,
OPENSEARCH_DASHBOARDS_SERVER_PASSWORD,
ADMIN_USER,
PROXY_USER,
PROXY_ROLE,
PROXY_ADMIN_ROLE,
ADMIN_CREDENTIALS,
} from '../constant';
Expand Down Expand Up @@ -138,53 +140,73 @@ describe('start OpenSearch Dashboards server', () => {
});

it('can access home page with proxy header', async () => {
const response = await wreck.get(
'https://localhost:9200/_plugins/_security/api/securityconfig',
{
rejectUnauthorized: false,
headers: {
PROXY_USER: ADMIN_USER,
PROXY_ROLE: PROXY_ADMIN_ROLE,
},
}
);
expect(response.res.statusCode).toEqual(200);
try {
const response = await wreck.get(
'https://localhost:9200/_plugins/_security/api/securityconfig',
{
rejectUnauthorized: false,
headers: {
[PROXY_USER]: ADMIN_USER,
[PROXY_ROLE]: PROXY_ADMIN_ROLE,
},
}
);
expect(response.res.statusCode).toEqual(200);
} catch (error) {
console.error('Request failed:', error);
throw error;
}
});

it('cannot access home page without proxy header', async () => {
const response = await wreck.get(
'https://localhost:9200/_plugins/_security/api/securityconfig',
{
rejectUnauthorized: false,
headers: {},
}
);
expect(response.res.statusCode).toEqual(401);
try {
const response = await wreck.get(
'https://localhost:9200/_plugins/_security/api/securityconfig',
{
rejectUnauthorized: false,
headers: {},
}
);
expect(response.res.statusCode).toEqual(401);
} catch (error) {
console.error('Request failed:', error);
throw error;
}
});

it('cannot access home page with partial proxy header', async () => {
const response = await wreck.get(
'https://localhost:9200/_plugins/_security/api/securityconfig',
{
rejectUnauthorized: false,
headers: {
PROXY_USER: ADMIN_USER,
},
}
);
expect(response.res.statusCode).toEqual(401);
try {
const response = await wreck.get(
'https://localhost:9200/_plugins/_security/api/securityconfig',
{
rejectUnauthorized: false,
headers: {
[PROXY_USER]: ADMIN_USER,
},
}
);
expect(response.res.statusCode).toEqual(401);
} catch (error) {
console.error('Request failed:', error);
throw error;
}
});

it('cannot access home page with partial proxy header2', async () => {
const response = await wreck.get(
'https://localhost:9200/_plugins/_security/api/securityconfig',
{
rejectUnauthorized: false,
headers: {
PROXY_ROLE: PROXY_ADMIN_ROLE,
},
}
);
expect(response.res.statusCode).toEqual(401);
try {
const response = await wreck.get(
'https://localhost:9200/_plugins/_security/api/securityconfig',
{
rejectUnauthorized: false,
headers: {
[PROXY_ROLE]: PROXY_ADMIN_ROLE,
},
}
);
expect(response.res.statusCode).toEqual(401);
} catch (error) {
console.error('Request failed:', error);
throw error;
}
});
});

0 comments on commit 792b33c

Please sign in to comment.