logo

pleroma

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

purge_expired_token_test.exs (1484B)


  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.Workers.PurgeExpiredTokenTest do
  5. use Pleroma.DataCase, async: true
  6. use Oban.Testing, repo: Pleroma.Repo
  7. import Pleroma.Factory
  8. setup do: clear_config([:oauth2, :clean_expired_tokens], true)
  9. test "purges expired oauth token" do
  10. user = insert(:user)
  11. app = insert(:oauth_app)
  12. {:ok, %{id: id}} = Pleroma.Web.OAuth.Token.create(app, user)
  13. assert_enqueued(
  14. worker: Pleroma.Workers.PurgeExpiredToken,
  15. args: %{token_id: id, mod: Pleroma.Web.OAuth.Token}
  16. )
  17. assert {:ok, %{id: ^id}} =
  18. perform_job(Pleroma.Workers.PurgeExpiredToken, %{
  19. token_id: id,
  20. mod: Pleroma.Web.OAuth.Token
  21. })
  22. assert Repo.aggregate(Pleroma.Web.OAuth.Token, :count, :id) == 0
  23. end
  24. test "purges expired mfa token" do
  25. authorization = insert(:oauth_authorization)
  26. {:ok, %{id: id}} = Pleroma.MFA.Token.create(authorization.user, authorization)
  27. assert_enqueued(
  28. worker: Pleroma.Workers.PurgeExpiredToken,
  29. args: %{token_id: id, mod: Pleroma.MFA.Token}
  30. )
  31. assert {:ok, %{id: ^id}} =
  32. perform_job(Pleroma.Workers.PurgeExpiredToken, %{
  33. token_id: id,
  34. mod: Pleroma.MFA.Token
  35. })
  36. assert Repo.aggregate(Pleroma.MFA.Token, :count, :id) == 0
  37. end
  38. end