logo

pleroma

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

utils_test.exs (1507B)


  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.Web.OAuth.Token.UtilsTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.Web.OAuth.Token.Utils
  7. import Pleroma.Factory
  8. describe "fetch_app/1" do
  9. test "returns error when credentials is invalid" do
  10. assert {:error, :not_found} =
  11. Utils.fetch_app(%Plug.Conn{params: %{"client_id" => 1, "client_secret" => "x"}})
  12. end
  13. test "returns App by params credentails" do
  14. app = insert(:oauth_app)
  15. assert {:ok, load_app} =
  16. Utils.fetch_app(%Plug.Conn{
  17. params: %{"client_id" => app.client_id, "client_secret" => app.client_secret}
  18. })
  19. assert load_app == app
  20. end
  21. test "returns App by header credentails" do
  22. app = insert(:oauth_app)
  23. header = "Basic " <> Base.encode64("#{app.client_id}:#{app.client_secret}")
  24. conn =
  25. %Plug.Conn{}
  26. |> Plug.Conn.put_req_header("authorization", header)
  27. assert {:ok, load_app} = Utils.fetch_app(conn)
  28. assert load_app == app
  29. end
  30. end
  31. describe "format_created_at/1" do
  32. test "returns formatted created at" do
  33. token = insert(:oauth_token)
  34. date = Utils.format_created_at(token)
  35. token_date =
  36. token.inserted_at
  37. |> DateTime.from_naive!("Etc/UTC")
  38. |> DateTime.to_unix()
  39. assert token_date == date
  40. end
  41. end
  42. end