Skip to content

Commit

Permalink
Use KibanaRequest.from instead of as KibanaRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed Nov 30, 2020
1 parent 0609062 commit 5129ba6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
19 changes: 14 additions & 5 deletions x-pack/plugins/fleet/server/services/api_keys/security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { KibanaRequest, FakeRequest, SavedObjectsClientContract } from 'src/core/server';
import type { Request } from '@hapi/hapi';
import { KibanaRequest, SavedObjectsClientContract } from '../../../../../../src/core/server';
import { FleetAdminUserInvalidError, isLegacyESClientError } from '../../errors';
import { CallESAsCurrentUser } from '../../types';
import { appContextService } from '../app_context';
Expand All @@ -19,13 +20,17 @@ export async function createAPIKey(
if (!adminUser) {
throw new Error('No admin user configured');
}
const request: FakeRequest = {
const request = KibanaRequest.from(({
path: '/',
route: { settings: {} },
url: { href: '/' },
raw: { req: { url: '/' } },
headers: {
authorization: `Basic ${Buffer.from(`${adminUser.username}:${adminUser.password}`).toString(
'base64'
)}`,
},
};
} as unknown) as Request);
const security = appContextService.getSecurity();
if (!security) {
throw new Error('Missing security plugin');
Expand Down Expand Up @@ -64,13 +69,17 @@ export async function invalidateAPIKey(soClient: SavedObjectsClientContract, id:
if (!adminUser) {
throw new Error('No admin user configured');
}
const request: FakeRequest = {
const request = KibanaRequest.from(({
path: '/',
route: { settings: {} },
url: { href: '/' },
raw: { req: { url: '/' } },
headers: {
authorization: `Basic ${Buffer.from(`${adminUser.username}:${adminUser.password}`).toString(
'base64'
)}`,
},
};
} as unknown) as Request);

const security = appContextService.getSecurity();
if (!security) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ export default function (providerContext: FtrProviderContext) {
policy_id: 'policy1',
})
.expect(400);

expect(res.body.message).match(/Fleet Admin user is Invalid/);
expect(res.body.message).match(/Fleet Admin user is invalid/);
});
});
});
Expand Down

0 comments on commit 5129ba6

Please sign in to comment.