mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Create getBasicAuthHeader util
This commit is contained in:
parent
f7a2caf38d
commit
fad6bde6af
2 changed files with 33 additions and 0 deletions
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { getBasicAuthHeader } from './get_basic_auth_header';
|
||||
|
||||
describe('getBasicAuthHeader', () => {
|
||||
it('constructs the basic auth header correctly', () => {
|
||||
expect(getBasicAuthHeader({ username: 'test', password: 'foo' })).toEqual({
|
||||
Authorization: `Basic ${Buffer.from('test:foo').toString('base64')}`,
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
interface GetBasicAuthHeaderArgs {
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export const getBasicAuthHeader = ({ username, password }: GetBasicAuthHeaderArgs) => {
|
||||
const header = `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`;
|
||||
|
||||
return { Authorization: header };
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue