logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

app_controller_test.exs (2611B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.MastodonAPI.AppControllerTest do
  5. use Pleroma.Web.ConnCase, async: true
  6. alias Pleroma.Repo
  7. alias Pleroma.Web.OAuth.App
  8. alias Pleroma.Web.Push
  9. import Pleroma.Factory
  10. test "apps/verify_credentials", %{conn: conn} do
  11. user_bound_token = insert(:oauth_token)
  12. app_bound_token = insert(:oauth_token, user: nil)
  13. refute app_bound_token.user
  14. for token <- [app_bound_token, user_bound_token] do
  15. conn =
  16. conn
  17. |> put_req_header("authorization", "Bearer #{token.token}")
  18. |> get("/api/v1/apps/verify_credentials")
  19. app = Repo.preload(token, :app).app
  20. expected = %{
  21. "name" => app.client_name,
  22. "website" => app.website,
  23. "vapid_key" => Push.vapid_config() |> Keyword.get(:public_key)
  24. }
  25. assert expected == json_response_and_validate_schema(conn, 200)
  26. end
  27. end
  28. test "creates an oauth app", %{conn: conn} do
  29. app_attrs = build(:oauth_app)
  30. conn =
  31. conn
  32. |> put_req_header("content-type", "application/json")
  33. |> post("/api/v1/apps", %{
  34. client_name: app_attrs.client_name,
  35. redirect_uris: app_attrs.redirect_uris
  36. })
  37. [app] = Repo.all(App)
  38. expected = %{
  39. "name" => app.client_name,
  40. "website" => app.website,
  41. "client_id" => app.client_id,
  42. "client_secret" => app.client_secret,
  43. "id" => app.id |> to_string(),
  44. "redirect_uri" => app.redirect_uris,
  45. "vapid_key" => Push.vapid_config() |> Keyword.get(:public_key)
  46. }
  47. assert expected == json_response_and_validate_schema(conn, 200)
  48. assert app.user_id == nil
  49. end
  50. test "creates an oauth app with a user", %{conn: conn} do
  51. user = insert(:user)
  52. app_attrs = build(:oauth_app)
  53. conn =
  54. conn
  55. |> put_req_header("content-type", "application/json")
  56. |> assign(:user, user)
  57. |> post("/api/v1/apps", %{
  58. client_name: app_attrs.client_name,
  59. redirect_uris: app_attrs.redirect_uris
  60. })
  61. [app] = Repo.all(App)
  62. expected = %{
  63. "name" => app.client_name,
  64. "website" => app.website,
  65. "client_id" => app.client_id,
  66. "client_secret" => app.client_secret,
  67. "id" => app.id |> to_string(),
  68. "redirect_uri" => app.redirect_uris,
  69. "vapid_key" => Push.vapid_config() |> Keyword.get(:public_key)
  70. }
  71. assert expected == json_response_and_validate_schema(conn, 200)
  72. assert app.user_id == user.id
  73. end
  74. end