mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-06 00:07:44 +01:00
93da4a1217
## About the changes This fixes a bunch of openHandles from our tests I've used this script to find out the ones that leave them: `find src -name "*.test.ts" -printf "%f\n" | xargs -i sh -c "echo ===== {} && yarn test {}"` If there's an issue, the script will halt and the last filename will be the one that has to be fixed. Each commit fixes one problem so it's easy to review
51 lines
1.6 KiB
TypeScript
51 lines
1.6 KiB
TypeScript
import dbInit from './helpers/database-init';
|
|
import { setupAppWithCustomAuth } from './helpers/test-helper';
|
|
import { RoleName } from '../../lib/types';
|
|
|
|
let db;
|
|
let stores;
|
|
|
|
const preHook = (app, config, { userService, accessService }) => {
|
|
app.use('/api/admin/', async (req, res, next) => {
|
|
const role = await accessService.getRootRole(RoleName.EDITOR);
|
|
req.user = await userService.createUser({
|
|
email: 'editor2@example.com',
|
|
rootRole: role.id,
|
|
});
|
|
next();
|
|
});
|
|
};
|
|
|
|
beforeAll(async () => {
|
|
db = await dbInit('custom_auth_serial');
|
|
stores = db.stores;
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await db.destroy();
|
|
});
|
|
|
|
test('Using custom auth type without defining custom middleware causes default DENY ALL policy to take effect', async () => {
|
|
jest.spyOn(global.console, 'error').mockImplementation(() => jest.fn());
|
|
const { request, destroy } = await setupAppWithCustomAuth(
|
|
stores,
|
|
undefined,
|
|
);
|
|
await request
|
|
.get('/api/admin/features')
|
|
.expect(401)
|
|
.expect((res) => {
|
|
expect(res.body.error).toBe(
|
|
'You have to configure a custom authentication middleware. Read https://docs.getunleash.io/docs/reference/deploy/configuring-unleash for more details',
|
|
);
|
|
});
|
|
await destroy();
|
|
});
|
|
|
|
test('If actually configuring a custom middleware should configure the middleware', async () => {
|
|
expect.assertions(0);
|
|
const { request, destroy } = await setupAppWithCustomAuth(stores, preHook);
|
|
await request.get('/api/admin/features').expect(200);
|
|
await destroy();
|
|
});
|