From 4fafc60303cb27dbf903c88aae8806f1d1b6aeed Mon Sep 17 00:00:00 2001 From: David Harsha Date: Fri, 13 Oct 2023 14:29:23 -0700 Subject: [PATCH] Follow meta schema redirects in tests It looks like they changed these to redirects: ``` % curl 'http://json-schema.org/draft-07/schema#' -I HTTP/1.1 301 Moved Permanently Date: Fri, 13 Oct 2023 21:29:36 GMT Connection: keep-alive Cache-Control: max-age=3600 Expires: Fri, 13 Oct 2023 22:29:36 GMT Location: https://json-schema.org/draft-07/schema Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=4Y8wC8Dh8QkEwNGjF%2FFKlVkfEiFB1hOv3XOnfGJPcIKfna%2FrsYwkURU1zkA5HAgGXRsXFZ3EUCjMOnZiLkXNjDJQ3zvaJJvsS43oAUhIM0uu2CFTfa4QHGRWI%2FpXcULLCqXrAzuUu%2FdG3RU0tFU%3D"}],"group":"cf-nel","max_age":604800} NEL: {"success_fraction":0,"report_to":"cf-nel","max_age":604800} Vary: Accept-Encoding CF-Cache-Status: DYNAMIC Server: cloudflare CF-RAY: 815aadd5892dcf05-SJC ``` Seems wrong to me, but idk. Added a test helper to resolve redirects when fetching things. --- test/json_schema_test_suite_test.rb | 2 +- test/json_schemer_test.rb | 2 +- test/test_helper.rb | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/test/json_schema_test_suite_test.rb b/test/json_schema_test_suite_test.rb index 26dedbef..f68d1a60 100644 --- a/test/json_schema_test_suite_test.rb +++ b/test/json_schema_test_suite_test.rb @@ -45,7 +45,7 @@ class JSONSchemaTestSuiteTest < Minitest::Test path = Pathname.new(__dir__).join('..', 'JSON-Schema-Test-Suite', 'remotes', uri.path.gsub(/\A\//, '')) JSON.parse(path.read) else - JSON.parse(Net::HTTP.get(uri)) + JSON.parse(fetch(uri)) end end diff --git a/test/json_schemer_test.rb b/test/json_schemer_test.rb index 1bde86f3..192f8b8e 100644 --- a/test/json_schemer_test.rb +++ b/test/json_schemer_test.rb @@ -422,7 +422,7 @@ def test_published_meta_schemas JSONSchemer::OpenAPI30::Document::SCHEMA ].each do |meta_schema| id = meta_schema.key?('$id') ? meta_schema.fetch('$id') : meta_schema.fetch('id') - assert_equal(meta_schema, JSON.parse(Net::HTTP.get(URI(id)))) + assert_equal(meta_schema, JSON.parse(fetch(id))) end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 60544faa..8a576cb2 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -12,3 +12,17 @@ require "json_schemer" require "minitest/autorun" + +def fetch(location, limit = 10) + raise if limit.zero? + uri = URI(location) + response = Net::HTTP.get_response(uri) + case response + when Net::HTTPSuccess + response.body + when Net::HTTPRedirection + fetch(URI.join(uri, response['Location']), limit - 1) + else + response.value.body + end +end