require File.expand_path('../test_helper', __FILE__)
require 'webmock'
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]
    assert_raises(URI::BadURIError) do
      JSON::Validator.validate(schema,data)
    end
  end

  def test_bad_host_ref
    schema = {
      "$schema" => "http://json-schema.org/draft-04/schema#",
      "type" => "array",
      "items" => { "$ref" => "http://ppcheesecheseunicornnuuuurrrrr.com/json.schema"}
    }

    data = [1,2,3]
    assert_raises(SocketError, OpenURI::HTTPError) do
      JSON::Validator.validate(schema,data)
    end
  end

end

require File.expand_path('../test_helper', __FILE__)
require 'webmock'
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]
    assert_raises(URI::BadURIError) do
      JSON::Validator.validate(schema,data)
    end
  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]
    assert_raises(SocketError, OpenURI::HTTPError) do
      JSON::Validator.validate(schema,data)
    end
  end

end

Use RFC 2606 reserved invalid DNS name in tests.
Use RFC 2606 reserved invalid DNS name in tests.

This test used a DNS name which, while currently not existing, is not
actually reserved. This can manifest as a test failure on poorly
configured (like Time Warner Cable) networks. This changes said DNS
name to one using a reserved invalid top level name as specified in
RFC 2606.
