mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-23 00:22:19 +01:00
Add test for api-token-middleware to not make database call when using PAT (#2110)
* Middleware first version * Middleware tests * Add tests * Finish middleware tests * Add type for request * Add flagresolver * Fix snapshot * Update flags and tests * Put it back as default * Update snapshot * Add middleware test
This commit is contained in:
parent
d79ace57ec
commit
d5f621f3b2
@ -58,6 +58,28 @@ test('should not add user if unknown token', async () => {
|
|||||||
expect(req.user).toBeFalsy();
|
expect(req.user).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should not make database query when provided PAT format', async () => {
|
||||||
|
const apiTokenService = {
|
||||||
|
getUserForToken: jest.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
|
const func = apiTokenMiddleware(config, { apiTokenService });
|
||||||
|
|
||||||
|
const cb = jest.fn();
|
||||||
|
|
||||||
|
const req = {
|
||||||
|
header: jest.fn().mockReturnValue('user:asdkjsdhg3'),
|
||||||
|
user: undefined,
|
||||||
|
};
|
||||||
|
|
||||||
|
await func(req, undefined, cb);
|
||||||
|
|
||||||
|
expect(apiTokenService.getUserForToken).not.toHaveBeenCalled();
|
||||||
|
expect(req.header).toHaveBeenCalled();
|
||||||
|
expect(cb).toHaveBeenCalled();
|
||||||
|
expect(req.user).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
test('should add user if known token', async () => {
|
test('should add user if known token', async () => {
|
||||||
const apiUser = new ApiUser({
|
const apiUser = new ApiUser({
|
||||||
username: 'default',
|
username: 'default',
|
||||||
|
Loading…
Reference in New Issue
Block a user