Skip to content
This repository has been archived by the owner on Mar 26, 2021. It is now read-only.

Commit

Permalink
presets can be object
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuan authored and Evgeniy Shershnev committed Oct 12, 2017
1 parent 4d9adc5 commit 6c0ec49
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ function csp(params) {
}, {});

if (params.presets) {
params.presets.forEach(preset => {
// Object.keys also works with array keys
Object.keys(params.presets).forEach(key => {
const preset = params.presets[key];
let presetPolicies;

if (typeof preset === 'string') {
Expand Down
10 changes: 10 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ test('Presets | extend', t => {
t.is(actual, 'script-src test.com; style-src test.com;');
});

test('Presets | object', t => {
const actual = csp({
presets: {
test: require('./fixtures/presets/csp-preset-test')
}
});

t.is(actual, 'script-src test.com; style-src test.com;');
});

test('Presets | resolve', t => {
t.is(csp.resolvePreset('csp-preset-test'), 'csp-preset-test');
t.is(csp.resolvePreset('test'), 'csp-preset-test');
Expand Down

0 comments on commit 6c0ec49

Please sign in to comment.