2021-04-29 15:18:58 +02:00
|
|
|
import dbInit from './helpers/database-init';
|
|
|
|
import { setupAppWithCustomAuth } from './helpers/test-helper';
|
|
|
|
|
|
|
|
let db;
|
|
|
|
let stores;
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
beforeAll(async () => {
|
2021-04-29 15:18:58 +02:00
|
|
|
db = await dbInit('custom_auth_serial');
|
|
|
|
stores = db.stores;
|
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('Using custom auth type without defining custom middleware causes default DENY ALL policy to take effect', async () => {
|
2021-10-29 11:22:31 +02:00
|
|
|
jest.spyOn(global.console, 'error').mockImplementation(() => jest.fn());
|
2021-05-28 11:10:24 +02:00
|
|
|
const { request, destroy } = await setupAppWithCustomAuth(
|
|
|
|
stores,
|
|
|
|
undefined,
|
|
|
|
);
|
2021-04-29 15:18:58 +02:00
|
|
|
await request
|
|
|
|
.get('/api/admin/features')
|
|
|
|
.expect(401)
|
2021-08-12 15:04:37 +02:00
|
|
|
.expect((res) => {
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(res.body.error).toBe(
|
2021-04-29 15:18:58 +02:00
|
|
|
'You have to configure a custom authentication middleware. Read https://docs.getunleash.io/docs/deploy/configuring_unleash for more details',
|
|
|
|
);
|
|
|
|
});
|
2021-05-28 11:10:24 +02:00
|
|
|
await destroy();
|
2021-04-29 15:18:58 +02:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('If actually configuring a custom middleware should configure the middleware', async () => {
|
|
|
|
expect.assertions(0);
|
|
|
|
const { request, destroy } = await setupAppWithCustomAuth(stores, () => {});
|
|
|
|
await request.get('/api/admin/features').expect(200);
|
|
|
|
await destroy();
|
2021-04-29 15:18:58 +02:00
|
|
|
});
|