This repository has been archived by the owner on Mar 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vladimir Kudinov
committed
Mar 20, 2017
1 parent
2093933
commit ccfb3b5
Showing
3 changed files
with
2,641 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,78 @@ | ||
const should = require('should'); | ||
const csp = require('../index'); | ||
import test from 'ava'; | ||
import csp from '../index'; | ||
|
||
describe('Input params', () => { | ||
it('should returns undefined if params was not specified', () => { | ||
should(csp()).be.type('undefined'); | ||
test('Empty args', t => { | ||
t.is(csp(), undefined); | ||
}); | ||
|
||
test('Empty policies', t => { | ||
const actual = csp({ | ||
nonce: true, | ||
foo: 'bar' | ||
}); | ||
t.is(actual, undefined); | ||
}); | ||
|
||
it('should returns undefined if policies property was not specified', () => { | ||
should(csp({ | ||
nonce: true, | ||
foo: 'bar' | ||
})).be.type('undefined'); | ||
test('Disallowed policies', t => { | ||
const actual = csp({ | ||
policies: { | ||
'script-src': [ 'test.com', csp.SELF ], | ||
'foo-bar-src': [ 'foo', 'bar' ] | ||
} | ||
}); | ||
const expected = "script-src test.com 'self';"; | ||
t.is(actual, expected); | ||
}); | ||
|
||
test('report-uri', t => { | ||
const actual = csp({ | ||
policies: { | ||
'script-src': [ csp.SELF ] | ||
}, | ||
'report-uri': 'https://test.com/cspreport' | ||
}) | ||
const expected = "script-src 'self'; report-uri https://test.com/cspreport;"; | ||
t.is(actual, expected); | ||
}); | ||
|
||
it('should ignore disallowed policies', () => { | ||
csp({ | ||
policies: { | ||
'script-src': [ 'test.com', csp.SELF ], | ||
'foo-bar-src': [ 'foo', 'bar' ] | ||
} | ||
}).should.be.equal('script-src test.com \'self\';'); | ||
test('Valueless directives', t => { | ||
const actualTrue = csp({ | ||
policies: { | ||
'script-src': ['test.com'], | ||
'block-all-mixed-content': true | ||
} | ||
}); | ||
|
||
it('should add report-uri param', () => { | ||
csp({ | ||
policies: { | ||
'script-src': [ csp.SELF ] | ||
}, | ||
'report-uri': 'https://test.com/cspreport' | ||
}).should.be.equal('script-src \'self\'; report-uri https://test.com/cspreport;'); | ||
const actualEmptyArray = csp({ | ||
policies: { | ||
'script-src': ['test.com'], | ||
'block-all-mixed-content': [] | ||
} | ||
}); | ||
|
||
it('should support valueless directives', () => { | ||
csp({ | ||
policies: { | ||
'script-src': [ 'test.com' ], | ||
'block-all-mixed-content': true | ||
} | ||
}).should.be.equal('script-src test.com; block-all-mixed-content;'); | ||
const actualEmptyString = csp({ | ||
policies: { | ||
'script-src': ['test.com'], | ||
'block-all-mixed-content': '' | ||
} | ||
}); | ||
|
||
csp({ | ||
policies: { | ||
'script-src': [ 'test.com' ], | ||
'block-all-mixed-content': [] | ||
} | ||
}).should.be.equal('script-src test.com; block-all-mixed-content;'); | ||
const expected = 'script-src test.com; block-all-mixed-content;'; | ||
|
||
csp({ | ||
policies: { | ||
'script-src': [ 'test.com' ], | ||
'block-all-mixed-content': '' | ||
} | ||
}).should.be.equal('script-src test.com; block-all-mixed-content;'); | ||
}); | ||
t.is(actualTrue, expected); | ||
t.is(actualEmptyArray, expected); | ||
t.is(actualEmptyString, expected); | ||
}); | ||
|
||
describe('Utils', () => { | ||
it('should build nonce param', () => { | ||
csp.nonce('vg3eer#E4gEbw34gwq3fgqGQWBWQh').should.be.equal('\'nonce-vg3eer#E4gEbw34gwq3fgqGQWBWQh\''); | ||
}); | ||
test('Nonce', t => { | ||
const actual = csp.nonce('vg3eer#E4gEbw34gwq3fgqGQWBWQh'); | ||
const expected = "'nonce-vg3eer#E4gEbw34gwq3fgqGQWBWQh'" | ||
t.is(actual, expected); | ||
}); | ||
|
||
describe('Constants', () => { | ||
it('should contains \'self\'', () => { | ||
csp.SELF.should.be.equal('\'self\''); | ||
}); | ||
it('should contains \'unsafe-inline\'', () => { | ||
csp.INLINE.should.be.equal('\'unsafe-inline\''); | ||
}); | ||
it('should contains \'unsafe-eval\'', () => { | ||
csp.EVAL.should.be.equal('\'unsafe-eval\''); | ||
}); | ||
it('should contains \'none\'', () => { | ||
csp.NONE.should.be.equal('\'none\''); | ||
}); | ||
}); | ||
test('Constants', t => { | ||
t.is(csp.SELF, "'self'"); | ||
t.is(csp.INLINE, "'unsafe-inline'"); | ||
t.is(csp.EVAL, "'unsafe-eval'"); | ||
t.is(csp.NONE, "'none'"); | ||
}); |
Oops, something went wrong.