fix headers in Fleet

This commit is contained in:
Matt Apperson 2019-11-17 18:37:12 -05:00
parent 0831ef0b6d
commit 94470547ae
11 changed files with 29 additions and 16 deletions

View file

@ -51,7 +51,7 @@ export class ElasticsearchAdapter implements ElasticsearchAdapterType {
}
if (user.kind === 'authenticated') {
return await callWithRequest({ headers: user[internalAuthData] }, endpoint, params);
return await callWithRequest(user[internalAuthData], endpoint, params);
}
throw new Error('Elastic search call is not implemented for unauthenticated user');

View file

@ -43,7 +43,7 @@ export class HapiFrameworkAdapter {
return isAuthenticated
? {
kind: 'authenticated',
[internalAuthData]: request.headers,
[internalAuthData]: request,
}
: {
kind: 'unauthenticated',

View file

@ -39,9 +39,7 @@ export class SODatabaseAdapter implements SODatabaseAdapterType {
private getClient(user: FrameworkUser) {
if (user.kind === 'authenticated') {
return this.savedObject.getScopedSavedObjectsClient({
headers: user[internalAuthData],
});
return this.savedObject.getScopedSavedObjectsClient(user[internalAuthData]);
}
if (user.kind === 'internal') {

View file

@ -51,7 +51,7 @@ export class ApiKeyLib implements Interface<ApiKeyLibType> {
user: FrameworkUser
): Promise<EnrollmentApiKeyVerificationResponse> {
if (user.kind === 'authenticated') {
const apiKeyHeader = user[internalAuthData].authorization.split(' ')[1];
const apiKeyHeader = user[internalAuthData].headers.authorization.split(' ')[1];
const apiKey = Buffer.from(apiKeyHeader, 'base64')
.toString('utf8')
.split(':')[1];
@ -76,7 +76,7 @@ export class ApiKeyLib implements Interface<ApiKeyLibType> {
user: FrameworkUser<any>
): Promise<AccessApiKeyVerificationResponse> {
if (user.kind === 'authenticated') {
const apiKeyHeader = user[internalAuthData].authorization.split(' ')[1];
const apiKeyHeader = user[internalAuthData].headers.authorization.split(' ')[1];
const [apiKeyId, apiKey] = Buffer.from(apiKeyHeader, 'base64')
.toString('utf8')
.split(':');

View file

@ -23,9 +23,11 @@ function getUser(apiKey?: string, apiKeyId?: string) {
return ({
kind: 'authenticated',
[internalAuthData]: {
authorization: `ApiKey ${Buffer.from(`${apiKeyId || 'key_id'}:${apiKey}`).toString(
'base64'
)}`,
headers: {
authorization: `ApiKey ${Buffer.from(`${apiKeyId || 'key_id'}:${apiKey}`).toString(
'base64'
)}`,
},
},
} as unknown) as FrameworkUser;
}

View file

@ -20,7 +20,9 @@ function getUser(): FrameworkUser {
return ({
kind: 'authenticated',
[internalAuthData]: {
authorization: `Basic ${Buffer.from(`elastic:changeme`).toString('base64')}`,
headers: {
authorization: `Basic ${Buffer.from(`elastic:changeme`).toString('base64')}`,
},
},
} as unknown) as FrameworkUser;
}
@ -33,7 +35,9 @@ function getUserForApiKey(apiKey: { id: string; api_key: string }) {
return {
kind: 'authenticated',
[internalAuthData]: {
authorization: `ApiKey ${apiKeyToString(apiKey)}`,
headers: {
authorization: `ApiKey ${apiKeyToString(apiKey)}`,
},
},
} as FrameworkUser;
}

View file

@ -183,7 +183,7 @@ export class ApiKeyLib {
throw new Error('Error must provide an authenticated user');
}
const authorizationHeader = user[internalAuthData].authorization;
const authorizationHeader = user[internalAuthData].headers.authorization;
if (!authorizationHeader) {
throw new Error('Authorization header must be set');

View file

@ -60,6 +60,9 @@ export const mappings = {
name: {
type: 'keyword',
},
type: {
type: 'keyword',
},
api_key: {
type: 'binary',
},

View file

@ -22,7 +22,9 @@ describe('AgentsEventsRepository', () => {
return ({
kind: 'authenticated',
[internalAuthData]: {
authorization: `Basic ${Buffer.from(`elastic:changeme`).toString('base64')}`,
headers: {
authorization: `Basic ${Buffer.from(`elastic:changeme`).toString('base64')}`,
},
},
} as unknown) as FrameworkUser;
}

View file

@ -23,7 +23,9 @@ describe('AgentsRepository', () => {
return ({
kind: 'authenticated',
[internalAuthData]: {
authorization: `Basic ${Buffer.from(`elastic:changeme`).toString('base64')}`,
headers: {
authorization: `Basic ${Buffer.from(`elastic:changeme`).toString('base64')}`,
},
},
} as unknown) as FrameworkUser;
}

View file

@ -40,7 +40,9 @@ describe('Enrollment api key Repository', () => {
return ({
kind: 'authenticated',
[internalAuthData]: {
authorization: `Basic ${Buffer.from(`elastic:changeme`).toString('base64')}`,
headers: {
authorization: `Basic ${Buffer.from(`elastic:changeme`).toString('base64')}`,
},
},
} as unknown) as FrameworkUser;
}