Updated basic auth parsing to ignore empty strings
This commit is contained in:
parent
1b404086d5
commit
82124b0669
2 changed files with 14 additions and 1 deletions
|
|
@ -54,10 +54,14 @@ defmodule PinchflatWeb.Router do
|
|||
username = Application.get_env(:pinchflat, :basic_auth_username)
|
||||
password = Application.get_env(:pinchflat, :basic_auth_password)
|
||||
|
||||
if username && password do
|
||||
if credential_set?(username) && credential_set?(password) do
|
||||
Plug.BasicAuth.basic_auth(conn, username: username, password: password, realm: "Pinchflat")
|
||||
else
|
||||
conn
|
||||
end
|
||||
end
|
||||
|
||||
defp credential_set?(credential) do
|
||||
credential && credential != ""
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -44,5 +44,14 @@ defmodule PinchflatWeb.RoutingTest do
|
|||
|
||||
assert conn.status == 200
|
||||
end
|
||||
|
||||
test "it treats empty strings as not being set when using basic auth", %{conn: conn} do
|
||||
Application.put_env(:pinchflat, :basic_auth_username, "")
|
||||
Application.put_env(:pinchflat, :basic_auth_password, "pass")
|
||||
|
||||
conn = get(conn, "/")
|
||||
|
||||
assert conn.status == 200
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue