|
1 |
| -import { getCSP, CSPDirectiveName, CSPHeaderParams, nonce, SELF } from '../src'; |
| 1 | +import {CSPDirectiveName, CSPHeaderParams, getCSP, nonce, NONE, SELF} from '../src'; |
2 | 2 |
|
3 | 3 | describe('CSP building', () => {
|
4 | 4 | test('should correctly make policy with the only rule', () => {
|
@@ -107,6 +107,32 @@ describe('Presets', () => {
|
107 | 107 | })).toBe('script-src domain1.com domain2.com;')
|
108 | 108 | });
|
109 | 109 |
|
| 110 | + test('should remove \'none\' directive when merging with well-defined directive', () => { |
| 111 | + expect(getCSP({ |
| 112 | + directives: { |
| 113 | + 'script-src': [ 'domain1.com' ] |
| 114 | + }, |
| 115 | + presets: [ |
| 116 | + { |
| 117 | + 'script-src': [ NONE ] |
| 118 | + } |
| 119 | + ] |
| 120 | + })).toBe('script-src domain1.com;') |
| 121 | + }); |
| 122 | + |
| 123 | + test('should remove \'none\' directive when merging with well-defined preset', () => { |
| 124 | + expect(getCSP({ |
| 125 | + directives: { |
| 126 | + 'script-src': [ NONE ] |
| 127 | + }, |
| 128 | + presets: [ |
| 129 | + { |
| 130 | + 'script-src': [ 'domain2.com' ] |
| 131 | + } |
| 132 | + ] |
| 133 | + })).toBe('script-src domain2.com;') |
| 134 | + }); |
| 135 | + |
110 | 136 | test('should work with empty policies', () => {
|
111 | 137 | expect(getCSP({
|
112 | 138 | directives: {},
|
@@ -206,6 +232,32 @@ describe('Presets', () => {
|
206 | 232 | })).toBe('script-src domain1.com domain2.com;')
|
207 | 233 | });
|
208 | 234 |
|
| 235 | + test('should remove \'none\' directive when merging with well-defined directive', () => { |
| 236 | + expect(getCSP({ |
| 237 | + directives: { |
| 238 | + 'script-src': [ 'domain1.com' ] |
| 239 | + }, |
| 240 | + presets: { |
| 241 | + myPreset: { |
| 242 | + 'script-src': [ NONE ] |
| 243 | + } |
| 244 | + } |
| 245 | + })).toBe('script-src domain1.com;') |
| 246 | + }); |
| 247 | + |
| 248 | + test('should remove \'none\' directive when merging with well-defined preset', () => { |
| 249 | + expect(getCSP({ |
| 250 | + directives: { |
| 251 | + 'script-src': [ NONE ] |
| 252 | + }, |
| 253 | + presets: { |
| 254 | + myPreset: { |
| 255 | + 'script-src': [ 'domain2.com' ] |
| 256 | + } |
| 257 | + } |
| 258 | + })).toBe('script-src domain2.com;') |
| 259 | + }); |
| 260 | + |
209 | 261 | test('should work with empty policies', () => {
|
210 | 262 | expect(getCSP({
|
211 | 263 | directives: {},
|
|
0 commit comments