From e55c6f311b8f459402134351230a5ff9700a8ff0 Mon Sep 17 00:00:00 2001 From: Thog Date: Sun, 20 May 2018 18:05:34 +0200 Subject: Migrate to comeonin 4 and Cachex 3 Also fix some warning in the code and add a missing alias --- test/web/twitter_api/views/notification_view_test.exs | 2 +- test/web/twitter_api/views/user_view_test.exs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'test/web/twitter_api') diff --git a/test/web/twitter_api/views/notification_view_test.exs b/test/web/twitter_api/views/notification_view_test.exs index e3b140657..79eafda7d 100644 --- a/test/web/twitter_api/views/notification_view_test.exs +++ b/test/web/twitter_api/views/notification_view_test.exs @@ -24,7 +24,7 @@ defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do {:ok, follower} = User.follow(follower, user) {:ok, activity} = ActivityPub.follow(follower, user) - Cachex.set(:user_cache, "user_info:#{user.id}", User.user_info(Repo.get!(User, user.id))) + Cachex.put(:user_cache, "user_info:#{user.id}", User.user_info(Repo.get!(User, user.id))) [follow_notif] = Notification.for_user(user) represented = %{ diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs index dd55c0b7e..9f8bf4cdc 100644 --- a/test/web/twitter_api/views/user_view_test.exs +++ b/test/web/twitter_api/views/user_view_test.exs @@ -31,7 +31,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do User.follow(second_follower, user) User.follow(user, follower) {:ok, user} = User.update_follower_count(user) - Cachex.set(:user_cache, "user_info:#{user.id}", User.user_info(Repo.get!(User, user.id))) + Cachex.put(:user_cache, "user_info:#{user.id}", User.user_info(Repo.get!(User, user.id))) image = "http://localhost:4001/images/avi.png" banner = "http://localhost:4001/images/banner.png" -- cgit v1.2.3 From d0690622cdb885005444848a7db34bf89151e803 Mon Sep 17 00:00:00 2001 From: Syldexia Date: Mon, 21 May 2018 22:17:34 +0100 Subject: Added endpoint for changing passwords --- .../twitter_api/twitter_api_controller_test.exs | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) (limited to 'test/web/twitter_api') diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 02aba0bc8..73443e053 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -8,6 +8,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do alias Pleroma.Web.TwitterAPI.NotificationView alias Pleroma.Web.CommonAPI alias Pleroma.Web.TwitterAPI.TwitterAPI + alias Comeonin.Pbkdf2 import Pleroma.Factory @@ -801,6 +802,82 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do assert user.bio == "Hello,
World! I
am a test." end + describe "POST /api/pleroma/change_password" do + setup [:valid_user] + + test "without credentials", %{conn: conn} do + conn = post(conn, "/api/pleroma/change_password") + assert json_response(conn, 403) == %{"error" => "Invalid credentials."} + end + + test "with credentials and invalid password", %{conn: conn, user: current_user} do + conn = + conn + |> with_credentials(current_user.nickname, "test") + |> post("/api/pleroma/change_password", %{ + "password" => "hi", + "new_password" => "newpass", + "new_password_confirmation" => "newpass" + }) + + assert json_response(conn, 200) == %{"error" => "Invalid password."} + end + + test "with credentials, valid password and new password and confirmation not matching", %{ + conn: conn, + user: current_user + } do + conn = + conn + |> with_credentials(current_user.nickname, "test") + |> post("/api/pleroma/change_password", %{ + "password" => "test", + "new_password" => "newpass", + "new_password_confirmation" => "notnewpass" + }) + + assert json_response(conn, 200) == %{ + "error" => "New password does not match confirmation." + } + end + + test "with credentials, valid password and invalid new password", %{ + conn: conn, + user: current_user + } do + conn = + conn + |> with_credentials(current_user.nickname, "test") + |> post("/api/pleroma/change_password", %{ + "password" => "test", + "new_password" => "", + "new_password_confirmation" => "" + }) + + assert json_response(conn, 200) == %{ + "error" => "New password can't be blank." + } + end + + test "with credentials, valid password and matching new password and confirmation", %{ + conn: conn, + user: current_user + } do + conn = + conn + |> with_credentials(current_user.nickname, "test") + |> post("/api/pleroma/change_password", %{ + "password" => "test", + "new_password" => "newpass", + "new_password_confirmation" => "newpass" + }) + + assert json_response(conn, 200) == %{"status" => "success"} + fetched_user = Repo.get(User, current_user.id) + assert Pbkdf2.checkpw("newpass", fetched_user.password_hash) == true + end + end + describe "POST /api/pleroma/delete_account" do setup [:valid_user] -- cgit v1.2.3 From 72b93d13f8208f22f9a771dc8ba18c474fc81849 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Tue, 22 May 2018 05:41:17 -0400 Subject: Hook up block/unblock to TwitterAPI --- test/web/twitter_api/twitter_api_controller_test.exs | 2 +- test/web/twitter_api/twitter_api_test.exs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'test/web/twitter_api') diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 02aba0bc8..625303b84 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -443,7 +443,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do test "with credentials", %{conn: conn, user: current_user} do blocked = insert(:user) - {:ok, current_user} = User.block(current_user, blocked) + {:ok, current_user, blocked} = TwitterAPI.block(current_user, %{"user_id" => blocked.id}) assert User.blocks?(current_user, blocked) conn = diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index af565c0e5..4716abb84 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -166,7 +166,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do test "Unblock another user using user_id" do unblocked = insert(:user) user = insert(:user) - User.block(user, unblocked) + {:ok, user, _unblocked} = TwitterAPI.block(user, %{"user_id" => unblocked.id}) {:ok, user, _unblocked} = TwitterAPI.unblock(user, %{"user_id" => unblocked.id}) assert user.info["blocks"] == [] @@ -175,7 +175,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do test "Unblock another user using screen_name" do unblocked = insert(:user) user = insert(:user) - User.block(user, unblocked) + {:ok, user, _unblocked} = TwitterAPI.block(user, %{"screen_name" => unblocked.nickname}) {:ok, user, _unblocked} = TwitterAPI.unblock(user, %{"screen_name" => unblocked.nickname}) assert user.info["blocks"] == [] -- cgit v1.2.3