1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.TwitterAPI.PasswordControllerTest do
6 use Pleroma.Web.ConnCase
8 alias Pleroma.PasswordResetToken
10 alias Pleroma.Web.OAuth.Token
11 import Pleroma.Factory
13 describe "GET /api/pleroma/password_reset/token" do
14 test "it returns error when token invalid", %{conn: conn} do
17 |> get("/api/pleroma/password_reset/token")
20 assert response =~ "<h2>Invalid Token</h2>"
23 test "it shows password reset form", %{conn: conn} do
25 {:ok, token} = PasswordResetToken.create_token(user)
29 |> get("/api/pleroma/password_reset/#{token.token}")
32 assert response =~ "<h2>Password Reset for #{user.nickname}</h2>"
36 describe "POST /api/pleroma/password_reset" do
37 test "it returns HTTP 200", %{conn: conn} do
39 {:ok, token} = PasswordResetToken.create_token(user)
40 {:ok, _access_token} = Token.create_token(insert(:oauth_app), user, %{})
44 password_confirmation: "test",
50 |> assign(:user, user)
51 |> post("/api/pleroma/password_reset", %{data: params})
54 assert response =~ "<h2>Password changed!</h2>"
56 user = refresh_record(user)
57 assert Pbkdf2.verify_pass("test", user.password_hash)
58 assert Enum.empty?(Token.get_user_tokens(user))
61 test "it sets password_reset_pending to false", %{conn: conn} do
62 user = insert(:user, password_reset_pending: true)
64 {:ok, token} = PasswordResetToken.create_token(user)
65 {:ok, _access_token} = Token.create_token(insert(:oauth_app), user, %{})
69 password_confirmation: "test",
74 |> assign(:user, user)
75 |> post("/api/pleroma/password_reset", %{data: params})
78 assert User.get_by_id(user.id).password_reset_pending == false