Skip to content

Commit

Permalink
Incorporate tests from #48696
Browse files Browse the repository at this point in the history
  • Loading branch information
John Schulz committed Oct 18, 2019
1 parent 478f80c commit ec8e21d
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,15 @@ export async function handleGetInfo(req: PackageRequest, extra: Extra) {
export const handleGetFile = async (req: Request, extra: Extra) => {
if (!req.url.path) throw new Error('path is required');
const filePath = req.url.path.replace(API_ROOT, '');
const response = await getFile(filePath);
const newResponse = extra.response(response.body);
// set the content type from the registry response
newResponse.header('Content-Type', response.headers.get('content-type') || '');
return newResponse;
const registryResponse = await getFile(filePath);
const epmResponse = extra.response(registryResponse.body);
const proxiedHeaders = ['Content-Type'];
proxiedHeaders.forEach(key => {
const value = registryResponse.headers.get(key);
if (value !== null) epmResponse.header(key, value);
});

return epmResponse;
};

export async function handleRequestInstall(req: InstallAssetRequest, extra: Extra) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const routes: ServerRoute[] = [
{
method: 'GET',
path: `${CommonRoutes.API_INFO_PATTERN}/{filePath*}`,
options: { tags: [`access:${PLUGIN.ID}`], json: { space: 2 } },
options: { tags: [`access:${PLUGIN.ID}`] },
handler: Packages.handleGetFile,
},
{
Expand Down
147 changes: 147 additions & 0 deletions x-pack/test/epm_api_integration/apis/file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import ServerMock from 'mock-http-server';
import { FtrProviderContext } from '../../api_integration/ftr_provider_context';

export default function({ getService }: FtrProviderContext) {
describe('package file', () => {
const server = new ServerMock({ host: 'localhost', port: 6666 });
beforeEach(() => {
server.start(() => {});
});
afterEach(() => {
server.stop(() => {});
});
it('fetches a .png screenshot image', async () => {
server.on({
method: 'GET',
path: '/package/auditd-2.0.4/img/screenshots/auditbeat-file-integrity-dashboard.png',
reply: {
headers: { 'content-type': 'image/png' },
},
});

const supertest = getService('supertest');
await supertest
.get('/api/epm/package/auditd-2.0.4/img/screenshots/auditbeat-file-integrity-dashboard.png')
.set('kbn-xsrf', 'xxx')
.expect('Content-Type', 'image/png')
.expect(200);
});

it('fetches an .svg icon image', async () => {
server.on({
method: 'GET',
path: '/package/auditd-2.0.4/img/icon.svg',
reply: {
headers: { 'content-type': 'image/svg' },
},
});

const supertest = getService('supertest');
await supertest
.get('/api/epm/package/auditd-2.0.4/img/icon.svg')
.set('kbn-xsrf', 'xxx')
.expect('Content-Type', 'image/svg');
});

it('fetches an auditbeat .conf rule file', async () => {
server.on({
method: 'GET',
path: '/package/auditd-2.0.4/auditbeat/rules/sample-rules-linux-32bit.conf',
});

const supertest = getService('supertest');
await supertest
.get('/api/epm/package/auditd-2.0.4/auditbeat/rules/sample-rules-linux-32bit.conf')
.set('kbn-xsrf', 'xxx')
.expect('Content-Type', 'application/json; charset=utf-8')
.expect(200);
});

it('fetches an auditbeat .yml config file', async () => {
server.on({
method: 'GET',
path: '/package/auditd-2.0.4/auditbeat/config/config.yml',
reply: {
headers: { 'content-type': 'text/yaml; charset=UTF-8' },
},
});

const supertest = getService('supertest');
await supertest
.get('/api/epm/package/auditd-2.0.4/auditbeat/config/config.yml')
.set('kbn-xsrf', 'xxx')
.expect('Content-Type', 'text/yaml; charset=UTF-8')
.expect(200);
});

it('fetches a .json kibana visualization file', async () => {
server.on({
method: 'GET',
path:
'/package/auditd-2.0.4/kibana/visualization/b21e0c70-c252-11e7-8692-232bd1143e8a-ecs.json',
});

const supertest = getService('supertest');
await supertest
.get(
'/api/epm/package/auditd-2.0.4/kibana/visualization/b21e0c70-c252-11e7-8692-232bd1143e8a-ecs.json'
)
.set('kbn-xsrf', 'xxx')
.expect('Content-Type', 'application/json; charset=utf-8')
.expect(200);
});

it('fetches a .json kibana dashboard file', async () => {
server.on({
method: 'GET',
path:
'/package/auditd-2.0.4/kibana/dashboard/7de391b0-c1ca-11e7-8995-936807a28b16-ecs.json',
});

const supertest = getService('supertest');
await supertest
.get(
'/api/epm/package/auditd-2.0.4/kibana/dashboard/7de391b0-c1ca-11e7-8995-936807a28b16-ecs.json'
)
.set('kbn-xsrf', 'xxx')
.expect('Content-Type', 'application/json; charset=utf-8')
.expect(200);
});

it('fetches an .json index pattern file', async () => {
server.on({
method: 'GET',
path: '/package/auditd-2.0.4/kibana/index-pattern/auditbeat-*.json',
});

const supertest = getService('supertest');
await supertest
.get('/api/epm/package/auditd-2.0.4/kibana/index-pattern/auditbeat-*.json')
.set('kbn-xsrf', 'xxx')
.expect('Content-Type', 'application/json; charset=utf-8')
.expect(200);
});

it('fetches a .json search file', async () => {
server.on({
method: 'GET',
path: '/package/auditd-2.0.4/kibana/search/0f10c430-c1c3-11e7-8995-936807a28b16-ecs.json',
});

const supertest = getService('supertest');
await supertest
.get(
'/api/epm/package/auditd-2.0.4/kibana/search/0f10c430-c1c3-11e7-8995-936807a28b16-ecs.json'
)
.set('kbn-xsrf', 'xxx')
.expect('Content-Type', 'application/json; charset=utf-8')
.expect(200);
});
});
}
61 changes: 0 additions & 61 deletions x-pack/test/epm_api_integration/apis/image.ts

This file was deleted.

2 changes: 1 addition & 1 deletion x-pack/test/epm_api_integration/apis/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export default function ({ loadTestFile }) {
describe('EPM Endpoints', function () {
this.tags('ciGroup7');
loadTestFile(require.resolve('./list'));
loadTestFile(require.resolve('./image'));
loadTestFile(require.resolve('./file'));
});
}

0 comments on commit ec8e21d

Please sign in to comment.