2019-05-17 12:21:11 -04:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-03-03 17:44:49 -05:00
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
2019-05-17 12:21:11 -04:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.MongooseIMController do
|
|
|
|
use Pleroma.Web.ConnCase
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
|
|
|
test "/user_exists", %{conn: conn} do
|
|
|
|
_user = insert(:user, nickname: "lain")
|
|
|
|
_remote_user = insert(:user, nickname: "alice", local: false)
|
2020-04-27 13:16:05 -04:00
|
|
|
_deactivated_user = insert(:user, nickname: "konata", deactivated: true)
|
2019-05-17 12:21:11 -04:00
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> get(mongoose_im_path(conn, :user_exists), user: "lain")
|
|
|
|
|> json_response(200)
|
|
|
|
|
|
|
|
assert res == true
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> get(mongoose_im_path(conn, :user_exists), user: "alice")
|
|
|
|
|> json_response(404)
|
|
|
|
|
|
|
|
assert res == false
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> get(mongoose_im_path(conn, :user_exists), user: "bob")
|
|
|
|
|> json_response(404)
|
|
|
|
|
|
|
|
assert res == false
|
2020-04-27 13:16:05 -04:00
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> get(mongoose_im_path(conn, :user_exists), user: "konata")
|
|
|
|
|> json_response(404)
|
|
|
|
|
|
|
|
assert res == false
|
2019-05-17 12:21:11 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "/check_password", %{conn: conn} do
|
2020-05-12 17:42:24 -04:00
|
|
|
user = insert(:user, password_hash: Pbkdf2.hash_pwd_salt("cool"))
|
2020-04-27 19:29:31 -04:00
|
|
|
|
|
|
|
_deactivated_user =
|
|
|
|
insert(:user,
|
|
|
|
nickname: "konata",
|
|
|
|
deactivated: true,
|
2020-05-12 17:42:24 -04:00
|
|
|
password_hash: Pbkdf2.hash_pwd_salt("cool")
|
2020-04-27 19:29:31 -04:00
|
|
|
)
|
2019-05-17 12:21:11 -04:00
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> get(mongoose_im_path(conn, :check_password), user: user.nickname, pass: "cool")
|
|
|
|
|> json_response(200)
|
|
|
|
|
|
|
|
assert res == true
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> get(mongoose_im_path(conn, :check_password), user: user.nickname, pass: "uncool")
|
|
|
|
|> json_response(403)
|
|
|
|
|
|
|
|
assert res == false
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
2020-04-27 13:16:05 -04:00
|
|
|
|> get(mongoose_im_path(conn, :check_password), user: "konata", pass: "cool")
|
2020-04-27 12:31:00 -04:00
|
|
|
|> json_response(404)
|
|
|
|
|
|
|
|
assert res == false
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
2019-05-17 12:21:11 -04:00
|
|
|
|> get(mongoose_im_path(conn, :check_password), user: "nobody", pass: "cool")
|
|
|
|
|> json_response(404)
|
|
|
|
|
|
|
|
assert res == false
|
|
|
|
end
|
|
|
|
end
|