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

Commit

Permalink
mocha -> ava
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Kudinov committed Mar 20, 2017
1 parent 2093933 commit ccfb3b5
Show file tree
Hide file tree
Showing 3 changed files with 2,641 additions and 153 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Content-Security-Policy header generator",
"main": "index.js",
"scripts": {
"test": "mocha test"
"test": "ava"
},
"keywords": [
"csp",
Expand All @@ -18,8 +18,7 @@
"node": ">=4"
},
"devDependencies": {
"mocha": "^2.4.5",
"should": "^8.3.0"
"ava": "^0.18.2"
},
"directories": {
"test": "test"
Expand Down
125 changes: 63 additions & 62 deletions test/index.test.js
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'");
});
Loading

0 comments on commit ccfb3b5

Please sign in to comment.