add tests for deactivated users for mongoose auth
authorfence <fence@desu-mail.moe>
Mon, 27 Apr 2020 16:31:00 +0000 (18:31 +0200)
committerfence <fence@desu-mail.moe>
Mon, 27 Apr 2020 16:31:00 +0000 (18:31 +0200)
lib/pleroma/web/mongooseim/mongoose_im_controller.ex
test/web/mongooseim/mongoose_im_controller_test.exs

index 744cf5227e02a5e648a5e403f4ffd753d285a3d4..c15b4bfb8198afd475f86c02198e814f0e2b29fd 100644 (file)
@@ -27,8 +27,13 @@ defmodule Pleroma.Web.MongooseIM.MongooseIMController do
 
   def check_password(conn, %{"user" => username, "pass" => password}) do
     user = Repo.get_by(User, nickname: username, local: true)
+    
+    state = case user do
+      nil -> nil
+      _ -> User.account_status(user)
+    end
 
-    case User.account_status(user) do
+    case state do
       :deactivated ->
         conn
         |> put_status(:not_found)
index 291ae54fc1639ddb53f6d268c2b98a7a7b13721a..5987111e5f115e6aae3622a22b23eba2af2d366d 100644 (file)
@@ -34,6 +34,7 @@ defmodule Pleroma.Web.MongooseIMController do
 
   test "/check_password", %{conn: conn} do
     user = insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt("cool"))
+    _deactivated_user = insert(:user, nickname: "konata", local: false, deactivated: true)
 
     res =
       conn
@@ -49,6 +50,14 @@ defmodule Pleroma.Web.MongooseIMController do
 
     assert res == false
 
+    res =
+      conn
+      |> get(mongoose_im_path(conn, :check_password), user: "konata", pass: "1337")
+      |> json_response(404)
+
+    assert res == false
+
+
     res =
       conn
       |> get(mongoose_im_path(conn, :check_password), user: "nobody", pass: "cool")