From 6e59feceaad9268c6f86c4308b6cf8103d3b3bba Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Thu, 7 Nov 2024 12:02:13 -0400 Subject: [PATCH] Fix segmentation fault on describing objects failures in `test` Signed-off-by: Juan Cruz Viotti --- test/CMakeLists.txt | 1 + test/test/fail_additional_properties.sh | 44 +++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100755 test/test/fail_additional_properties.sh diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9da80194..0f1924d9 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -79,6 +79,7 @@ add_jsonschema_test_unix(metaschema/pass_single) add_jsonschema_test_unix(metaschema/pass_2020_12) # Test +add_jsonschema_test_unix(test/fail_additional_properties) add_jsonschema_test_unix(test/fail_true_single_resolve) add_jsonschema_test_unix(test/fail_true_single_resolve_verbose) add_jsonschema_test_unix(test/fail_false_single_resolve) diff --git a/test/test/fail_additional_properties.sh b/test/test/fail_additional_properties.sh new file mode 100755 index 00000000..e60fdf0a --- /dev/null +++ b/test/test/fail_additional_properties.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +set -o errexit +set -o nounset + +TMP="$(mktemp -d)" +clean() { rm -rf "$TMP"; } +trap clean EXIT + +cat << 'EOF' > "$TMP/schema.json" +{ + "id": "https://example.com", + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "additionalProperties": false, + "properties": { + "foo": true, + "bar": true + } +} +EOF + +cat << 'EOF' > "$TMP/test.json" +{ + "target": "https://example.com", + "tests": [ + { + "valid": false, + "data": { "fo": true } + } + ] +} +EOF + +"$1" test "$TMP/test.json" --resolve "$TMP/schema.json" 1> "$TMP/output.txt" 2>&1 \ + && CODE="$?" || CODE="$?" +test "$CODE" = "1" || exit 1 + +cat << EOF > "$TMP/expected.txt" +$(realpath "$TMP")/test.json: + 1/1 FAIL +EOF + +diff "$TMP/output.txt" "$TMP/expected.txt"