From 84da6c014a59c9853a07a9aad4c0ad46fab4fa26 Mon Sep 17 00:00:00 2001 From: Dmitry Tymchuk Date: Thu, 21 Sep 2017 15:54:17 +0200 Subject: [PATCH] Enable a rate limiter --- .../web/controllers/assigner_controller.ex | 2 +- test/controllers/assigner_controller_test.exs | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/xperiments/web/controllers/assigner_controller.ex b/lib/xperiments/web/controllers/assigner_controller.ex index c68a3de..005a588 100644 --- a/lib/xperiments/web/controllers/assigner_controller.ex +++ b/lib/xperiments/web/controllers/assigner_controller.ex @@ -2,7 +2,7 @@ defmodule Xperiments.Web.AssignerController do use Xperiments.Web, :controller alias Xperiments.{Repo, Experiment} - # plug Xperiments.Plug.RateLimit, max_requests: 5, interval_seconds: 60 + plug Xperiments.Plug.RateLimit, max_requests: 5, interval_seconds: 60 plug :auth_request when action in [:example] def experiments(conn, params) do diff --git a/test/controllers/assigner_controller_test.exs b/test/controllers/assigner_controller_test.exs index 432c03c..9314dd4 100644 --- a/test/controllers/assigner_controller_test.exs +++ b/test/controllers/assigner_controller_test.exs @@ -98,16 +98,16 @@ defmodule Xperiments.AssignerControllerTest do assert db_exp.statistics.variants_impression == %{hd(context.exp.variants).id => 4} end - # test "requests are throttled", context do - # for _i <- 0..4 do - # post(context.conn, "#{@api_path}/experiments/events", %{event: "impression", payload: context.call_payload}) - # |> json_response(200) - # end - # body = - # post(context.conn, "#{@api_path}/experiments/events", %{event: "impression", payload: context.call_payload}) - # |> json_response(403) - # assert body == %{"error" => "Rate limit exceeded"} - # end + test "requests are throttled", context do + for _i <- 0..4 do + post(context.conn, "#{@api_path}/experiments/events", %{event: "impression", payload: context.call_payload}) + |> json_response(200) + end + body = + post(context.conn, "#{@api_path}/experiments/events", %{event: "impression", payload: context.call_payload}) + |> json_response(403) + assert body == %{"error" => "Rate limit exceeded"} + end end describe "Rules/Segments logic" do