analytics/test/plausible_web/plugs/firewall_test.exs
Adam Rutkowski 5de43b758d
Run tests in async mode where applicable (#2542)
* Set pg pool size for MIX_ENV=test

* Include slow tests in CI run

* Exclude slow tests by default

* Mark tests slow/async where applicable

* Restructure captcha mocks

* Revert async where env is relied upon

* Add --max-failures=1 to CI run

* Set warnings as errors

* Disable async where various mocks are used

* Revert "Disable async where various mocks are used"

This reverts commit 2446b72a29.

* Disable async for test using vcr
2022-12-26 10:20:29 -03:00

30 lines
676 B
Elixir

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