1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.OAuth.Token.UtilsTest do
7 alias Pleroma.Web.OAuth.Token.Utils
10 describe "fetch_app/1" do
11 test "returns error when credentials is invalid" do
12 assert {:error, :not_found} =
13 Utils.fetch_app(%Plug.Conn{params: %{"client_id" => 1, "client_secret" => "x"}})
16 test "returns App by params credentails" do
17 app = insert(:oauth_app)
19 assert {:ok, load_app} =
20 Utils.fetch_app(%Plug.Conn{
21 params: %{"client_id" => app.client_id, "client_secret" => app.client_secret}
24 assert load_app == app
27 test "returns App by header credentails" do
28 app = insert(:oauth_app)
29 header = "Basic " <> Base.encode64("#{app.client_id}:#{app.client_secret}")
33 |> Plug.Conn.put_req_header("authorization", header)
35 assert {:ok, load_app} = Utils.fetch_app(conn)
36 assert load_app == app
40 describe "format_created_at/1" do
41 test "returns formatted created at" do
42 token = insert(:oauth_token)
43 date = Utils.format_created_at(token)
47 |> DateTime.from_naive!("Etc/UTC")
50 assert token_date == date