From c672ff2de82234e4c21c84ae6f571b39e086e44f Mon Sep 17 00:00:00 2001 From: "M.Shibuya" Date: Sat, 6 Mar 2021 15:48:36 +0900 Subject: [PATCH] Test against Ruby 3.0 --- .travis.yml | 1 + README.md | 2 +- spec/lib/ssrf_filter_spec.rb | 5 +++-- ssrf_filter.gemspec | 5 ++--- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index a0cee30..11b5270 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,7 @@ rvm: - ruby-2.5 - ruby-2.6 - ruby-2.7 + - ruby-3.0 - ruby-head script: - bundle exec bundler-audit diff --git a/README.md b/README.md index 415b614..6db18c7 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ This gem provides a safe and easy way to fetch content from user-submitted urls. - handles URIs/IPv4/IPv6, redirects, DNS, etc, correctly - has 0 runtime dependencies - has a comprehensive test suite (100% code coverage) -- is tested against ruby `2.0`, `2.1`, `2.2`, `2.3`, `2.4`, `2.5`, `2.6`, `2.7`, and `ruby-head` +- is tested against ruby `2.0`, `2.1`, `2.2`, `2.3`, `2.4`, `2.5`, `2.6`, `2.7`, `3.0`, and `ruby-head` ### Quick start diff --git a/spec/lib/ssrf_filter_spec.rb b/spec/lib/ssrf_filter_spec.rb index 76c809a..0f683c7 100644 --- a/spec/lib/ssrf_filter_spec.rb +++ b/spec/lib/ssrf_filter_spec.rb @@ -172,7 +172,7 @@ it 'should disallow header values with newlines and carriage returns' do # Starting in ruby 2.5, assigning a header value with newlines throws an ArgumentError major, minor = RUBY_VERSION.scan(/\A(\d+)\.(\d+)\.\d+\Z/).first.map(&:to_i) - exception = major >= 2 && minor >= 5 ? ArgumentError : SsrfFilter::CRLFInjection + exception = major >= 3 || (major >= 2 && minor >= 5) ? ArgumentError : SsrfFilter::CRLFInjection expect do SsrfFilter.get("https://#{public_ipv4}", headers: {'name' => "val\nue"}) @@ -417,9 +417,10 @@ def inject_custom_trust_store(*certificates) end it 'should follow redirects and succeed on a public hostname' do + major = RUBY_VERSION.scan(/\A(\d+)\.\d+\.\d+\Z/).first.map(&:to_i).first stub_request(:post, "https://#{public_ipv4}/path?key=value").with(headers: {host: 'www.example.com'}) .to_return(status: 301, headers: {location: 'https://www.example2.com/path2?key2=value2'}) - stub_request(:post, "https://#{public_ipv6}/path2?key2=value2") + stub_request(:post, "https://#{major >= 3 ? "[#{public_ipv6}]" : public_ipv6}/path2?key2=value2") .with(headers: {host: 'www.example2.com'}).to_return(status: 200, body: 'response body') resolver = proc do |hostname| [{ diff --git a/ssrf_filter.gemspec b/ssrf_filter.gemspec index ac46f9d..16edc52 100644 --- a/ssrf_filter.gemspec +++ b/ssrf_filter.gemspec @@ -20,9 +20,8 @@ Gem::Specification.new do |gem| gem.add_development_dependency('bundler-audit', '~> 0.6.1') gem.add_development_dependency('coveralls', '~> 0.8.22') gem.add_development_dependency('rspec', '~> 3.8.0') - gem.add_development_dependency('webmock', '~> 3.5.1') - - raise 'Unsupported version of ruby' unless major == 2 + gem.add_development_dependency('webmock', '>= 3.5.1') + gem.add_development_dependency('webrick') if major >= 3 if minor > 1 gem.add_development_dependency('rubocop', '~> 0.65.0')