Merge remote-tracking branch 'pleroma/develop' into cycles-uploader
[akkoma] / test / pleroma / web / mongoose_im_controller_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.MongooseIMControllerTest do
6 use Pleroma.Web.ConnCase, async: true
7 import Pleroma.Factory
8
9 test "/user_exists", %{conn: conn} do
10 _user = insert(:user, nickname: "lain")
11 _remote_user = insert(:user, nickname: "alice", local: false)
12 _deactivated_user = insert(:user, nickname: "konata", is_active: false)
13
14 res =
15 conn
16 |> get(mongoose_im_path(conn, :user_exists), user: "lain")
17 |> json_response(200)
18
19 assert res == true
20
21 res =
22 conn
23 |> get(mongoose_im_path(conn, :user_exists), user: "alice")
24 |> json_response(404)
25
26 assert res == false
27
28 res =
29 conn
30 |> get(mongoose_im_path(conn, :user_exists), user: "bob")
31 |> json_response(404)
32
33 assert res == false
34
35 res =
36 conn
37 |> get(mongoose_im_path(conn, :user_exists), user: "konata")
38 |> json_response(404)
39
40 assert res == false
41 end
42
43 test "/check_password", %{conn: conn} do
44 user = insert(:user, password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt("cool"))
45
46 _deactivated_user =
47 insert(:user,
48 nickname: "konata",
49 is_active: false,
50 password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt("cool")
51 )
52
53 res =
54 conn
55 |> get(mongoose_im_path(conn, :check_password), user: user.nickname, pass: "cool")
56 |> json_response(200)
57
58 assert res == true
59
60 res =
61 conn
62 |> get(mongoose_im_path(conn, :check_password), user: user.nickname, pass: "uncool")
63 |> json_response(403)
64
65 assert res == false
66
67 res =
68 conn
69 |> get(mongoose_im_path(conn, :check_password), user: "konata", pass: "cool")
70 |> json_response(404)
71
72 assert res == false
73
74 res =
75 conn
76 |> get(mongoose_im_path(conn, :check_password), user: "nobody", pass: "cool")
77 |> json_response(404)
78
79 assert res == false
80 end
81 end