Skip to content

Commit

Permalink
Follow meta schema redirects in tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
davishmcclurg committed Oct 13, 2023
1 parent 5c002fe commit 4fafc60
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion test/json_schema_test_suite_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/json_schemer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 14 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4fafc60

Please sign in to comment.