2022-04-06 08:11:41 +02:00
|
|
|
import { ALL } from '../types/models/api-token';
|
|
|
|
import { createApiToken } from './api-token-schema';
|
|
|
|
|
|
|
|
test('should reject token with projects and project', async () => {
|
|
|
|
expect.assertions(1);
|
|
|
|
try {
|
|
|
|
await createApiToken.validateAsync({
|
|
|
|
username: 'test',
|
|
|
|
type: 'admin',
|
|
|
|
project: 'default',
|
|
|
|
projects: ['default'],
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
expect(error.details[0].message).toEqual(
|
|
|
|
'"project" must not exist simultaneously with [projects]',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should not have default project set if projects is present', async () => {
|
|
|
|
let token = await createApiToken.validateAsync({
|
|
|
|
username: 'test',
|
|
|
|
type: 'admin',
|
|
|
|
projects: ['default'],
|
|
|
|
});
|
|
|
|
expect(token.project).not.toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should have project set to default if projects is missing', async () => {
|
|
|
|
let token = await createApiToken.validateAsync({
|
|
|
|
username: 'test',
|
|
|
|
type: 'admin',
|
|
|
|
});
|
|
|
|
expect(token.project).toBe(ALL);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should not have projects set if project is present', async () => {
|
|
|
|
let token = await createApiToken.validateAsync({
|
|
|
|
username: 'test',
|
|
|
|
type: 'admin',
|
|
|
|
project: 'default',
|
|
|
|
});
|
|
|
|
expect(token.projects).not.toBeDefined();
|
|
|
|
});
|
2022-08-17 10:55:52 +02:00
|
|
|
|
|
|
|
test('should set metadata', async () => {
|
|
|
|
let token = await createApiToken.validateAsync({
|
|
|
|
username: 'test',
|
|
|
|
type: 'admin',
|
|
|
|
project: 'default',
|
|
|
|
metadata: {
|
|
|
|
corsOrigins: ['*'],
|
|
|
|
alias: 'secret',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(token.projects).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
2022-08-18 10:20:51 +02:00
|
|
|
test('should allow for frontend key (embedded proxy)', async () => {
|
2022-08-17 10:55:52 +02:00
|
|
|
let token = await createApiToken.validateAsync({
|
|
|
|
username: 'test',
|
2022-08-18 10:20:51 +02:00
|
|
|
type: 'frontend',
|
2022-08-17 10:55:52 +02:00
|
|
|
project: 'default',
|
|
|
|
metadata: {
|
|
|
|
corsOrigins: ['*'],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(token.error).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
2022-08-18 10:20:51 +02:00
|
|
|
test('should set environment to default for frontend key', async () => {
|
2022-08-17 10:55:52 +02:00
|
|
|
let token = await createApiToken.validateAsync({
|
|
|
|
username: 'test',
|
2022-08-18 10:20:51 +02:00
|
|
|
type: 'frontend',
|
2022-08-17 10:55:52 +02:00
|
|
|
project: 'default',
|
|
|
|
metadata: {
|
|
|
|
corsOrigins: ['*'],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(token.environment).toEqual('default');
|
|
|
|
});
|