1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.MastodonAPI.AppControllerTest do
6 use Pleroma.Web.ConnCase, async: true
9 alias Pleroma.Web.OAuth.App
10 alias Pleroma.Web.Push
12 import Pleroma.Factory
14 test "apps/verify_credentials", %{conn: conn} do
15 user_bound_token = insert(:oauth_token)
16 app_bound_token = insert(:oauth_token, user: nil)
17 refute app_bound_token.user
19 for token <- [app_bound_token, user_bound_token] do
22 |> put_req_header("authorization", "Bearer #{token.token}")
23 |> get("/api/v1/apps/verify_credentials")
25 app = Repo.preload(token, :app).app
28 "name" => app.client_name,
29 "website" => app.website,
30 "vapid_key" => Push.vapid_config() |> Keyword.get(:public_key)
33 assert expected == json_response_and_validate_schema(conn, 200)
37 test "creates an oauth app", %{conn: conn} do
38 app_attrs = build(:oauth_app)
42 |> put_req_header("content-type", "application/json")
43 |> post("/api/v1/apps", %{
44 client_name: app_attrs.client_name,
45 redirect_uris: app_attrs.redirect_uris
51 "name" => app.client_name,
52 "website" => app.website,
53 "client_id" => app.client_id,
54 "client_secret" => app.client_secret,
55 "id" => app.id |> to_string(),
56 "redirect_uri" => app.redirect_uris,
57 "vapid_key" => Push.vapid_config() |> Keyword.get(:public_key)
60 assert expected == json_response_and_validate_schema(conn, 200)
61 assert app.user_id == nil
64 test "creates an oauth app with a user", %{conn: conn} do
66 app_attrs = build(:oauth_app)
70 |> put_req_header("content-type", "application/json")
71 |> assign(:user, user)
72 |> post("/api/v1/apps", %{
73 client_name: app_attrs.client_name,
74 redirect_uris: app_attrs.redirect_uris
80 "name" => app.client_name,
81 "website" => app.website,
82 "client_id" => app.client_id,
83 "client_secret" => app.client_secret,
84 "id" => app.id |> to_string(),
85 "redirect_uri" => app.redirect_uris,
86 "vapid_key" => Push.vapid_config() |> Keyword.get(:public_key)
89 assert expected == json_response_and_validate_schema(conn, 200)
90 assert app.user_id == user.id