mirror of
https://github.com/GTFOBins/GTFOBins.github.io
synced 2024-12-25 06:19:27 +01:00
Add a simple YAML schema validation test
This commit is contained in:
parent
6bfc58daab
commit
7a3422666f
@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
install:
|
install:
|
||||||
- pip install --user yamllint
|
- pip install --user jsonschema yamllint
|
||||||
script:
|
script:
|
||||||
- make lint
|
- make lint
|
||||||
|
1
Makefile
1
Makefile
@ -11,3 +11,4 @@ bundle:
|
|||||||
|
|
||||||
lint:
|
lint:
|
||||||
yamllint . _gtfobins/*.md
|
yamllint . _gtfobins/*.md
|
||||||
|
scripts/validate-schema.py
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
title: GTFOBins
|
title: GTFOBins
|
||||||
|
|
||||||
exclude: ['/Gemfile', '/Makefile', '/README.md', '/CONTRIBUTING.md']
|
exclude: ['/scripts', '/Gemfile', '/Makefile', '/README.md', '/CONTRIBUTING.md']
|
||||||
|
|
||||||
permalink: pretty
|
permalink: pretty
|
||||||
|
|
||||||
|
60
scripts/validate-schema.py
Executable file
60
scripts/validate-schema.py
Executable file
@ -0,0 +1,60 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import jsonschema
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
def parse_yaml(path):
|
||||||
|
with open(path) as fs:
|
||||||
|
text = fs.read()
|
||||||
|
return yaml.load_all(text)
|
||||||
|
|
||||||
|
def build_schema():
|
||||||
|
function_names = next(parse_yaml('_data/functions.yml')).keys()
|
||||||
|
return {
|
||||||
|
"definitions": {
|
||||||
|
'examples': {
|
||||||
|
'type': 'array',
|
||||||
|
'items': {
|
||||||
|
'type': 'object',
|
||||||
|
'properties': {
|
||||||
|
'description': {'type': 'string'},
|
||||||
|
'code': {'type': 'string'}
|
||||||
|
},
|
||||||
|
'required': ['code'],
|
||||||
|
'additionalProperties': False
|
||||||
|
},
|
||||||
|
'minimum': 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'type': 'object',
|
||||||
|
'properties': {
|
||||||
|
'description': {'type': 'string'},
|
||||||
|
'functions': {
|
||||||
|
'type': 'object',
|
||||||
|
"patternProperties": {
|
||||||
|
'|'.join(function_names): {'$ref': '#/definitions/examples'}
|
||||||
|
},
|
||||||
|
'additionalProperties': False
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'required': ['functions'],
|
||||||
|
'additionalProperties': False
|
||||||
|
}
|
||||||
|
|
||||||
|
def validate_directory(root):
|
||||||
|
schema = build_schema()
|
||||||
|
root, _, files = next(os.walk(root))
|
||||||
|
for name in files:
|
||||||
|
if not name.endswith('.md'):
|
||||||
|
continue
|
||||||
|
path = os.path.join(root, name)
|
||||||
|
data = parse_yaml(path)
|
||||||
|
try:
|
||||||
|
jsonschema.validate(next(data), schema)
|
||||||
|
except jsonschema.exceptions.ValidationError as err:
|
||||||
|
print('{}: {}'.format(name, err))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
validate_directory("_gtfobins/")
|
Loading…
Reference in New Issue
Block a user