Skip to content

Commit

Permalink
Fix security test types
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdover committed Oct 7, 2019
1 parent cc9e8f7 commit 2e6d826
Showing 1 changed file with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import { Legacy } from 'kibana';
import { kibanaTestUser } from '@kbn/test';
import { initSpacesOnRequestInterceptor } from './on_request_interceptor';
import {
HttpServiceSetup,
CoreSetup,
SavedObjectsLegacyService,
SavedObjectsErrorHelpers,
IBasePath,
IRouter,
} from '../../../../../../../src/core/server';
import {
elasticsearchServiceMock,
Expand Down Expand Up @@ -46,7 +47,7 @@ describe('onPostAuthInterceptor', () => {

afterEach(async () => await root.shutdown());

function initKbnServer(http: HttpServiceSetup, routes: 'legacy' | 'new-platform') {
function initKbnServer(router: IRouter, basePath: IBasePath, routes: 'legacy' | 'new-platform') {
const kbnServer = kbnTestServer.getKbnServer(root);

if (routes === 'legacy') {
Expand All @@ -55,52 +56,50 @@ describe('onPostAuthInterceptor', () => {
method: 'GET',
path: '/foo',
handler: (req: Legacy.Request, h: Legacy.ResponseToolkit) => {
return h.response({ path: req.path, basePath: http.basePath.get(req) });
return h.response({ path: req.path, basePath: basePath.get(req) });
},
},
{
method: 'GET',
path: '/app/kibana',
handler: (req: Legacy.Request, h: Legacy.ResponseToolkit) => {
return h.response({ path: req.path, basePath: http.basePath.get(req) });
return h.response({ path: req.path, basePath: basePath.get(req) });
},
},
{
method: 'GET',
path: '/app/app-1',
handler: (req: Legacy.Request, h: Legacy.ResponseToolkit) => {
return h.response({ path: req.path, basePath: http.basePath.get(req) });
return h.response({ path: req.path, basePath: basePath.get(req) });
},
},
{
method: 'GET',
path: '/app/app-2',
handler: (req: Legacy.Request, h: Legacy.ResponseToolkit) => {
return h.response({ path: req.path, basePath: http.basePath.get(req) });
return h.response({ path: req.path, basePath: basePath.get(req) });
},
},
{
method: 'GET',
path: '/api/test/foo',
handler: (req: Legacy.Request) => {
return { path: req.path, basePath: http.basePath.get(req) };
return { path: req.path, basePath: basePath.get(req) };
},
},
{
method: 'GET',
path: '/some/path/s/foo/bar',
handler: (req: Legacy.Request, h: Legacy.ResponseToolkit) => {
return h.response({ path: req.path, basePath: http.basePath.get(req) });
return h.response({ path: req.path, basePath: basePath.get(req) });
},
},
]);
}

if (routes === 'new-platform') {
const router = http.createRouter('/');

router.get({ path: '/api/np_test/foo', validate: false }, (context, req, h) => {
return h.ok({ body: { path: req.url.pathname, basePath: http.basePath.get(req) } });
return h.ok({ body: { path: req.url.pathname, basePath: basePath.get(req) } });
});
}
}
Expand Down Expand Up @@ -216,11 +215,13 @@ describe('onPostAuthInterceptor', () => {
spacesService,
});

initKbnServer(http, 'new-platform');
const router = http.createRouter('/');

initKbnServer(router, http.basePath, 'new-platform');

await root.start();

initKbnServer(http, 'legacy');
initKbnServer(router, http.basePath, 'legacy');

const response = await kbnTestServer.request.get(root, path);

Expand Down

0 comments on commit 2e6d826

Please sign in to comment.