Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elena-shostak committed Jan 6, 2025
1 parent 9f12936 commit f0d69d6
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 29 deletions.
29 changes: 0 additions & 29 deletions src/core/packages/http/router-server-internal/src/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,35 +397,6 @@ describe('CoreKibanaRequest', () => {

expect(kibanaRequest.route.options.authRequired).toBe(true);
});
it('handles required authc: { enabled: false }', () => {
const request = hapiMocks.createRequest({
route: {
settings: {
app: {
security: { authc: { enabled: false } },
},
},
},
});
const kibanaRequest = CoreKibanaRequest.from(request);

expect(kibanaRequest.route.options.authRequired).toBe(false);
});

it(`handles required authc: { enabled: 'optional' }`, () => {
const request = hapiMocks.createRequest({
route: {
settings: {
app: {
security: { authc: { enabled: 'optional' } },
},
},
},
});
const kibanaRequest = CoreKibanaRequest.from(request);

expect(kibanaRequest.route.options.authRequired).toBe('optional');
});

it('handles required authz simple config', () => {
const security: RouteSecurity = {
Expand Down
69 changes: 69 additions & 0 deletions src/core/packages/http/server-internal/src/http_server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1777,3 +1777,72 @@ describe('configuration change', () => {
);
});
});

test('exposes authentication details of incoming request to a route handler', async () => {
const { registerRouter, registerAuth, server: innerServer } = await server.setup({ config$ });

const router = new Router('', logger, enhanceWithContext, routerOptions);
router.get(
{
path: '/',
validate: false,
security: {
authc: { enabled: false, reason: 'test' },
authz: { enabled: false, reason: 'test' },
},
},
(context, req, res) => res.ok({ body: req.route })
);
router.get(
{
path: '/foo',
validate: false,
security: {
authc: { enabled: 'optional' },
authz: { enabled: false, reason: 'test' },
},
},
(context, req, res) => res.ok({ body: req.route })
);
// mocking to have `authRegistered` filed set to true
registerAuth((req, res) => res.unauthorized());
registerRouter(router);

await server.start();
await supertest(innerServer.listener)
.get('/')
.expect(200, {
method: 'get',
path: '/',
routePath: '/',
options: {
authRequired: false,
xsrfRequired: false,
access: 'internal',
tags: [],
timeout: {},
security: {
authc: { enabled: false, reason: 'test' },
authz: { enabled: false, reason: 'test' },
},
},
});
await supertest(innerServer.listener)
.get('/foo')
.expect(200, {
method: 'get',
path: '/foo',
routePath: '/foo',
options: {
authRequired: 'optional',
xsrfRequired: false,
access: 'internal',
tags: [],
timeout: {},
security: {
authc: { enabled: 'optional' },
authz: { enabled: false, reason: 'test' },
},
},
});
});

0 comments on commit f0d69d6

Please sign in to comment.