1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 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
9 alias Pleroma.Web.OAuth.Token
10 import Pleroma.Factory
12 describe "GET /api/pleroma/password_reset/token" do
13 test "it returns error when token invalid", %{conn: conn} do
16 |> get("/api/pleroma/password_reset/token")
19 assert response =~ "<h2>Invalid Token</h2>"
22 test "it shows password reset form", %{conn: conn} do
24 {:ok, token} = PasswordResetToken.create_token(user)
28 |> get("/api/pleroma/password_reset/#{token.token}")
31 assert response =~ "<h2>Password Reset for #{user.nickname}</h2>"
35 describe "POST /api/pleroma/password_reset" do
36 test "it returns HTTP 200", %{conn: conn} do
38 {:ok, token} = PasswordResetToken.create_token(user)
39 {:ok, _access_token} = Token.create_token(insert(:oauth_app), user, %{})
43 password_confirmation: "test",
49 |> assign(:user, user)
50 |> post("/api/pleroma/password_reset", %{data: params})
53 assert response =~ "<h2>Password changed!</h2>"
55 user = refresh_record(user)
56 assert Comeonin.Pbkdf2.checkpw("test", user.password_hash)
57 assert length(Token.get_user_tokens(user)) == 0