Skip to content

Commit

Permalink
Plug RateLimiter uniquement pour l'app transport (#3718)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineAugusti authored Jan 17, 2024
1 parent c471d43 commit bd92be7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
9 changes: 9 additions & 0 deletions apps/gbfs/test/gbfs/controllers/index_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,13 @@ defmodule GBFS.IndexControllerTest do
# We did not receive telemetry events (ie metrics have not been saved to the database)
refute_receive {:telemetry_event, [:gbfs, :request, _], %{}, %{}}
end

test "rate limiter is not enabled for the GBFS app", %{conn: conn} do
[blocked_ip] = Application.fetch_env!(:phoenix_ddos, :blocklist_ips)

conn
|> Plug.Conn.put_req_header("x-forwarded-for", to_string(blocked_ip))
|> get("/gbfs")
|> json_response(200)
end
end
1 change: 0 additions & 1 deletion apps/transport/lib/transport_web/endpoint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ defmodule TransportWeb.Endpoint do

plug(Plug.RequestId)
plug(RemoteIp, headers: ["x-forwarded-for"])
plug(TransportWeb.Plugs.RateLimiter, :use_env_variables)
plug(Plug.Logger)

plug(Plug.Parsers,
Expand Down
1 change: 1 addition & 0 deletions apps/transport/lib/transport_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defmodule TransportWeb.Router do

pipeline :browser_no_csp do
plug(:canonical_host)
plug(TransportWeb.Plugs.RateLimiter, :use_env_variables)
plug(:accepts, ["html"])
plug(:fetch_session)
plug(:fetch_flash)
Expand Down
22 changes: 15 additions & 7 deletions apps/transport/test/transport_web/routing/proxy_routing_test.exs
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
defmodule TransportWeb.ProxyRoutingTest do
use TransportWeb.ConnCase, async: true
import Phoenix.ConnTest

test "accepts proxy. subdomain calls and delegates them to unlock", %{conn: conn} do
conn =
conn
|> Map.put(:host, "proxy.example.com")
|> get(~p"/")
test "accepts proxy. subdomain, calls and delegates them to Unlock", %{conn: conn} do
conn = %{conn | host: "proxy.example.com"} |> get(~p"/")

[h] = Plug.Conn.get_resp_header(conn, "x-request-id")
assert h

assert text_response(conn, 200) =~ ~r/Unlock/
assert text_response(conn, 200) =~ "Unlock"
end

test "rate limiter is not enabled for proxy", %{conn: conn} do
[blocked_ip] = Application.fetch_env!(:phoenix_ddos, :blocklist_ips)

response =
%{conn | host: "proxy.example.com"}
|> Plug.Conn.put_req_header("x-forwarded-for", to_string(blocked_ip))
|> get(~p"/")
|> text_response(200)

assert response =~ "Unlock"
end
end

0 comments on commit bd92be7

Please sign in to comment.