1 defmodule Pleroma.Web.OAuth.AuthorizationTest do
3 alias Pleroma.Web.OAuth.{Authorization, App}
6 test "create an authorization token for a valid app" do
7 {:ok, app} = Repo.insert(App.register_changeset(%App{}, %{client_name: "client", scopes: "scope", redirect_uris: "url"}))
10 {:ok, auth} = Authorization.create_authorization(app, user)
12 assert auth.user_id == user.id
13 assert auth.app_id == app.id
14 assert String.length(auth.token) > 10
15 assert auth.used == false
18 test "use up a token" do
19 {:ok, app} = Repo.insert(App.register_changeset(%App{}, %{client_name: "client", scopes: "scope", redirect_uris: "url"}))
22 {:ok, auth} = Authorization.create_authorization(app, user)
24 {:ok, auth} = Authorization.use_token(auth)
26 assert auth.used == true
28 assert {:error, "already used"} == Authorization.use_token(auth)
30 expired_auth = %Authorization{
33 valid_until: NaiveDateTime.add(NaiveDateTime.utc_now, -10),
38 {:ok, expired_auth} = Repo.insert(expired_auth)
40 assert {:error, "token expired"} == Authorization.use_token(expired_auth)