aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/fixtures/httpoison_mock/status.alpicola.com_host_meta2
-rw-r--r--test/support/factory.ex3
-rw-r--r--test/support/httpoison_mock.ex8
-rw-r--r--test/web/common_api/common_api_test.exs13
-rw-r--r--test/web/common_api/common_api_utils_test.exs5
-rw-r--r--test/web/twitter_api/twitter_api_controller_test.exs77
-rw-r--r--test/web/twitter_api/views/notification_view_test.exs2
-rw-r--r--test/web/twitter_api/views/user_view_test.exs2
-rw-r--r--test/web/web_finger/web_finger_test.exs6
9 files changed, 112 insertions, 6 deletions
diff --git a/test/fixtures/httpoison_mock/status.alpicola.com_host_meta b/test/fixtures/httpoison_mock/status.alpicola.com_host_meta
new file mode 100644
index 000000000..6948c30ea
--- /dev/null
+++ b/test/fixtures/httpoison_mock/status.alpicola.com_host_meta
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><hm:Host xmlns:hm="http://host-meta.net/xrd/1.0">status.alpicola.com</hm:Host><Link rel="lrdd" template="http://status.alpicola.com/main/xrd?uri={uri}"><Title>Resource Descriptor</Title></Link></XRD> \ No newline at end of file
diff --git a/test/support/factory.ex b/test/support/factory.ex
index 8e21e2562..b2e98c8d1 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -95,7 +95,8 @@ defmodule Pleroma.Factory do
}
%Pleroma.Activity{
- data: data
+ data: data,
+ actor: follower.ap_id
}
end
diff --git a/test/support/httpoison_mock.ex b/test/support/httpoison_mock.ex
index f28557975..6e8336a93 100644
--- a/test/support/httpoison_mock.ex
+++ b/test/support/httpoison_mock.ex
@@ -531,6 +531,14 @@ defmodule HTTPoisonMock do
}}
end
+ def get("http://status.alpicola.com/.well-known/host-meta", [], follow_redirect: true) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/status.alpicola.com_host_meta")
+ }}
+ end
+
def get("http://macgirvin.com/.well-known/host-meta", [], follow_redirect: true) do
{:ok,
%Response{
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
new file mode 100644
index 000000000..b597e6e0a
--- /dev/null
+++ b/test/web/common_api/common_api_test.exs
@@ -0,0 +1,13 @@
+defmodule Pleroma.Web.CommonAPI.UtilsTest do
+ use Pleroma.DataCase
+ alias Pleroma.Web.CommonAPI
+
+ import Pleroma.Factory
+
+ test "it de-duplicates tags" do
+ user = insert(:user)
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu #2HU"})
+
+ assert activity.data["object"]["tag"] == ["2hu"]
+ end
+end
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index 23cce471f..f39472ee3 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -21,13 +21,12 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
test "incorrect password given" do
{:ok, user} = UserBuilder.insert()
- assert Utils.confirm_current_password(user, %{"password" => ""}) ==
- {:error, "Invalid password."}
+ assert Utils.confirm_current_password(user, "") == {:error, "Invalid password."}
end
test "correct password given" do
{:ok, user} = UserBuilder.insert()
- assert Utils.confirm_current_password(user, %{"password" => "test"}) == {:ok, user}
+ assert Utils.confirm_current_password(user, "test") == {:ok, user}
end
end
end
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 625303b84..c2ea41aa3 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,<br>World! I<br> 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]
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"
diff --git a/test/web/web_finger/web_finger_test.exs b/test/web/web_finger/web_finger_test.exs
index 2d6ff2656..99bf210ea 100644
--- a/test/web/web_finger/web_finger_test.exs
+++ b/test/web/web_finger/web_finger_test.exs
@@ -88,6 +88,12 @@ defmodule Pleroma.Web.WebFingerTest do
assert template == "https://macgirvin.com/xrd/?uri={uri}"
end
+
+ test "it gets the xrd endpoint for statusnet" do
+ {:ok, template} = WebFinger.find_lrdd_template("status.alpicola.com")
+
+ assert template == "http://status.alpicola.com/main/xrd?uri={uri}"
+ end
end
describe "ensure_keys_present" do