Skip to content

Commit

Permalink
Merge branch 'master' into logs-unskip-highlighting-test
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Jul 8, 2020
2 parents 4a290b0 + 67be99d commit 6391ec3
Show file tree
Hide file tree
Showing 16 changed files with 1,468 additions and 198 deletions.
137 changes: 136 additions & 1 deletion src/core/server/http/integration_tests/lifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import supertest from 'supertest';
import request from 'request';
import { schema } from '@kbn/config-schema';

import { ensureRawRequest } from '../router';
import { HttpService } from '../http_service';
Expand Down Expand Up @@ -222,6 +223,39 @@ describe('OnPreAuth', () => {

await supertest(innerServer.listener).get('/').expect(200, { customField: 'undefined' });
});

it('has no access to request body', async () => {
const { registerOnPreAuth, server: innerServer, createRouter } = await server.setup(setupDeps);
const router = createRouter('/');
let requestBody = null;
registerOnPreAuth((req, res, t) => {
requestBody = req.body;
return t.next();
});

router.post(
{
path: '/',
validate: {
body: schema.object({
term: schema.string(),
}),
},
},
(context, req, res) => res.ok({ body: req.body.term })
);

await server.start();

await supertest(innerServer.listener)
.post('/')
.send({
term: 'foo',
})
.expect(200, 'foo');

expect(requestBody).toStrictEqual({});
});
});

describe('OnPostAuth', () => {
Expand Down Expand Up @@ -356,6 +390,39 @@ describe('OnPostAuth', () => {

await supertest(innerServer.listener).get('/').expect(200, { customField: 'undefined' });
});

it('has no access to request body', async () => {
const { registerOnPostAuth, server: innerServer, createRouter } = await server.setup(setupDeps);
const router = createRouter('/');
let requestBody = null;
registerOnPostAuth((req, res, t) => {
requestBody = req.body;
return t.next();
});

router.post(
{
path: '/',
validate: {
body: schema.object({
term: schema.string(),
}),
},
},
(context, req, res) => res.ok({ body: req.body.term })
);

await server.start();

await supertest(innerServer.listener)
.post('/')
.send({
term: 'foo',
})
.expect(200, 'foo');

expect(requestBody).toStrictEqual({});
});
});

describe('Auth', () => {
Expand Down Expand Up @@ -852,10 +919,43 @@ describe('Auth', () => {

await supertest(innerServer.listener).get('/').expect(200, { customField: 'undefined' });
});

it('has no access to request body', async () => {
const { registerAuth, server: innerServer, createRouter } = await server.setup(setupDeps);
const router = createRouter('/');
let requestBody = null;
registerAuth((req, res, t) => {
requestBody = req.body;
return t.authenticated({});
});

router.post(
{
path: '/',
validate: {
body: schema.object({
term: schema.string(),
}),
},
},
(context, req, res) => res.ok({ body: req.body.term })
);

await server.start();

await supertest(innerServer.listener)
.post('/')
.send({
term: 'foo',
})
.expect(200, 'foo');

expect(requestBody).toStrictEqual({});
});
});

describe('OnPreResponse', () => {
it('supports registering response inceptors', async () => {
it('supports registering response interceptors', async () => {
const { registerOnPreResponse, server: innerServer, createRouter } = await server.setup(
setupDeps
);
Expand Down Expand Up @@ -1001,4 +1101,39 @@ describe('OnPreResponse', () => {

await supertest(innerServer.listener).get('/').expect(200);
});

it('has no access to request body', async () => {
const { registerOnPreResponse, server: innerServer, createRouter } = await server.setup(
setupDeps
);
const router = createRouter('/');
let requestBody = null;
registerOnPreResponse((req, res, t) => {
requestBody = req.body;
return t.next();
});

router.post(
{
path: '/',
validate: {
body: schema.object({
term: schema.string(),
}),
},
},
(context, req, res) => res.ok({ body: req.body.term })
);

await server.start();

await supertest(innerServer.listener)
.post('/')
.send({
term: 'foo',
})
.expect(200, 'foo');

expect(requestBody).toStrictEqual({});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { Observable } from 'rxjs';
import { FilterManager } from './filter_manager';

export const createFilterManagerMock = () => {
const filterManager = ({
mergeIncomingFilters: jest.fn(),
handleStateUpdate: jest.fn(),
getFilters: jest.fn(),
getAppFilters: jest.fn(),
getGlobalFilters: jest.fn(),
getPartitionedFilters: jest.fn(),
getUpdates$: jest.fn(() => new Observable()),
getFetches$: jest.fn(() => new Observable()),
addFilters: jest.fn(),
setFilters: jest.fn(),
setGlobalFilters: jest.fn(),
setAppFilters: jest.fn(),
removeFilter: jest.fn(),
removeAll: jest.fn(),
} as unknown) as jest.Mocked<FilterManager>;

return filterManager;
};
5 changes: 3 additions & 2 deletions src/plugins/data/public/query/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
import { Observable } from 'rxjs';
import { QueryService, QuerySetup, QueryStart } from '.';
import { timefilterServiceMock } from './timefilter/timefilter_service.mock';
import { createFilterManagerMock } from './filter_manager/filter_manager.mock';

type QueryServiceClientContract = PublicMethodsOf<QueryService>;

const createSetupContractMock = () => {
const setupContract: jest.Mocked<QuerySetup> = {
filterManager: jest.fn() as any,
filterManager: createFilterManagerMock(),
timefilter: timefilterServiceMock.createSetupContract(),
state$: new Observable(),
};
Expand All @@ -36,7 +37,7 @@ const createSetupContractMock = () => {
const createStartContractMock = () => {
const startContract: jest.Mocked<QueryStart> = {
addToQueryLog: jest.fn(),
filterManager: jest.fn() as any,
filterManager: createFilterManagerMock(),
savedQueries: jest.fn() as any,
state$: new Observable(),
timefilter: timefilterServiceMock.createStartContract(),
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/server/ui_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ export function getUiSettings(): Record<string, UiSettingsParams<unknown>> {
}`,
type: 'json',
description: i18n.translate('data.advancedSettings.timepicker.refreshIntervalDefaultsText', {
defaultMessage: `The timefilter's default refresh interval`,
defaultMessage: `The timefilter's default refresh interval. The "value" needs to be specified in milliseconds.`,
}),
requiresPageReload: true,
schema: schema.object({
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/visualizations/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ const createStartContract = (): VisualizationsStart => ({
get: jest.fn(),
all: jest.fn(),
getAliases: jest.fn(),
savedVisualizationsLoader: {} as any,
savedVisualizationsLoader: {
get: jest.fn(),
} as any,
showNewVisModal: jest.fn(),
createVis: jest.fn(),
convertFromSerializedVis: jest.fn(),
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/visualize/public/application/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export type PureVisState = SavedVisState;

export interface VisualizeAppState {
filters: Filter[];
uiState: PersistedState;
uiState: Record<string, unknown>;
vis: PureVisState;
query: Query;
savedQuery?: string;
Expand Down
Loading

0 comments on commit 6391ec3

Please sign in to comment.