Made infrastructure to ensure private data is not leaked to client

This commit is contained in:
2023-08-11 13:52:10 +02:00
parent 8660345bf6
commit 22545e46bb
7 changed files with 232 additions and 29 deletions

58
src/lib/config.test.ts Normal file
View File

@@ -0,0 +1,58 @@
import { describe, expect, it } from 'vitest';
import { config, defaultConfig, mergeConfig, type Config, stripPrivateFields } from './config';
describe('Config', () => {
it('should be export a build time config', () => {
expect(config).toBeTruthy();
});
it('should be able to merge with POJO', () => {
const merged = mergeConfig(defaultConfig, {
subtitle: "Homer's favorite neighboor",
services: [
{
title: 'favorite occupations',
items: [
{
title: 'anoy homer',
customKey: 'all the time'
}
]
}
]
});
expect(merged.title).toEqual('Flanders');
expect(merged.services).toHaveLength(1);
expect(merged.services[0].title).toEqual('favorite occupations');
expect(merged.services[0].items).toHaveLength(1);
expect(merged.services[0].items[0].title).toEqual('anoy homer');
expect(merged.services[0].items[0].customKey).toEqual('all the time');
});
it('should be able to strip custom keys', () => {
const custom: Config = {
title: 'custom',
secret: {secret: 'some secret'},
services: [
{
title: 'top services',
secret: 'secret',
items: [
{
title: 'top service',
url: 'somewhere',
secret: 'secret'
}
]
}
]
};
const stripped: Config = stripPrivateFields(custom);
expect(stripped.secret).toBeUndefined();
expect(stripped.services[0].secret).toBeUndefined();
expect(stripped.services[0].items[0].secret).toBeUndefined();
});
});