logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

basic_auth_decoder_plug_test.exs (972B)


  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. defmodule Pleroma.Plugs.BasicAuthDecoderPlugTest do
  5. use Pleroma.Web.ConnCase, async: true
  6. alias Pleroma.Plugs.BasicAuthDecoderPlug
  7. defp basic_auth_enc(username, password) do
  8. "Basic " <> Base.encode64("#{username}:#{password}")
  9. end
  10. test "it puts the decoded credentials into the assigns", %{conn: conn} do
  11. header = basic_auth_enc("moonman", "iloverobek")
  12. conn =
  13. conn
  14. |> put_req_header("authorization", header)
  15. |> BasicAuthDecoderPlug.call(%{})
  16. assert conn.assigns[:auth_credentials] == %{
  17. username: "moonman",
  18. password: "iloverobek"
  19. }
  20. end
  21. test "without a authorization header it doesn't do anything", %{conn: conn} do
  22. ret_conn =
  23. conn
  24. |> BasicAuthDecoderPlug.call(%{})
  25. assert conn == ret_conn
  26. end
  27. end