Skip to content

Commit

Permalink
test: throttle weight 0
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiemccarthy committed Dec 12, 2021
1 parent 1c02f54 commit 6ec96eb
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions spec/acceptance/throttling_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
weight_proc = lambda do |request|
if request.env["X-APIKey"] == "private-secret"
3
elsif request.env["X-Lightweight"].present?
0
else
2
end
Expand All @@ -80,6 +82,12 @@

assert_equal 200, last_response.status

2.times do
get "/", {}, "REMOTE_ADDR" => "1.2.3.4", "X-Lightweight" => "1"

assert_equal 200, last_response.status
end

get "/", {}, "REMOTE_ADDR" => "1.2.3.4"

assert_equal 200, last_response.status
Expand All @@ -90,6 +98,12 @@
assert_nil last_response.headers["Retry-After"]
assert_equal "Retry later\n", last_response.body

get "/", {}, "REMOTE_ADDR" => "1.2.3.4", "X-Lightweight" => "1"

assert_equal 429, last_response.status
assert_nil last_response.headers["Retry-After"]
assert_equal "Retry later\n", last_response.body

get "/", {}, "REMOTE_ADDR" => "5.6.7.8", "X-APIKey" => "private-secret"

assert_equal 200, last_response.status
Expand All @@ -105,6 +119,12 @@

assert_equal 200, last_response.status
end

5.times do
get "/", {}, "REMOTE_ADDR" => "9.10.11.12", "X-Lightweight" => "1"

assert_equal 200, last_response.status
end
end

it "returns correct Retry-After header if enabled" do
Expand Down

0 comments on commit 6ec96eb

Please sign in to comment.