-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I pulled in [ajv](https://npm.im/ajv) for this. I had tried to use [z-schema](https://npm.im/z-schema) but I couldn't get it working quickly (apparently you need to supply the metaschema??) so abandoned it. If there's a more lightweight, _maintained_ solution, I'm happy to try it.
- Loading branch information
Showing
9 changed files
with
196 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,7 @@ | ||
{ | ||
"resolutions": { | ||
"some>package": { | ||
"some>other>package": "/etc/passwd" | ||
} | ||
} | ||
} |
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,9 @@ | ||
{ | ||
"resources": { | ||
"bad>!!packagename": { | ||
"globals": { | ||
"console": true | ||
} | ||
} | ||
} | ||
} |
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 @@ | ||
{} |
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,63 @@ | ||
{ | ||
"resources": { | ||
"browserify>buffer": { | ||
"globals": { | ||
"console": true | ||
}, | ||
"packages": { | ||
"browserify>buffer>base64-js": true, | ||
"browserify>buffer>ieee754": true | ||
} | ||
}, | ||
"browserify>events": { | ||
"globals": { | ||
"console": true | ||
} | ||
}, | ||
"browserify>process": { | ||
"globals": { | ||
"clearTimeout": true, | ||
"setTimeout": true | ||
} | ||
}, | ||
"browserify>string_decoder": { | ||
"packages": { | ||
"browserify>util>safe-buffer": true | ||
} | ||
}, | ||
"browserify>util>safe-buffer": { | ||
"packages": { | ||
"browserify>buffer": true | ||
} | ||
}, | ||
"keccak": { | ||
"packages": { | ||
"browserify>buffer": true, | ||
"keccak>readable-stream": true | ||
} | ||
}, | ||
"keccak>readable-stream": { | ||
"packages": { | ||
"browserify>browser-resolve": true, | ||
"browserify>buffer": true, | ||
"browserify>events": true, | ||
"browserify>inherits": true, | ||
"browserify>process": true, | ||
"browserify>string_decoder": true, | ||
"keccak>readable-stream>util-deprecate": true | ||
} | ||
}, | ||
"keccak>readable-stream>util-deprecate": { | ||
"globals": { | ||
"console.trace": true, | ||
"console.warn": true, | ||
"localStorage": true | ||
} | ||
} | ||
}, | ||
"resolutions": { | ||
"some>package": { | ||
"some>other>package": "./here" | ||
} | ||
} | ||
} |
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,29 @@ | ||
const test = require('ava') | ||
const Ajv = require('ajv') | ||
|
||
const schema = require('../schema/lavamoat-policy.v0-0-1.schema.json') | ||
const validPolicy = require('./policy/valid.json') | ||
const invalidPolicyEmpty = require('./policy/invalid-empty.json') | ||
const invalidBadPkgName = require('./policy/invalid-bad-pkg-name.json') | ||
const invalidBadPath = require('./policy/invalid-bad-path.json') | ||
|
||
const ajv = new Ajv({ allErrors: true }) | ||
const validate = ajv.compile(schema) | ||
test('policy schema - known good policy', (t) => { | ||
t.truthy(validate(validPolicy)) | ||
}) | ||
|
||
test('policy schema - invalid policy - empty', (t) => { | ||
t.falsy(validate(invalidPolicyEmpty)) | ||
t.snapshot(validate.errors) | ||
}) | ||
|
||
test('policy schema - invalid policy - bad pkg name', (t) => { | ||
t.falsy(validate(invalidBadPkgName)) | ||
t.snapshot(validate.errors) | ||
}) | ||
|
||
test('policy schema - invalid policy - bad resolution path', (t) => { | ||
t.falsy(validate(invalidBadPath)) | ||
t.snapshot(validate.errors) | ||
}) |
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,69 @@ | ||
# Snapshot report for `test/policySchema.spec.js` | ||
|
||
The actual snapshot is saved in `policySchema.spec.js.snap`. | ||
|
||
Generated by [AVA](https://avajs.dev). | ||
|
||
## policy schema - invalid policy - empty | ||
|
||
> Snapshot 1 | ||
[ | ||
{ | ||
dataPath: '', | ||
keyword: 'required', | ||
message: 'should have required property \'resources\'', | ||
params: { | ||
missingProperty: 'resources', | ||
}, | ||
schemaPath: '#/anyOf/0/required', | ||
}, | ||
{ | ||
dataPath: '', | ||
keyword: 'required', | ||
message: 'should have required property \'resolutions\'', | ||
params: { | ||
missingProperty: 'resolutions', | ||
}, | ||
schemaPath: '#/anyOf/1/required', | ||
}, | ||
{ | ||
dataPath: '', | ||
keyword: 'anyOf', | ||
message: 'should match some schema in anyOf', | ||
params: {}, | ||
schemaPath: '#/anyOf', | ||
}, | ||
] | ||
|
||
## policy schema - invalid policy - bad pkg name | ||
|
||
> Snapshot 1 | ||
[ | ||
{ | ||
dataPath: '.resources', | ||
keyword: 'additionalProperties', | ||
message: 'should NOT have additional properties', | ||
params: { | ||
additionalProperty: 'bad>!!packagename', | ||
}, | ||
schemaPath: '#/properties/resources/additionalProperties', | ||
}, | ||
] | ||
|
||
## policy schema - invalid policy - bad resolution path | ||
|
||
> Snapshot 1 | ||
[ | ||
{ | ||
dataPath: '.resolutions[\'some>package\'][\'some>other>package\']', | ||
keyword: 'pattern', | ||
message: 'should match pattern "^(\\.{1,2})(/(?=[^/\\0])[^/\\0]+)*/?$"', | ||
params: { | ||
pattern: '^(\\.{1,2})(/(?=[^/\\0])[^/\\0]+)*/?$', | ||
}, | ||
schemaPath: '#/properties/resolutions/patternProperties/%5E(%40%5Ba-z0-9-~0%5D%5Ba-z0-9-._~0%5D*~1)%3F%5Ba-z0-9-~0%5D%5Ba-z0-9-._~0%5D*(%3E(%40%5Ba-z0-9-~0%5D%5Ba-z0-9-._~0%5D*~1)%3F%5Ba-z0-9-~0%5D%5Ba-z0-9-._~0%5D*)*%24/patternProperties/%5E(%40%5Ba-z0-9-~0%5D%5Ba-z0-9-._~0%5D*~1)%3F%5Ba-z0-9-~0%5D%5Ba-z0-9-._~0%5D*(%3E(%40%5Ba-z0-9-~0%5D%5Ba-z0-9-._~0%5D*~1)%3F%5Ba-z0-9-~0%5D%5Ba-z0-9-._~0%5D*)*%24/pattern', | ||
}, | ||
] |
Binary file not shown.