diff --git a/npm/ng-packs/packages/core/src/lib/strategies/content-security.strategy.ts b/npm/ng-packs/packages/core/src/lib/strategies/content-security.strategy.ts index 54016b5836..2875916ef2 100644 --- a/npm/ng-packs/packages/core/src/lib/strategies/content-security.strategy.ts +++ b/npm/ng-packs/packages/core/src/lib/strategies/content-security.strategy.ts @@ -4,7 +4,7 @@ export abstract class ContentSecurityStrategy { abstract applyCSP(element: HTMLScriptElement | HTMLStyleElement): void; } -export class StrictContentSecurityStrategy extends ContentSecurityStrategy { +export class LooseContentSecurityStrategy extends ContentSecurityStrategy { constructor(nonce: string) { super(nonce); } @@ -14,7 +14,7 @@ export class StrictContentSecurityStrategy extends ContentSecurityStrategy { } } -export class LooseContentSecurityStrategy extends ContentSecurityStrategy { +export class StrictContentSecurityStrategy extends ContentSecurityStrategy { constructor() { super(); } @@ -23,10 +23,10 @@ export class LooseContentSecurityStrategy extends ContentSecurityStrategy { } export const CONTENT_SECURITY_STRATEGY = { - Loose() { - return new LooseContentSecurityStrategy(); + Loose(nonce: string) { + return new LooseContentSecurityStrategy(nonce); }, - Strict(nonce: string) { - return new StrictContentSecurityStrategy(nonce); + Strict() { + return new StrictContentSecurityStrategy(); }, }; diff --git a/npm/ng-packs/packages/core/src/lib/tests/content-security.strategy.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/content-security.strategy.spec.ts index 06db799ca0..c617e35893 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/content-security.strategy.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/content-security.strategy.spec.ts @@ -7,25 +7,25 @@ import { uuid } from '../utils'; describe('LooseContentSecurityStrategy', () => { describe('#applyCSP', () => { - it('should not set nonce attribute', () => { - const strategy = new LooseContentSecurityStrategy(); + it('should set nonce attribute', () => { + const nonce = uuid(); + const strategy = new LooseContentSecurityStrategy(nonce); const element = document.createElement('link'); strategy.applyCSP(element); - expect(element.getAttribute('nonce')).toBeNull(); + expect(element.getAttribute('nonce')).toBe(nonce); }); }); }); describe('StrictContentSecurityStrategy', () => { describe('#applyCSP', () => { - it('should set nonce attribute', () => { - const nonce = uuid(); - const strategy = new StrictContentSecurityStrategy(nonce); + it('should not set nonce attribute', () => { + const strategy = new StrictContentSecurityStrategy(); const element = document.createElement('link'); strategy.applyCSP(element); - expect(element.getAttribute('nonce')).toBe(nonce); + expect(element.getAttribute('nonce')).toBeNull(); }); }); }); @@ -33,8 +33,8 @@ describe('StrictContentSecurityStrategy', () => { describe('CONTENT_SECURITY_STRATEGY', () => { test.each` name | Strategy | nonce - ${'Loose'} | ${LooseContentSecurityStrategy} | ${undefined} - ${'Strict'} | ${StrictContentSecurityStrategy} | ${uuid()} + ${'Loose'} | ${LooseContentSecurityStrategy} | ${uuid()} + ${'Strict'} | ${StrictContentSecurityStrategy} | ${undefined} `('should successfully map $name to $Strategy.name', ({ name, Strategy, nonce }) => { expect(CONTENT_SECURITY_STRATEGY[name](nonce)).toEqual(new Strategy(nonce)); });