Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
972B

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2018 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