-
Notifications
You must be signed in to change notification settings - Fork 27
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
Showing
3 changed files
with
52 additions
and
2 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
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const test = require('node:test'); | ||
const assert = require('node:assert'); | ||
const salvation = require('../../../target/javascript/salvation-v3.0.1.min.js'); | ||
|
||
test('salvation initialization', () => { | ||
assert.notStrictEqual(salvation.main, undefined); | ||
try { | ||
salvation.main(); | ||
assert.notStrictEqual(getErrorsForSerializedCSP, undefined); | ||
assert.notStrictEqual(getErrorsForSerializedCSPList, undefined); | ||
} catch (e) { | ||
assert.fail('main function should not throw an exception', e.message); | ||
} | ||
}); | ||
|
||
test('.getErrorsForSerializedCSP() gives no errors for a valid CSP', () => { | ||
salvation.main(); | ||
const result = getErrorsForSerializedCSP('default-src \'none\';'); | ||
assert.strictEqual(result.length, 0, 'No errors should be found'); | ||
}); | ||
|
||
test('.getErrorsForSerializedCSP() provides feedback', () => { | ||
salvation.main(); | ||
const result = getErrorsForSerializedCSP('hello world'); | ||
assert.strictEqual(result, 'Warning at directive 0: Unrecognized directive hello'); | ||
}); | ||
|
||
test('.getErrorsForSerializedCSPList() gives no errors for a valid CSP', () => { | ||
salvation.main(); | ||
const result = getErrorsForSerializedCSPList('default-src \'none\',plugin-types image/png application/pdf; sandbox,style-src https: \'self\''); | ||
assert.strictEqual(result, ''); | ||
}); | ||
|
||
test('.getErrorsForSerializedCSPList() provides feedback', () => { | ||
salvation.main(); | ||
const result = getErrorsForSerializedCSPList('hello,foobar,script-src \'self\'; style-src \'self\''); | ||
assert.strictEqual(result, 'Warning at directive 0: Unrecognized directive hello\n' | ||
+ 'Warning at directive 0: Unrecognized directive foobar'); | ||
}); |