Remove Firewall plug; redundant at infra level (#2730)
* Remove Firewall plug; redundant at infra level * Update changelogpull/2731/head
parent
8b0f0cabc2
commit
4b21b4e6d0
@ -1,17 +0,0 @@
|
||||
defmodule PlausibleWeb.Firewall do
|
||||
import Plug.Conn
|
||||
|
||||
def init(opts) do
|
||||
opts
|
||||
end
|
||||
|
||||
def call(conn, _opts) do
|
||||
blocklist = Keyword.fetch!(Application.get_env(:plausible, __MODULE__), :blocklist)
|
||||
|
||||
if PlausibleWeb.RemoteIp.get(conn) in blocklist do
|
||||
send_resp(conn, 404, "Not found") |> halt
|
||||
else
|
||||
conn
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1,29 +0,0 @@
|
||||
defmodule PlausibleWeb.FirewallTest do
|
||||
use Plausible.DataCase
|
||||
use Plug.Test
|
||||
alias PlausibleWeb.Firewall
|
||||
|
||||
@allowed_ip "127.0.0.1"
|
||||
@blocked_ip "127.0.0.2"
|
||||
@opts [blocklist: [@blocked_ip]]
|
||||
|
||||
setup_patch_env(PlausibleWeb.Firewall, blocklist: [@blocked_ip])
|
||||
|
||||
test "ignores request if IP is allowed" do
|
||||
conn =
|
||||
conn(:get, "/")
|
||||
|> put_req_header("x-forwarded-for", @allowed_ip)
|
||||
|> Firewall.call(@opts)
|
||||
|
||||
assert conn.status == nil
|
||||
end
|
||||
|
||||
test "responds with 404 if IP is blocked" do
|
||||
conn =
|
||||
conn(:get, "/")
|
||||
|> put_req_header("x-forwarded-for", @blocked_ip)
|
||||
|> Firewall.call(@opts)
|
||||
|
||||
assert conn.status == 404
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue