Correctly handle invalid credentials on auth login.
authorlain <lain@soykaf.club>
Mon, 28 Jan 2019 10:41:47 +0000 (11:41 +0100)
committerlain <lain@soykaf.club>
Mon, 28 Jan 2019 10:41:47 +0000 (11:41 +0100)
Closes #407

lib/pleroma/web/oauth/fallback_controller.ex
test/web/oauth/oauth_controller_test.exs

index 1eeda3d245a2cba087413b8b0f7bc4f81fa8d9eb..f0fe3b5785b11902d02cf852d625d7f1fc2e3668 100644 (file)
@@ -9,7 +9,8 @@ defmodule Pleroma.Web.OAuth.FallbackController do
   # No user/password
   def call(conn, _) do
     conn
+    |> put_status(:unauthorized)
     |> put_flash(:error, "Invalid Username/Password")
-    |> OAuthController.authorize(conn.params)
+    |> OAuthController.authorize(conn.params["authorization"])
   end
 end
index ccd55225859fa699fda02cdf41426ace62155fe9..e0d3cb55f916d0ccafc777457251028db12e90bf 100644 (file)
@@ -34,6 +34,31 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
     assert Repo.get_by(Authorization, token: code)
   end
 
+  test "correctly handles wrong credentials", %{conn: conn} do
+    user = insert(:user)
+    app = insert(:oauth_app)
+
+    result =
+      conn
+      |> post("/oauth/authorize", %{
+        "authorization" => %{
+          "name" => user.nickname,
+          "password" => "wrong",
+          "client_id" => app.client_id,
+          "redirect_uri" => app.redirect_uris,
+          "state" => "statepassed"
+        }
+      })
+      |> html_response(:unauthorized)
+
+    # Keep the details
+    assert result =~ app.client_id
+    assert result =~ app.redirect_uris
+
+    # Error message
+    assert result =~ "Invalid"
+  end
+
   test "issues a token for an all-body request" do
     user = insert(:user)
     app = insert(:oauth_app)