From fc4169dc91bef93be3c3653bd1f9aec0b97cd253 Mon Sep 17 00:00:00 2001 From: thymusvulgaris <87661013+thymusvulgaris@users.noreply.github.com> Date: Mon, 24 Jun 2024 07:19:39 +0100 Subject: [PATCH] Add Plug.BasicAuth test * Add test that asserts Plug.BasicAuth.basic_auth/2 raises key error when no options are given and default options are used. --- test/plug/basic_auth_test.exs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/plug/basic_auth_test.exs b/test/plug/basic_auth_test.exs index 5bca299e..7e9fda0c 100644 --- a/test/plug/basic_auth_test.exs +++ b/test/plug/basic_auth_test.exs @@ -15,6 +15,14 @@ defmodule Plug.BasicAuthTest do refute conn.halted end + test "raises key error when no options are given" do + assert_raise KeyError, fn -> + conn(:get, "/") + |> put_req_header("authorization", encode_basic_auth("hello", "world")) + |> basic_auth() + end + end + test "refutes invalid user and password" do for {user, pass} <- [{"hello", "wrong"}, {"wrong", "hello"}] do conn =