From b9bddc9cb775ddbf5c2eac48bf0d93dd5a5d0e78 Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Fri, 25 Jun 2021 21:32:09 -0700 Subject: [PATCH] test that sibling $ids to $refs are ignored --- tests/draft3/ref.json | 36 ++++++++++++++++++++++++++++++++++++ tests/draft4/ref.json | 36 ++++++++++++++++++++++++++++++++++++ tests/draft6/ref.json | 36 ++++++++++++++++++++++++++++++++++++ tests/draft7/ref.json | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 144 insertions(+) diff --git a/tests/draft3/ref.json b/tests/draft3/ref.json index 26dcb52d..760b7713 100644 --- a/tests/draft3/ref.json +++ b/tests/draft3/ref.json @@ -200,6 +200,42 @@ } ] }, + { + "description": "$ref prevents a sibling $id from changing the base uri", + "schema": { + "$id": "http://localhost:1234/sibling_id/base/", + "definitions": { + "foo": { + "$id": "http://localhost:1234/sibling_id/foo.json", + "minimum": 2 + }, + "base_foo": { + "$comment": "this canonical uri is http://localhost:1234/sibling_id/base/foo.json", + "$id": "foo.json", + "minimum": 5 + } + }, + "allOf": [ + { + "$comment": "$ref resolves to http://localhost:1234/sibling_id/base/foo.json, not ttp://localhost:1234/sibling_id/foo.json", + "$id": "http://localhost:1234/sibling_id/", + "$ref": "foo.json" + } + ] + }, + "tests": [ + { + "description": "$ref resolves to /definitions/foo, data validates", + "data": 10, + "valid": true + }, + { + "description": "$ref resolves to /definitions/foo, data does not validate", + "data": 1, + "valid": false + } + ] + }, { "description": "remote ref, containing refs itself", "schema": {"$ref": "http://json-schema.org/draft-03/schema#"}, diff --git a/tests/draft4/ref.json b/tests/draft4/ref.json index cc2ecf12..ae3770b6 100644 --- a/tests/draft4/ref.json +++ b/tests/draft4/ref.json @@ -175,6 +175,42 @@ } ] }, + { + "description": "$ref prevents a sibling $id from changing the base uri", + "schema": { + "$id": "http://localhost:1234/sibling_id/base/", + "definitions": { + "foo": { + "$id": "http://localhost:1234/sibling_id/foo.json", + "minimum": 2 + }, + "base_foo": { + "$comment": "this canonical uri is http://localhost:1234/sibling_id/base/foo.json", + "$id": "foo.json", + "minimum": 5 + } + }, + "allOf": [ + { + "$comment": "$ref resolves to http://localhost:1234/sibling_id/base/foo.json, not ttp://localhost:1234/sibling_id/foo.json", + "$id": "http://localhost:1234/sibling_id/", + "$ref": "foo.json" + } + ] + }, + "tests": [ + { + "description": "$ref resolves to /definitions/foo, data validates", + "data": 10, + "valid": true + }, + { + "description": "$ref resolves to /definitions/foo, data does not validate", + "data": 1, + "valid": false + } + ] + }, { "description": "remote ref, containing refs itself", "schema": {"$ref": "http://json-schema.org/draft-04/schema#"}, diff --git a/tests/draft6/ref.json b/tests/draft6/ref.json index 1fb426b2..7780c3f3 100644 --- a/tests/draft6/ref.json +++ b/tests/draft6/ref.json @@ -175,6 +175,42 @@ } ] }, + { + "description": "$ref prevents a sibling $id from changing the base uri", + "schema": { + "$id": "http://localhost:1234/sibling_id/base/", + "definitions": { + "foo": { + "$id": "http://localhost:1234/sibling_id/foo.json", + "minimum": 2 + }, + "base_foo": { + "$comment": "this canonical uri is http://localhost:1234/sibling_id/base/foo.json", + "$id": "foo.json", + "minimum": 5 + } + }, + "allOf": [ + { + "$comment": "$ref resolves to http://localhost:1234/sibling_id/base/foo.json, not ttp://localhost:1234/sibling_id/foo.json", + "$id": "http://localhost:1234/sibling_id/", + "$ref": "foo.json" + } + ] + }, + "tests": [ + { + "description": "$ref resolves to /definitions/foo, data validates", + "data": 10, + "valid": true + }, + { + "description": "$ref resolves to /definitions/foo, data does not validate", + "data": 1, + "valid": false + } + ] + }, { "description": "remote ref, containing refs itself", "schema": {"$ref": "http://json-schema.org/draft-06/schema#"}, diff --git a/tests/draft7/ref.json b/tests/draft7/ref.json index 406ae168..ff98d79f 100644 --- a/tests/draft7/ref.json +++ b/tests/draft7/ref.json @@ -175,6 +175,42 @@ } ] }, + { + "description": "$ref prevents a sibling $id from changing the base uri", + "schema": { + "$id": "http://localhost:1234/sibling_id/base/", + "definitions": { + "foo": { + "$id": "http://localhost:1234/sibling_id/foo.json", + "minimum": 2 + }, + "base_foo": { + "$comment": "this canonical uri is http://localhost:1234/sibling_id/base/foo.json", + "$id": "foo.json", + "minimum": 5 + } + }, + "allOf": [ + { + "$comment": "$ref resolves to http://localhost:1234/sibling_id/base/foo.json, not ttp://localhost:1234/sibling_id/foo.json", + "$id": "http://localhost:1234/sibling_id/", + "$ref": "foo.json" + } + ] + }, + "tests": [ + { + "description": "$ref resolves to /definitions/foo, data validates", + "data": 10, + "valid": true + }, + { + "description": "$ref resolves to /definitions/foo, data does not validate", + "data": 1, + "valid": false + } + ] + }, { "description": "remote ref, containing refs itself", "schema": {"$ref": "http://json-schema.org/draft-07/schema#"},