Skip to content

Commit

Permalink
Fixes integrationtests
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
  • Loading branch information
DarshitChanpura committed Mar 12, 2024
1 parent f331377 commit 63abb41
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
5 changes: 4 additions & 1 deletion server/auth/types/authentication_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ export abstract class AuthenticationType implements IAuthenticationType {
let authInfo: any | undefined;

// Adds a basic auth credentials headers to requests originated as anonymous user
if (this.config.auth.anonymous_auth_enabled) {
if (
this.config.auth.anonymous_auth_enabled &&
!request.headers.hasOwnProperty('authorization')
) {
const anonymousAuthHeaders = { authorization: ANONYMOUS_AUTH_HEADER };
Object.assign(authHeaders, anonymousAuthHeaders);
}
Expand Down
5 changes: 0 additions & 5 deletions test/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,9 @@
* permissions and limitations under the License.
*/

import { version, opensearchDashboards } from '../package.json';

export const OPENSEARCH_DASHBOARDS_SERVER_USER: string = 'kibanaserver';
export const OPENSEARCH_DASHBOARDS_SERVER_PASSWORD: string = 'kibanaserver';

export const ELASTICSEARCH_VERSION: string = opensearchDashboards.version;
export const SECURITY_ES_PLUGIN_VERSION: string = version;

export const ADMIN_USER: string = 'admin';
export const ADMIN_PASSWORD: string = 'admin';
const ADMIN_USER_PASS: string = `${ADMIN_USER}:${ADMIN_PASSWORD}`;
Expand Down
18 changes: 5 additions & 13 deletions test/jest_integration/basic_auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
} from '../constant';
import { getAuthCookie, extractAuthCookie } from '../helper/cookie';
import wreck from '@hapi/wreck';
import { ANONYMOUS_AUTH_HEADER } from '../../common';

describe('start OpenSearch Dashboards server', () => {
let root: Root;
Expand Down Expand Up @@ -226,16 +227,11 @@ describe('start OpenSearch Dashboards server', () => {
.unset(AUTHORIZATION_HEADER_NAME);

expect(response.status).toEqual(302);
expect(response.header.location).toEqual('/auth/anonymous?nextUrl=%2Fapp%2Fhome');
expect(response.header.location).toEqual('/app/login?nextUrl=%2Fapp%2Fhome');

const response2 = await osdTestServer.request.get(root, response.header.location);

expect(response2.status).toEqual(302);
expect(response2.header.location).toEqual('/app/login?nextUrl=%2Fapp%2Fhome');

const response3 = await osdTestServer.request.get(root, response2.header.location);

expect(response3.status).toEqual(200);
expect(response2.status).toEqual(200);
});

it('redirect for home follows login for anonymous auth disabled', async () => {
Expand Down Expand Up @@ -264,14 +260,10 @@ describe('start OpenSearch Dashboards server', () => {
.unset(AUTHORIZATION_HEADER_NAME);

expect(response.status).toEqual(302);
expect(response.header.location).toEqual(expectedPath);

const response2 = await osdTestServer.request.get(root, response.header.location);

expect(response2.status).toEqual(302);
expect(response2.header.location).toEqual(expectedPath);

const response3 = await osdTestServer.request.get(root, response2.header.location);

expect(response3.status).toEqual(200);
expect(response2.status).toEqual(200);
});
});

0 comments on commit 63abb41

Please sign in to comment.