logo

pleroma

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

mongoose_im_controller_test.exs (1983B)


  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.Web.MongooseIMController do
  5. use Pleroma.Web.ConnCase
  6. import Pleroma.Factory
  7. test "/user_exists", %{conn: conn} do
  8. _user = insert(:user, nickname: "lain")
  9. _remote_user = insert(:user, nickname: "alice", local: false)
  10. _deactivated_user = insert(:user, nickname: "konata", deactivated: true)
  11. res =
  12. conn
  13. |> get(mongoose_im_path(conn, :user_exists), user: "lain")
  14. |> json_response(200)
  15. assert res == true
  16. res =
  17. conn
  18. |> get(mongoose_im_path(conn, :user_exists), user: "alice")
  19. |> json_response(404)
  20. assert res == false
  21. res =
  22. conn
  23. |> get(mongoose_im_path(conn, :user_exists), user: "bob")
  24. |> json_response(404)
  25. assert res == false
  26. res =
  27. conn
  28. |> get(mongoose_im_path(conn, :user_exists), user: "konata")
  29. |> json_response(404)
  30. assert res == false
  31. end
  32. test "/check_password", %{conn: conn} do
  33. user = insert(:user, password_hash: Pbkdf2.hash_pwd_salt("cool"))
  34. _deactivated_user =
  35. insert(:user,
  36. nickname: "konata",
  37. deactivated: true,
  38. password_hash: Pbkdf2.hash_pwd_salt("cool")
  39. )
  40. res =
  41. conn
  42. |> get(mongoose_im_path(conn, :check_password), user: user.nickname, pass: "cool")
  43. |> json_response(200)
  44. assert res == true
  45. res =
  46. conn
  47. |> get(mongoose_im_path(conn, :check_password), user: user.nickname, pass: "uncool")
  48. |> json_response(403)
  49. assert res == false
  50. res =
  51. conn
  52. |> get(mongoose_im_path(conn, :check_password), user: "konata", pass: "cool")
  53. |> json_response(404)
  54. assert res == false
  55. res =
  56. conn
  57. |> get(mongoose_im_path(conn, :check_password), user: "nobody", pass: "cool")
  58. |> json_response(404)
  59. assert res == false
  60. end
  61. end