|
|
|
@ -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)); |
|
|
|
}); |
|
|
|
|