Sha256: 5374c4d75de4889f1ca61dbcfb8d063a7ef5e98eca2cb796e3401a0d7825d849

Contents?: true

Size: 1.36 KB

Versions: 2

Compression:

Stored size: 1.36 KB

Contents

require File.expand_path('../support/test_helper', __FILE__)
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", __FILE__)

    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

Version data entries

2 entries across 1 versions & 1 rubygems

Version Path
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/bundler/gems/json-schema-2253a5ee6679/test/bad_schema_ref_test.rb
mountapi-0.11.1 vendor/json-schema/test/bad_schema_ref_test.rb