From 45436c6c10dcb29193f22ba53f3c163973dbe349 Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Tue, 10 Nov 2020 15:27:35 -0800 Subject: [PATCH 1/2] Add a test to demonstrate the invalidity of a naive infinite loop detection algorithm It seems silly, but this was an error I had in my own implementation until last week! :o --- .../optional/infinite-loop-detection.json | 36 +++++++++++++++++++ .../optional/infinite-loop-detection.json | 36 +++++++++++++++++++ .../optional/infinite-loop-detection.json | 36 +++++++++++++++++++ .../optional/infinite-loop-detection.json | 36 +++++++++++++++++++ .../optional/infinite-loop-detection.json | 36 +++++++++++++++++++ 5 files changed, 180 insertions(+) create mode 100644 tests/draft2019-09/optional/infinite-loop-detection.json create mode 100644 tests/draft3/optional/infinite-loop-detection.json create mode 100644 tests/draft4/optional/infinite-loop-detection.json create mode 100644 tests/draft6/optional/infinite-loop-detection.json create mode 100644 tests/draft7/optional/infinite-loop-detection.json diff --git a/tests/draft2019-09/optional/infinite-loop-detection.json b/tests/draft2019-09/optional/infinite-loop-detection.json new file mode 100644 index 00000000..9c3c3627 --- /dev/null +++ b/tests/draft2019-09/optional/infinite-loop-detection.json @@ -0,0 +1,36 @@ +[ + { + "description": "evaluating the same schema location against the same data location twice is not a sign of an infinite loop", + "schema": { + "$defs": { + "int": { "type": "integer" } + }, + "allOf": [ + { + "properties": { + "foo": { + "$ref": "#/$defs/int" + } + } + }, + { + "additionalProperties": { + "$ref": "#/$defs/int" + } + } + ] + }, + "tests": [ + { + "description": "passing case", + "data": { "foo": 1 }, + "valid": true + }, + { + "description": "failing case", + "data": { "foo": "a string" }, + "valid": false + } + ] + } +] diff --git a/tests/draft3/optional/infinite-loop-detection.json b/tests/draft3/optional/infinite-loop-detection.json new file mode 100644 index 00000000..0426a3ee --- /dev/null +++ b/tests/draft3/optional/infinite-loop-detection.json @@ -0,0 +1,36 @@ +[ + { + "description": "evaluating the same schema location against the same data location twice is not a sign of an infinite loop", + "schema": { + "definitions": { + "int": { "type": "integer" } + }, + "allOf": [ + { + "properties": { + "foo": { + "$ref": "#/definitions/int" + } + } + }, + { + "additionalProperties": { + "$ref": "#/defintions/int" + } + } + ] + }, + "tests": [ + { + "description": "passing case", + "data": { "foo": 1 }, + "valid": true + }, + { + "description": "failing case", + "data": { "foo": "a string" }, + "valid": false + } + ] + } +] diff --git a/tests/draft4/optional/infinite-loop-detection.json b/tests/draft4/optional/infinite-loop-detection.json new file mode 100644 index 00000000..0426a3ee --- /dev/null +++ b/tests/draft4/optional/infinite-loop-detection.json @@ -0,0 +1,36 @@ +[ + { + "description": "evaluating the same schema location against the same data location twice is not a sign of an infinite loop", + "schema": { + "definitions": { + "int": { "type": "integer" } + }, + "allOf": [ + { + "properties": { + "foo": { + "$ref": "#/definitions/int" + } + } + }, + { + "additionalProperties": { + "$ref": "#/defintions/int" + } + } + ] + }, + "tests": [ + { + "description": "passing case", + "data": { "foo": 1 }, + "valid": true + }, + { + "description": "failing case", + "data": { "foo": "a string" }, + "valid": false + } + ] + } +] diff --git a/tests/draft6/optional/infinite-loop-detection.json b/tests/draft6/optional/infinite-loop-detection.json new file mode 100644 index 00000000..0426a3ee --- /dev/null +++ b/tests/draft6/optional/infinite-loop-detection.json @@ -0,0 +1,36 @@ +[ + { + "description": "evaluating the same schema location against the same data location twice is not a sign of an infinite loop", + "schema": { + "definitions": { + "int": { "type": "integer" } + }, + "allOf": [ + { + "properties": { + "foo": { + "$ref": "#/definitions/int" + } + } + }, + { + "additionalProperties": { + "$ref": "#/defintions/int" + } + } + ] + }, + "tests": [ + { + "description": "passing case", + "data": { "foo": 1 }, + "valid": true + }, + { + "description": "failing case", + "data": { "foo": "a string" }, + "valid": false + } + ] + } +] diff --git a/tests/draft7/optional/infinite-loop-detection.json b/tests/draft7/optional/infinite-loop-detection.json new file mode 100644 index 00000000..0426a3ee --- /dev/null +++ b/tests/draft7/optional/infinite-loop-detection.json @@ -0,0 +1,36 @@ +[ + { + "description": "evaluating the same schema location against the same data location twice is not a sign of an infinite loop", + "schema": { + "definitions": { + "int": { "type": "integer" } + }, + "allOf": [ + { + "properties": { + "foo": { + "$ref": "#/definitions/int" + } + } + }, + { + "additionalProperties": { + "$ref": "#/defintions/int" + } + } + ] + }, + "tests": [ + { + "description": "passing case", + "data": { "foo": 1 }, + "valid": true + }, + { + "description": "failing case", + "data": { "foo": "a string" }, + "valid": false + } + ] + } +] From 371fcabadefe5b06373b30679af3199fb244b309 Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Tue, 10 Nov 2020 15:27:35 -0800 Subject: [PATCH 2/2] Add a test to demonstrate the invalidity of a naive infinite loop detection algorithm It seems silly, but this was an error I had in my own implementation until last week! :o --- .../draft2019-09/infinite-loop-detection.json | 36 +++++++++++++++++++ tests/draft3/infinite-loop-detection.json | 36 +++++++++++++++++++ tests/draft4/infinite-loop-detection.json | 36 +++++++++++++++++++ tests/draft6/infinite-loop-detection.json | 36 +++++++++++++++++++ tests/draft7/infinite-loop-detection.json | 36 +++++++++++++++++++ 5 files changed, 180 insertions(+) create mode 100644 tests/draft2019-09/infinite-loop-detection.json create mode 100644 tests/draft3/infinite-loop-detection.json create mode 100644 tests/draft4/infinite-loop-detection.json create mode 100644 tests/draft6/infinite-loop-detection.json create mode 100644 tests/draft7/infinite-loop-detection.json diff --git a/tests/draft2019-09/infinite-loop-detection.json b/tests/draft2019-09/infinite-loop-detection.json new file mode 100644 index 00000000..9c3c3627 --- /dev/null +++ b/tests/draft2019-09/infinite-loop-detection.json @@ -0,0 +1,36 @@ +[ + { + "description": "evaluating the same schema location against the same data location twice is not a sign of an infinite loop", + "schema": { + "$defs": { + "int": { "type": "integer" } + }, + "allOf": [ + { + "properties": { + "foo": { + "$ref": "#/$defs/int" + } + } + }, + { + "additionalProperties": { + "$ref": "#/$defs/int" + } + } + ] + }, + "tests": [ + { + "description": "passing case", + "data": { "foo": 1 }, + "valid": true + }, + { + "description": "failing case", + "data": { "foo": "a string" }, + "valid": false + } + ] + } +] diff --git a/tests/draft3/infinite-loop-detection.json b/tests/draft3/infinite-loop-detection.json new file mode 100644 index 00000000..0426a3ee --- /dev/null +++ b/tests/draft3/infinite-loop-detection.json @@ -0,0 +1,36 @@ +[ + { + "description": "evaluating the same schema location against the same data location twice is not a sign of an infinite loop", + "schema": { + "definitions": { + "int": { "type": "integer" } + }, + "allOf": [ + { + "properties": { + "foo": { + "$ref": "#/definitions/int" + } + } + }, + { + "additionalProperties": { + "$ref": "#/defintions/int" + } + } + ] + }, + "tests": [ + { + "description": "passing case", + "data": { "foo": 1 }, + "valid": true + }, + { + "description": "failing case", + "data": { "foo": "a string" }, + "valid": false + } + ] + } +] diff --git a/tests/draft4/infinite-loop-detection.json b/tests/draft4/infinite-loop-detection.json new file mode 100644 index 00000000..0426a3ee --- /dev/null +++ b/tests/draft4/infinite-loop-detection.json @@ -0,0 +1,36 @@ +[ + { + "description": "evaluating the same schema location against the same data location twice is not a sign of an infinite loop", + "schema": { + "definitions": { + "int": { "type": "integer" } + }, + "allOf": [ + { + "properties": { + "foo": { + "$ref": "#/definitions/int" + } + } + }, + { + "additionalProperties": { + "$ref": "#/defintions/int" + } + } + ] + }, + "tests": [ + { + "description": "passing case", + "data": { "foo": 1 }, + "valid": true + }, + { + "description": "failing case", + "data": { "foo": "a string" }, + "valid": false + } + ] + } +] diff --git a/tests/draft6/infinite-loop-detection.json b/tests/draft6/infinite-loop-detection.json new file mode 100644 index 00000000..0426a3ee --- /dev/null +++ b/tests/draft6/infinite-loop-detection.json @@ -0,0 +1,36 @@ +[ + { + "description": "evaluating the same schema location against the same data location twice is not a sign of an infinite loop", + "schema": { + "definitions": { + "int": { "type": "integer" } + }, + "allOf": [ + { + "properties": { + "foo": { + "$ref": "#/definitions/int" + } + } + }, + { + "additionalProperties": { + "$ref": "#/defintions/int" + } + } + ] + }, + "tests": [ + { + "description": "passing case", + "data": { "foo": 1 }, + "valid": true + }, + { + "description": "failing case", + "data": { "foo": "a string" }, + "valid": false + } + ] + } +] diff --git a/tests/draft7/infinite-loop-detection.json b/tests/draft7/infinite-loop-detection.json new file mode 100644 index 00000000..0426a3ee --- /dev/null +++ b/tests/draft7/infinite-loop-detection.json @@ -0,0 +1,36 @@ +[ + { + "description": "evaluating the same schema location against the same data location twice is not a sign of an infinite loop", + "schema": { + "definitions": { + "int": { "type": "integer" } + }, + "allOf": [ + { + "properties": { + "foo": { + "$ref": "#/definitions/int" + } + } + }, + { + "additionalProperties": { + "$ref": "#/defintions/int" + } + } + ] + }, + "tests": [ + { + "description": "passing case", + "data": { "foo": 1 }, + "valid": true + }, + { + "description": "failing case", + "data": { "foo": "a string" }, + "valid": false + } + ] + } +]