From 1f2633c6f1c15942684468d0ecff36b241bed96c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Mon, 13 Feb 2017 11:15:51 +0100 Subject: [PATCH] Add testing, update travis --- .travis.yml | 21 ++++++++++----------- jq_all_the_things.sh | 13 +++++++++++++ schema.json | 30 ++++++++++++++++++++++++++++++ validate_all.sh | 21 +++++++++++++++++++++ 4 files changed, 74 insertions(+), 11 deletions(-) create mode 100755 jq_all_the_things.sh create mode 100644 schema.json create mode 100755 validate_all.sh diff --git a/.travis.yml b/.travis.yml index e3735b5..3c90269 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,16 @@ -language: bash +language: python + +cache: pip + +python: + - "3.6" sudo: required -dist: trusty - install: - - git clone https://github.com/stedolan/jq.git - - pushd jq - - autoreconf -i - - ./configure --disable-maintainer-mode - - make - - sudo make install - - popd + - sudo apt-get update -qq + - sudo apt-get install -y -qq jq + - pip install jsonschema script: - - cat */*/*.json | jq . + - ./validate_all.sh diff --git a/jq_all_the_things.sh b/jq_all_the_things.sh new file mode 100755 index 0000000..e2ed85c --- /dev/null +++ b/jq_all_the_things.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -e +set -x + +# Seeds sponge, from moreutils + +for dir in objects/*/list.json +do + cat ${dir} | jq . | sponge ${dir} +done + +cat schema.json | jq . | sponge schema.json diff --git a/schema.json b/schema.json new file mode 100644 index 0000000..999134e --- /dev/null +++ b/schema.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json-schema.org/schema#", + "title": "Validator for misp-objects", + "id": "https://www.github.com/MISP/misp-objects/schema.json", + "type": "object", + "properties": { + "meta-category": { + "type": "string" + }, + "name": { + "type": "string" + }, + "description": { + "type": "string" + }, + "version": { + "type": "integer" + }, + "attributes": { + "type": "object" + } + }, + "required": [ + "attributes", + "version", + "description", + "meta-category", + "name" + ] +} diff --git a/validate_all.sh b/validate_all.sh new file mode 100755 index 0000000..4c288a0 --- /dev/null +++ b/validate_all.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +set -e +set -x + +./jq_all_the_things.sh + +diffs=`git status --porcelain | wc -l` + +if ![ $diffs -eq 0 ]; then + echo "Please make sure you run ./jq_all_the_things.sh before commiting." + exit 1 +fi + +for dir in objects/*/list.json +do + echo -n "${dir}: " + jsonschema -i ${dir} schema.json + echo '' +done +