Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Lock down Rack for old Grape v1.x versions #2711

Merged
merged 5 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion test/multiverse/suites/grape/Envfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ def activesupport_version(grape_version)
", '< 7.1'" if grape_version&.include?('1.5')
end

# Grape v1.x expects Rack to deliver `rack/auth/digest/md5`, but Rack
# stopped offering that class in Rack v3.1.0
def rack_version(grape_version)
", '~> 3.0.11'" if grape_version.to_s.sub(/^[^\d]+/, '').start_with?('1.')
end

def gem_list(grape_version = nil)
<<~RB
gem 'rack'
gem 'rack'#{rack_version(grape_version)}
gem 'rack-test', '>= 0.8.0'
gem 'grape'#{grape_version}

Expand Down
11 changes: 9 additions & 2 deletions test/multiverse/suites/grape/grape_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,23 @@ def test_request_and_response_attributes_recorded_as_agent_attributes
'request.headers.host' => last_request.host,
'request.method' => last_request.request_method
}
actual = agent_attributes_for_single_event_posted_without_ignored_attributes

# Rack >= 2.1 changes how/when contentLength is computed and Grape >= 1.3 also changes to deal with this.
# interactions with Rack < 2.1 and >= 2.1 differ on response.headers.contentLength calculations
# so we remove it when it is zero since its not present in such cases.
#
# Rack >= 3.1 further changes things, so we also excuse an actual 0 value
# when it is in play
if Gem::Version.new(::Grape::VERSION) >= Gem::Version.new('1.3.0')
if expected['response.headers.contentLength'] == 0
rack31_plus_and_zero = Rack.respond_to?(:release) &&
Gem::Version.new(Rack.release) >= Gem::Version.new('3.1.0') &&
actual['request.headers.contentLength'] == 0

if expected['response.headers.contentLength'] == 0 || rack31_plus_and_zero
expected.delete('response.headers.contentLength')
end
end
actual = agent_attributes_for_single_event_posted_without_ignored_attributes

assert_equal(expected, actual)
end
Expand Down
Loading