Skip to content

Commit

Permalink
Remove code that references the request body
Browse files Browse the repository at this point in the history
  • Loading branch information
rmcastil committed Nov 19, 2024
1 parent 56441d1 commit e8d91ec
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 21 deletions.
6 changes: 1 addition & 5 deletions lib/wafris/wafris_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Wafris
class WafrisRequest
attr_reader :ip, :user_agent, :path, :parameters, :host, :method,
:headers, :body, :request_id, :request_timestamp
:headers, :request_id, :request_timestamp

def initialize(request, env)
@ip = encode_to_utf8(IpResolver.new(request).resolve)
Expand All @@ -15,10 +15,6 @@ def initialize(request, env)
@headers = extract_headers(env)
@request_id = env.fetch("action_dispatch.request_id", SecureRandom.uuid.to_s)
@request_timestamp = Time.now.utc.to_i

pos = request.body&.pos
@body = encode_to_utf8(request.body&.read)
request.body&.rewind if request.body&.pos != pos
end

def data(treatment:, category:, rule:)
Expand Down
17 changes: 1 addition & 16 deletions test/wafris_request_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@ def setup
@mock_request.expect(:params, {"foo" => "bar"})
@mock_request.expect(:host, "example.com")
@mock_request.expect(:request_method, "GET")
@request_body = StringIO.new("test body")
# Expect multiple calls to body to simulate rewind and position checks
4.times { @mock_request.expect(:body, @request_body) }
@mock_env = {
"HTTP_USER_AGENT" => "MockAgent",
"HTTP_HOST" => "example.com",
"REQUEST_METHOD" => "GET",
"PATH_INFO" => "/test",
"QUERY_STRING" => "foo=bar",
"action_dispatch.request_id" => "123456",
"rack.input" => StringIO.new("test body")
"action_dispatch.request_id" => "123456"
}
@ip_resolver = Minitest::Mock.new
@ip_resolver.expect(:resolve, "127.0.0.1")
Expand All @@ -35,7 +31,6 @@ def test_initialization
assert_equal "example.com", wafris_request.host
assert_equal "GET", wafris_request.method
assert_equal({"HTTP_USER_AGENT" => "MockAgent", "HTTP_HOST" => "example.com"}, wafris_request.headers)
assert_equal "test body", wafris_request.body
assert_equal "123456", wafris_request.request_id
assert_equal 1234567890, wafris_request.request_timestamp
end
Expand All @@ -44,16 +39,6 @@ def test_initialization
@mock_request.verify
end

def test_request_body_position_after_initialization
Time.stub :now, Time.at(1234567890) do
Wafris::IpResolver.stub(:new, @ip_resolver) do
Wafris::WafrisRequest.new(@mock_request, @mock_env)

assert_equal 0, @request_body.pos
end
end
end

def test_request_id_fallback
@mock_env.delete("action_dispatch.request_id")

Expand Down

0 comments on commit e8d91ec

Please sign in to comment.