Merge branch 'develop' of https://git.pleroma.social/pleroma/pleroma into develop
[akkoma] / test / plugs / basic_auth_decoder_plug_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Plugs.BasicAuthDecoderPlugTest do
6 use Pleroma.Web.ConnCase, async: true
7
8 alias Pleroma.Plugs.BasicAuthDecoderPlug
9
10 defp basic_auth_enc(username, password) do
11 "Basic " <> Base.encode64("#{username}:#{password}")
12 end
13
14 test "it puts the decoded credentials into the assigns", %{conn: conn} do
15 header = basic_auth_enc("moonman", "iloverobek")
16
17 conn =
18 conn
19 |> put_req_header("authorization", header)
20 |> BasicAuthDecoderPlug.call(%{})
21
22 assert conn.assigns[:auth_credentials] == %{
23 username: "moonman",
24 password: "iloverobek"
25 }
26 end
27
28 test "without a authorization header it doesn't do anything", %{conn: conn} do
29 ret_conn =
30 conn
31 |> BasicAuthDecoderPlug.call(%{})
32
33 assert conn == ret_conn
34 end
35 end