1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
require File.expand_path('support/test_helper', __dir__)
require 'socket'
class BadSchemaRefTest < Minitest::Test
def setup
WebMock.allow_net_connect!
end
def teardown
WebMock.disable_net_connect!
end
def test_bad_uri_ref
schema = {
'$schema' => 'http://json-schema.org/draft-04/schema#',
'type' => 'array',
'items' => { '$ref' => '../google.json' },
}
data = [1, 2, 3]
error = assert_raises(JSON::Schema::ReadFailed) do
JSON::Validator.validate(schema, data)
end
expanded_path = File.expand_path('../google.json', __dir__)
assert_equal(:file, error.type)
assert_equal(expanded_path, error.location)
assert_equal("Read of file at #{expanded_path} failed", error.message)
end
def test_bad_host_ref
schema = {
'$schema' => 'http://json-schema.org/draft-04/schema#',
'type' => 'array',
'items' => { '$ref' => 'http://ppcheesecheseunicornnuuuurrrrr.example.invalid/json.schema' },
}
data = [1, 2, 3]
error = assert_raises(JSON::Schema::ReadFailed) do
JSON::Validator.validate(schema, data)
end
assert_equal(:uri, error.type)
assert_equal('http://ppcheesecheseunicornnuuuurrrrr.example.invalid/json.schema', error.location)
assert_equal('Read of URI at http://ppcheesecheseunicornnuuuurrrrr.example.invalid/json.schema failed', error.message)
end
end
|