Skip to content

Commit

Permalink
Merge branch 'master' of github.com:elastic/kibana into maps/ems_sugg…
Browse files Browse the repository at this point in the history
…est2
  • Loading branch information
thomasneirynck committed Jun 22, 2021
2 parents 4aeb1ae + 564807c commit 140a939
Show file tree
Hide file tree
Showing 45 changed files with 1,160 additions and 405 deletions.
6 changes: 6 additions & 0 deletions src/core/public/application/utils/get_app_info.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,18 @@ describe('getAppInfo', () => {

it('adds default deepLinks when needed', () => {
const app = createApp({
order: 3,
deepLinks: [
{
id: 'sub-id',
title: 'sub-title',
order: 2,
deepLinks: [
{
id: 'sub-sub-id',
title: 'sub-sub-title',
path: '/sub-sub',
order: 1,
keywords: ['sub sub'],
},
],
Expand All @@ -210,19 +213,22 @@ describe('getAppInfo', () => {
searchable: true,
appRoute: `/app/some-id`,
keywords: [],
order: 3,
deepLinks: [
{
id: 'sub-id',
title: 'sub-title',
navLinkStatus: AppNavLinkStatus.hidden,
searchable: true,
order: 2,
keywords: [],
deepLinks: [
{
id: 'sub-sub-id',
title: 'sub-sub-title',
navLinkStatus: AppNavLinkStatus.hidden,
searchable: true,
order: 1,
path: '/sub-sub',
keywords: ['sub sub'],
deepLinks: [],
Expand Down
4 changes: 1 addition & 3 deletions src/core/public/application/utils/get_app_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ function getDeepLinkInfos(deepLinks?: AppDeepLink[]): PublicAppDeepLinkInfo[] {
return deepLinks.map(
({ navLinkStatus = AppNavLinkStatus.default, ...rawDeepLink }): PublicAppDeepLinkInfo => {
return {
id: rawDeepLink.id,
title: rawDeepLink.title,
path: rawDeepLink.path,
...rawDeepLink,
keywords: rawDeepLink.keywords ?? [],
navLinkStatus:
navLinkStatus === AppNavLinkStatus.default ? AppNavLinkStatus.hidden : navLinkStatus,
Expand Down
127 changes: 123 additions & 4 deletions src/core/server/http/http_server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
*/

import { Server } from 'http';
import { readFileSync } from 'fs';
import { rmdir, mkdtemp, readFile, writeFile } from 'fs/promises';
import supertest from 'supertest';
import { omit } from 'lodash';
import { join } from 'path';

import { ByteSizeValue, schema } from '@kbn/config-schema';
import { HttpConfig } from './http_config';
Expand Down Expand Up @@ -47,9 +48,9 @@ const enhanceWithContext = (fn: (...args: any[]) => any) => fn.bind(null, {});
let certificate: string;
let key: string;

beforeAll(() => {
certificate = readFileSync(KBN_CERT_PATH, 'utf8');
key = readFileSync(KBN_KEY_PATH, 'utf8');
beforeAll(async () => {
certificate = await readFile(KBN_CERT_PATH, 'utf8');
key = await readFile(KBN_KEY_PATH, 'utf8');
});

beforeEach(() => {
Expand Down Expand Up @@ -1409,13 +1410,131 @@ describe('setup contract', () => {
});

describe('#registerStaticDir', () => {
const assetFolder = join(__dirname, 'integration_tests', 'fixtures', 'static');
let tempDir: string;

beforeAll(async () => {
tempDir = await mkdtemp('cache-test');
});

afterAll(async () => {
if (tempDir) {
await rmdir(tempDir, { recursive: true });
}
});

test('does not throw if called after stop', async () => {
const { registerStaticDir } = await server.setup(config);
await server.stop();
expect(() => {
registerStaticDir('/path1/{path*}', '/path/to/resource');
}).not.toThrow();
});

test('returns correct headers for static assets', async () => {
const { registerStaticDir, server: innerServer } = await server.setup(config);

registerStaticDir('/static/{path*}', assetFolder);

await server.start();
const response = await supertest(innerServer.listener)
.get('/static/some_json.json')
.expect(200);

expect(response.get('cache-control')).toEqual('must-revalidate');
expect(response.get('etag')).not.toBeUndefined();
});

test('returns compressed version if present', async () => {
const { registerStaticDir, server: innerServer } = await server.setup(config);

registerStaticDir('/static/{path*}', assetFolder);

await server.start();
const response = await supertest(innerServer.listener)
.get('/static/compression_available.json')
.set('accept-encoding', 'gzip')
.expect(200);

expect(response.get('cache-control')).toEqual('must-revalidate');
expect(response.get('etag')).not.toBeUndefined();
expect(response.get('content-encoding')).toEqual('gzip');
});

test('returns uncompressed version if compressed asset is not available', async () => {
const { registerStaticDir, server: innerServer } = await server.setup(config);

registerStaticDir('/static/{path*}', assetFolder);

await server.start();
const response = await supertest(innerServer.listener)
.get('/static/some_json.json')
.set('accept-encoding', 'gzip')
.expect(200);

expect(response.get('cache-control')).toEqual('must-revalidate');
expect(response.get('etag')).not.toBeUndefined();
expect(response.get('content-encoding')).toBeUndefined();
});

test('returns a 304 if etag value matches', async () => {
const { registerStaticDir, server: innerServer } = await server.setup(config);

registerStaticDir('/static/{path*}', assetFolder);

await server.start();
const response = await supertest(innerServer.listener)
.get('/static/some_json.json')
.expect(200);

const etag = response.get('etag');
expect(etag).not.toBeUndefined();

await supertest(innerServer.listener)
.get('/static/some_json.json')
.set('If-None-Match', etag)
.expect(304);
});

test('serves content if etag values does not match', async () => {
const { registerStaticDir, server: innerServer } = await server.setup(config);

registerStaticDir('/static/{path*}', assetFolder);

await server.start();

await supertest(innerServer.listener)
.get('/static/some_json.json')
.set('If-None-Match', `"definitely not a valid etag"`)
.expect(200);
});

test('dynamically updates depending on the content of the file', async () => {
const tempFile = join(tempDir, 'some_file.json');

const { registerStaticDir, server: innerServer } = await server.setup(config);
registerStaticDir('/static/{path*}', tempDir);

await server.start();

await supertest(innerServer.listener).get('/static/some_file.json').expect(404);

await writeFile(tempFile, `{ "over": 9000 }`);

let response = await supertest(innerServer.listener)
.get('/static/some_file.json')
.expect(200);

const etag1 = response.get('etag');

await writeFile(tempFile, `{ "over": 42 }`);

response = await supertest(innerServer.listener).get('/static/some_file.json').expect(200);

const etag2 = response.get('etag');

expect(etag1).not.toEqual(etag2);
});
});

describe('#registerOnPreRouting', () => {
Expand Down
8 changes: 7 additions & 1 deletion src/core/server/http/http_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,13 @@ export class HttpServer {
lookupCompressed: true,
},
},
options: { auth: false },
options: {
auth: false,
cache: {
privacy: 'public',
otherwise: 'must-revalidate',
},
},
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"hello": "dolly"
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"foo": "bar"
}
3 changes: 2 additions & 1 deletion src/dev/run_licenses_csv_report.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ run(
licenses: [
'Custom;https://www.redhat.com/licenses/EULA_Red_Hat_Universal_Base_Image_English_20190422.pdf',
],
sourceURL: 'https://oss-dependencies.elastic.co/redhat/ubi/ubi-minimal-8-source.tar.gz',
sourceURL:
'https://oss-dependencies.elastic.co/red-hat-universal-base-image-minimal/8/ubi-minimal-8-source.tar.gz',
}
);

Expand Down
Loading

0 comments on commit 140a939

Please sign in to comment.