mirror of
https://github.com/immich-app/immich
synced 2026-08-22 13:13:05 +00:00
tests
This commit is contained in:
parent
de796491da
commit
91bd1ebe81
1 changed files with 33 additions and 1 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import { ImmichTelemetry } from 'src/enum';
|
||||
import { clearEnvCache, ConfigRepository } from 'src/repositories/config.repository';
|
||||
import { applyCspHashes, clearEnvCache, ConfigRepository } from 'src/repositories/config.repository';
|
||||
|
||||
const getEnv = () => {
|
||||
clearEnvCache();
|
||||
|
|
@ -325,3 +325,35 @@ describe('getEnv', () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('applyCspHashes', () => {
|
||||
const manifest = { 'script-src': [`'sha256-script'`], 'style-src': [`'sha256-style'`] };
|
||||
|
||||
it('should append the hashes of the inline content', () => {
|
||||
const directives = applyCspHashes({ 'script-src': [`'self'`], 'style-src': [`'self'`] }, manifest);
|
||||
|
||||
expect(directives).toEqual({
|
||||
'script-src': [`'self'`, `'sha256-script'`],
|
||||
'style-src': [`'self'`, `'sha256-style'`],
|
||||
});
|
||||
});
|
||||
|
||||
it('should skip a directive that allows unsafe-inline, which a hash would disable', () => {
|
||||
const directives = applyCspHashes({ 'script-src': [`'self'`, `'unsafe-inline'`] }, manifest);
|
||||
|
||||
expect(directives['script-src']).toEqual([`'self'`, `'unsafe-inline'`]);
|
||||
});
|
||||
|
||||
it('should skip a directive the policy does not declare', () => {
|
||||
const directives = applyCspHashes({ 'script-src': [`'self'`] }, manifest);
|
||||
|
||||
expect(directives).not.toHaveProperty('style-src');
|
||||
});
|
||||
|
||||
it('should not mutate the directives it is given', () => {
|
||||
const directives = { 'script-src': [`'self'`] };
|
||||
applyCspHashes(directives, manifest);
|
||||
|
||||
expect(directives).toEqual({ 'script-src': [`'self'`] });
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue