Skip to content

Commit

Permalink
adapt integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Mar 10, 2021
1 parent 73fa489 commit ec79c02
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/core/server/http/integration_tests/router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,30 @@ describe('Options', () => {
});
});

it('User with invalid credentials cannot access a route', async () => {
const { server: innerServer, createRouter, registerAuth } = await server.setup(setupDeps);
it('User with invalid credentials can access a route', async () => {
const { server: innerServer, createRouter, registerAuth, auth } = await server.setup(
setupDeps
);
const router = createRouter('/');

registerAuth((req, res, toolkit) => res.unauthorized());

router.get(
{ path: '/', validate: false, options: { authRequired: 'optional' } },
(context, req, res) => res.ok({ body: 'ok' })
(context, req, res) =>
res.ok({
body: {
httpAuthIsAuthenticated: auth.isAuthenticated(req),
requestIsAuthenticated: req.auth.isAuthenticated,
},
})
);
await server.start();

await supertest(innerServer.listener).get('/').expect(401);
await supertest(innerServer.listener).get('/').expect(200, {
httpAuthIsAuthenticated: false,
requestIsAuthenticated: false,
});
});

it('does not redirect user and allows access to a resource', async () => {
Expand Down

0 comments on commit ec79c02

Please sign in to comment.