-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add LOG_FAILED_LOGIN_ATTEMPTS (#2936)
* add failed login logs * put failed login attempt logs behind a config option * add changelog entry * add config test * add auth_controller tests * move tests to separate non-async test module --------- Co-authored-by: Uku Taht <[email protected]>
- Loading branch information
Showing
5 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
test/plausible_web/controllers/auth_controller/logs_test.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
defmodule PlausibleWeb.AuthController.LogsTest do | ||
use PlausibleWeb.ConnCase | ||
import ExUnit.CaptureLog | ||
|
||
describe "POST /login" do | ||
setup do | ||
patch_env(:log_failed_login_attempts, true) | ||
end | ||
|
||
test "logs on missing user", %{conn: conn} do | ||
logs = | ||
capture_log(fn -> | ||
post(conn, "/login", email: "[email protected]", password: "password") | ||
end) | ||
|
||
assert logs =~ "[warning] [login] user not found for [email protected]" | ||
end | ||
|
||
test "logs on wrong password", %{conn: conn} do | ||
user = insert(:user, password: "password") | ||
|
||
logs = | ||
capture_log(fn -> | ||
post(conn, "/login", email: user.email, password: "wrong") | ||
end) | ||
|
||
assert logs =~ "[warning] [login] wrong password for #{user.email}" | ||
end | ||
|
||
test "logs on too many login attempts", %{conn: conn} do | ||
user = insert(:user, password: "password") | ||
|
||
capture_log(fn -> | ||
for _ <- 1..5 do | ||
build_conn() | ||
|> put_req_header("x-forwarded-for", "1.1.1.1") | ||
|> post("/login", email: user.email, password: "wrong") | ||
end | ||
end) | ||
|
||
logs = | ||
capture_log(fn -> | ||
conn | ||
|> put_req_header("x-forwarded-for", "1.1.1.1") | ||
|> post("/login", email: user.email, password: "wrong") | ||
end) | ||
|
||
assert logs =~ "[warning] [login] too many logging attempts for #{user.email}" | ||
end | ||
end | ||
end |