aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorrinpatch <rinpatch@sdf.org>2020-02-29 23:08:14 +0000
committerrinpatch <rinpatch@sdf.org>2020-02-29 23:08:14 +0000
commit438394d40447bdfb590ff206ad80907294da0e65 (patch)
treeeba301a4ae02e8306eb8849b8a1f0918f55921da /test
parent19e559fe5130f66a967732a40ccea1ac39e85eb8 (diff)
parentb5465bf385800d52998bca472a19ea1b9db4c252 (diff)
downloadpleroma-438394d40447bdfb590ff206ad80907294da0e65.tar.gz
Merge branch 'fix/easy-timeline-dos' into 'develop'
Cap the number of requested statuses in timelines to 40 and rate limit them See merge request pleroma/pleroma!2253
Diffstat (limited to 'test')
-rw-r--r--test/plugs/rate_limiter_test.exs31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/plugs/rate_limiter_test.exs b/test/plugs/rate_limiter_test.exs
index 104d67611..8cdc8d1a2 100644
--- a/test/plugs/rate_limiter_test.exs
+++ b/test/plugs/rate_limiter_test.exs
@@ -242,4 +242,35 @@ defmodule Pleroma.Plugs.RateLimiterTest do
refute conn_2.halted
end
end
+
+ test "doesn't crash due to a race condition when multiple requests are made at the same time and the bucket is not yet initialized" do
+ limiter_name = :test_race_condition
+ Pleroma.Config.put([:rate_limit, limiter_name], {1000, 5})
+ Pleroma.Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8})
+
+ opts = RateLimiter.init(name: limiter_name)
+
+ conn = conn(:get, "/")
+ conn_2 = conn(:get, "/")
+
+ %Task{pid: pid1} =
+ task1 =
+ Task.async(fn ->
+ receive do
+ :process2_up ->
+ RateLimiter.call(conn, opts)
+ end
+ end)
+
+ task2 =
+ Task.async(fn ->
+ send(pid1, :process2_up)
+ RateLimiter.call(conn_2, opts)
+ end)
+
+ Task.await(task1)
+ Task.await(task2)
+
+ refute {:err, :not_found} == RateLimiter.inspect_bucket(conn, limiter_name, opts)
+ end
end