From 5b0d0b9ab2e9efba3d170a06ea3cc5c4ca33c2c9 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Sat, 14 Apr 2018 22:34:06 -0400 Subject: Add unreblogging tests --- test/web/activity_pub/activity_pub_test.exs | 20 ++++++++++++++++++++ .../mastodon_api/mastodon_api_controller_test.exs | 19 +++++++++++++++++++ 2 files changed, 39 insertions(+) (limited to 'test') diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 657d75a55..84f844322 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -271,6 +271,26 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do end end + describe "unannouncing an object" do + test "unannouncing a previously announced object" do + note_activity = insert(:note_activity) + object = Object.get_by_ap_id(note_activity.data["object"]["id"]) + user = insert(:user) + + # Unannouncing an object that is not announced does nothing + {:ok, object} = ActivityPub.unannounce(user, object) + assert object.data["announcement_count"] == 0 + + {:ok, announce_activity, object} = ActivityPub.announce(user, object) + assert object.data["announcement_count"] == 1 + + {:ok, object} = ActivityPub.unannounce(user, object) + assert object.data["announcement_count"] == 0 + + assert Repo.get(Activity, announce_activity.id) == nil + end + end + describe "uploading files" do test "copies the file to the configured folder" do file = %Plug.Upload{ diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 5293b9364..f3a9c1def 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -264,6 +264,25 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do end end + describe "unreblogging" do + test "unreblogs and returns the unreblogged status", %{conn: conn} do + activity = insert(:note_activity) + user = insert(:user) + + {:ok, _, _} = CommonAPI.repeat(activity.id, user) + + conn = + conn + |> assign(:user, user) + |> post("/api/v1/statuses/#{activity.id}/unreblog") + + assert %{"reblog" => %{"id" => id, "reblogged" => false, "reblogs_count" => 0}} = + json_response(conn, 200) + + assert to_string(activity.id) == id + end + end + describe "favoriting" do test "favs a status and returns it", %{conn: conn} do activity = insert(:note_activity) -- cgit v1.2.3 From 42279f54cfa6b1728f71de0a14cfde8e615141e7 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Mon, 16 Apr 2018 23:30:52 -0400 Subject: Return target status in MastoAPI endpoint instead of reblog activity --- test/web/mastodon_api/mastodon_api_controller_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index f3a9c1def..2a24037d7 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -276,7 +276,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do |> assign(:user, user) |> post("/api/v1/statuses/#{activity.id}/unreblog") - assert %{"reblog" => %{"id" => id, "reblogged" => false, "reblogs_count" => 0}} = + assert %{"id" => id, "reblogged" => false, "reblogs_count" => 0} = json_response(conn, 200) assert to_string(activity.id) == id -- cgit v1.2.3 From 687db1bc3a13d3303865a104f0475a6fc4671037 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Wed, 18 Apr 2018 03:39:42 -0400 Subject: Expose unannounce activity so that it can be tested --- test/web/activity_pub/activity_pub_test.exs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 84f844322..85a6aecf0 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -278,15 +278,24 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do user = insert(:user) # Unannouncing an object that is not announced does nothing - {:ok, object} = ActivityPub.unannounce(user, object) - assert object.data["announcement_count"] == 0 + #{:ok, object} = ActivityPub.unannounce(user, object) + #assert object.data["announcement_count"] == 0 {:ok, announce_activity, object} = ActivityPub.announce(user, object) assert object.data["announcement_count"] == 1 - {:ok, object} = ActivityPub.unannounce(user, object) + {:ok, unannounce_activity, object} = ActivityPub.unannounce(user, object) assert object.data["announcement_count"] == 0 + assert unannounce_activity.data["to"] == [ + User.ap_followers(user), + note_activity.data["actor"] + ] + assert unannounce_activity.data["type"] == "Undo" + assert unannounce_activity.data["object"] == object.data["id"] + assert unannounce_activity.data["actor"] == user.ap_id + assert unannounce_activity.data["context"] == object.data["context"] + assert Repo.get(Activity, announce_activity.id) == nil end end -- cgit v1.2.3 From 7b4f55238eeb8561c6a8e43321cd965667cefabe Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Wed, 18 Apr 2018 06:00:40 -0400 Subject: Handle unrepeats via the TwitterAPI --- test/web/activity_pub/activity_pub_test.exs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 85a6aecf0..6a07da775 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -284,9 +284,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do {:ok, announce_activity, object} = ActivityPub.announce(user, object) assert object.data["announcement_count"] == 1 - {:ok, unannounce_activity, object} = ActivityPub.unannounce(user, object) + {:ok, unannounce_activity, activity, object} = ActivityPub.unannounce(user, object) assert object.data["announcement_count"] == 0 + assert activity == announce_activity + assert unannounce_activity.data["to"] == [ User.ap_followers(user), note_activity.data["actor"] -- cgit v1.2.3 From f0798440de96139f5717e90582e41ddb6ce5a0ce Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Fri, 20 Apr 2018 23:22:16 -0400 Subject: Use correct activity for undo --- test/web/activity_pub/activity_pub_test.exs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 6a07da775..e3258ed4e 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -291,12 +291,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do assert unannounce_activity.data["to"] == [ User.ap_followers(user), - note_activity.data["actor"] + announce_activity.data["actor"] ] assert unannounce_activity.data["type"] == "Undo" - assert unannounce_activity.data["object"] == object.data["id"] + assert unannounce_activity.data["object"] == announce_activity.data["id"] assert unannounce_activity.data["actor"] == user.ap_id - assert unannounce_activity.data["context"] == object.data["context"] + assert unannounce_activity.data["context"] == announce_activity.data["context"] assert Repo.get(Activity, announce_activity.id) == nil end -- cgit v1.2.3 From 8c0806539c1eac776db0634e2888927f1dd2141d Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Sun, 22 Apr 2018 21:28:51 -0400 Subject: Embed announce activity data instead of linking to it --- test/web/activity_pub/activity_pub_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index e3258ed4e..208cc42d2 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -292,9 +292,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do assert unannounce_activity.data["to"] == [ User.ap_followers(user), announce_activity.data["actor"] - ] + ] assert unannounce_activity.data["type"] == "Undo" - assert unannounce_activity.data["object"] == announce_activity.data["id"] + assert unannounce_activity.data["object"] == announce_activity.data assert unannounce_activity.data["actor"] == user.ap_id assert unannounce_activity.data["context"] == announce_activity.data["context"] -- cgit v1.2.3 From e981280fa74ddccb02c7deb27bd5cc5e85f9fc8f Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Wed, 25 Apr 2018 01:43:45 -0400 Subject: Formatting fixes --- test/web/activity_pub/activity_pub_test.exs | 7 ++++--- test/web/mastodon_api/mastodon_api_controller_test.exs | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 31ac10d70..d9f00613a 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -280,8 +280,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do user = insert(:user) # Unannouncing an object that is not announced does nothing - #{:ok, object} = ActivityPub.unannounce(user, object) - #assert object.data["announcement_count"] == 0 + # {:ok, object} = ActivityPub.unannounce(user, object) + # assert object.data["announcement_count"] == 0 {:ok, announce_activity, object} = ActivityPub.announce(user, object) assert object.data["announcement_count"] == 1 @@ -294,7 +294,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do assert unannounce_activity.data["to"] == [ User.ap_followers(user), announce_activity.data["actor"] - ] + ] + assert unannounce_activity.data["type"] == "Undo" assert unannounce_activity.data["object"] == announce_activity.data["id"] assert unannounce_activity.data["actor"] == user.ap_id diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 2a24037d7..14f8c3c42 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -276,8 +276,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do |> assign(:user, user) |> post("/api/v1/statuses/#{activity.id}/unreblog") - assert %{"id" => id, "reblogged" => false, "reblogs_count" => 0} = - json_response(conn, 200) + assert %{"id" => id, "reblogged" => false, "reblogs_count" => 0} = json_response(conn, 200) assert to_string(activity.id) == id end -- cgit v1.2.3 From 8b4ee0ea51431e268011781403bc97864b294989 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Fri, 4 May 2018 03:19:48 -0400 Subject: Fix formatting --- test/web/activity_pub/activity_pub_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 7735e1bf8..155965de8 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -295,7 +295,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do User.ap_followers(user), announce_activity.data["actor"] ] - + assert unannounce_activity.data["type"] == "Undo" assert unannounce_activity.data["object"] == announce_activity.data assert unannounce_activity.data["actor"] == user.ap_id -- cgit v1.2.3 From 89603eda9ea51c5bd3c681fce958a4a6b446debe Mon Sep 17 00:00:00 2001 From: Pierrick Brun Date: Mon, 7 May 2018 20:51:14 +0200 Subject: do not create notification for yourself --- test/notification_test.exs | 7 +++++++ test/web/twitter_api/twitter_api_controller_test.exs | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/notification_test.exs b/test/notification_test.exs index 568ad642c..2ca1ac13d 100644 --- a/test/notification_test.exs +++ b/test/notification_test.exs @@ -33,6 +33,13 @@ defmodule Pleroma.NotificationTest do assert nil == Notification.create_notification(activity, user) end + + test "it doesn't create a notification for user if he is the activity author" do + activity = insert(:note_activity) + author = User.get_by_ap_id(activity.data["actor"]) + + assert nil == Notification.create_notification(activity, author) + end end describe "get notification" do diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index d7113979a..896fe246d 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -257,8 +257,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do end test "with credentials", %{conn: conn, user: current_user} do + other_user = insert(:user) + {:ok, activity} = - ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: current_user}) + ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: other_user}) conn = conn -- cgit v1.2.3 From 16b793656d2eb79e19224462180d2d21fb57cc29 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Fri, 11 May 2018 15:30:47 -0400 Subject: Add tests for unrepeats --- test/fixtures/mastodon-undo-announce.json | 47 +++++++++++++++++++++++++++ test/web/activity_pub/transmogrifier_test.exs | 28 ++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 test/fixtures/mastodon-undo-announce.json (limited to 'test') diff --git a/test/fixtures/mastodon-undo-announce.json b/test/fixtures/mastodon-undo-announce.json new file mode 100644 index 000000000..2d8bca436 --- /dev/null +++ b/test/fixtures/mastodon-undo-announce.json @@ -0,0 +1,47 @@ +{ + "type": "Undo", + "signature": { + "type": "RsaSignature2017", + "signatureValue": "VU9AmHf3Pus9cWtMG/TOdxr+MRQfPHdTVKBBgFJBXhAlMhxEtcbxsu7zmqBgfIz6u0HpTCi5jRXEMftc228OJf/aBUkr4hyWADgcdmhPQgpibouDLgQf9BmnrPqb2rMbzZyt49GJkQZma8taLh077TTq6OKcnsAAJ1evEKOcRYS4OxBSwh4nI726bOXzZWoNzpTcrnm+llcUEN980sDSAS0uyZdb8AxZdfdG6DJQX4AkUD5qTpfqP/vC1ISirrNphvVhlxjUV9Amr4SYTsLx80vdZe5NjeL5Ir4jTIIQLedpxaDu1M9Q+Jpc0fYByQ2hOwUq8JxEmvHvarKjrq0Oww==", + "creator": "http://mastodon.example.org/users/admin#main-key", + "created": "2018-05-11T16:23:45Z" + }, + "object": { + "type": "Announce", + "to": [ + "http://www.w3.org/ns/activitystreams#Public" + ], + "published": "2018-05-11T16:23:37Z", + "object": "http://lostallofmy.faith/objects/acc592f0-093a-4326-856e-2ab30947ef11", + "id": "http://mastodon.example.org/users/admin/statuses/100011594053806179/activity", + "cc": [ + "http://lostallofmy.faith/users/admin", + "http://mastodon.example.org/users/admin/followers" + ], + "atomUri": "http://mastodon.example.org/users/admin/statuses/100011594053806179/activity", + "actor": "http://mastodon.example.org/users/admin" + }, + "id": "http://mastodon.example.org/users/admin#announces/100011594053806179/undo", + "actor": "http://mastodon.example.org/users/admin", + "@context": [ + "http://www.w3.org/ns/activitystreams", + "http://w3id.org/security/v1", + { + "toot": "http://joinmastodon.org/ns#", + "sensitive": "as:sensitive", + "ostatus": "http://ostatus.org#", + "movedTo": "as:movedTo", + "manuallyApprovesFollowers": "as:manuallyApprovesFollowers", + "inReplyToAtomUri": "ostatus:inReplyToAtomUri", + "focalPoint": { + "@id": "toot:focalPoint", + "@container": "@list" + }, + "featured": "toot:featured", + "conversation": "ostatus:conversation", + "atomUri": "ostatus:atomUri", + "Hashtag": "as:Hashtag", + "Emoji": "toot:Emoji" + } + ] +} diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index eb093262f..a3408da9d 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -232,6 +232,34 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do refute Repo.get(Activity, activity.id) end + + test "it works for incoming unannounces with an existing notice" do + user = insert(:user) + {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"}) + + announce_data = + File.read!("test/fixtures/mastodon-announce.json") + |> Poison.decode!() + |> Map.put("object", activity.data["object"]["id"]) + + {:ok, %Activity{data: announce_data, local: false}} = + Transmogrifier.handle_incoming(announce_data) + + data = + File.read!("test/fixtures/mastodon-undo-announce.json") + |> Poison.decode!() + |> Map.put("object", announce_data) + |> Map.put("actor", announce_data["actor"]) + + {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) + + assert data["type"] == "Undo" + assert data["object"]["type"] == "Announce" + assert data["object"]["object"] == activity.data["object"]["id"] + + assert data["object"]["id"] == + "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity" + end end describe "prepare outgoing" do -- cgit v1.2.3 From 694e3769542ae661d3967c1c03d24be0496d98cc Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Sat, 12 May 2018 11:10:49 -0400 Subject: Update test fixture --- test/fixtures/mastodon-undo-announce.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/fixtures/mastodon-undo-announce.json b/test/fixtures/mastodon-undo-announce.json index 2d8bca436..05332bed2 100644 --- a/test/fixtures/mastodon-undo-announce.json +++ b/test/fixtures/mastodon-undo-announce.json @@ -12,13 +12,13 @@ "http://www.w3.org/ns/activitystreams#Public" ], "published": "2018-05-11T16:23:37Z", - "object": "http://lostallofmy.faith/objects/acc592f0-093a-4326-856e-2ab30947ef11", - "id": "http://mastodon.example.org/users/admin/statuses/100011594053806179/activity", + "object": "http://mastodon.example.org/@admin/99541947525187367", + "id": "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity", "cc": [ - "http://lostallofmy.faith/users/admin", + "http://mastodon.example.org/users/admin", "http://mastodon.example.org/users/admin/followers" ], - "atomUri": "http://mastodon.example.org/users/admin/statuses/100011594053806179/activity", + "atomUri": "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity", "actor": "http://mastodon.example.org/users/admin" }, "id": "http://mastodon.example.org/users/admin#announces/100011594053806179/undo", -- cgit v1.2.3 From ec531ca281008e7d8d9d659e6f046a551fcb7c8a Mon Sep 17 00:00:00 2001 From: lain Date: Sun, 13 May 2018 11:18:48 +0200 Subject: Add test. --- test/web/activity_pub/activity_pub_test.exs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test') diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 6d23adfcd..d336fad95 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -171,6 +171,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do end describe "public fetch activities" do + test "doesn't retrieve unlisted activities" do + user = insert(:user) + {:ok, unlisted_activity} = CommonAPI.post(user, %{"status" => "yeah", "visibility" => "unlisted"}) + {:ok, listed_activity} = CommonAPI.post(user, %{"status" => "yeah"}) + + [activity] = ActivityPub.fetch_public_activities() + + assert activity == listed_activity + end + test "retrieves public activities" do _activities = ActivityPub.fetch_public_activities() -- cgit v1.2.3 From 1027d1f6963b495a5abc67b05447619ce7d429db Mon Sep 17 00:00:00 2001 From: lain Date: Sun, 13 May 2018 12:07:11 +0200 Subject: Remove 'unlisted' handling for now. It's just too slow (over 1 second on small systems, haven't looked at the queries in detail yet). We'll need some other way to handle it. --- test/web/activity_pub/activity_pub_test.exs | 1 + 1 file changed, 1 insertion(+) (limited to 'test') diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index a39ba9adb..c4b59f5c7 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -171,6 +171,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do end describe "public fetch activities" do + @tag :skip test "doesn't retrieve unlisted activities" do user = insert(:user) {:ok, unlisted_activity} = CommonAPI.post(user, %{"status" => "yeah", "visibility" => "unlisted"}) -- cgit v1.2.3 From c7a85de35c3ef8cfca447ffdb85cd929258642df Mon Sep 17 00:00:00 2001 From: lain Date: Sun, 13 May 2018 12:38:13 +0200 Subject: Revert "Remove 'unlisted' handling for now." This reverts commit 1027d1f6963b495a5abc67b05447619ce7d429db. --- test/web/activity_pub/activity_pub_test.exs | 1 - 1 file changed, 1 deletion(-) (limited to 'test') diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index c4b59f5c7..a39ba9adb 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -171,7 +171,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do end describe "public fetch activities" do - @tag :skip test "doesn't retrieve unlisted activities" do user = insert(:user) {:ok, unlisted_activity} = CommonAPI.post(user, %{"status" => "yeah", "visibility" => "unlisted"}) -- cgit v1.2.3 From 89954a2ce7a5003c539650112c974d1d05908e27 Mon Sep 17 00:00:00 2001 From: lain Date: Sun, 13 May 2018 13:02:24 +0200 Subject: Fix format. --- test/web/activity_pub/activity_pub_test.exs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index a39ba9adb..c1ba626b7 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -173,7 +173,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do describe "public fetch activities" do test "doesn't retrieve unlisted activities" do user = insert(:user) - {:ok, unlisted_activity} = CommonAPI.post(user, %{"status" => "yeah", "visibility" => "unlisted"}) + + {:ok, unlisted_activity} = + CommonAPI.post(user, %{"status" => "yeah", "visibility" => "unlisted"}) + {:ok, listed_activity} = CommonAPI.post(user, %{"status" => "yeah"}) [activity] = ActivityPub.fetch_public_activities() -- cgit v1.2.3 From a16117225f9a4da9da08013ae256d8ac02ee3ec5 Mon Sep 17 00:00:00 2001 From: Syldexia Date: Fri, 11 May 2018 12:32:59 +0100 Subject: Added endpoint for user account deletion --- test/web/common_api/common_api_utils_test.exs | 20 ++++++++++++ .../twitter_api/twitter_api_controller_test.exs | 36 ++++++++++++++++++++++ 2 files changed, 56 insertions(+) (limited to 'test') diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs index 689bdd61e..d59864c43 100644 --- a/test/web/common_api/common_api_utils_test.exs +++ b/test/web/common_api/common_api_utils_test.exs @@ -1,5 +1,6 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do alias Pleroma.Web.CommonAPI.Utils + alias Pleroma.Builders.{UserBuilder} use Pleroma.DataCase test "it adds attachment links to a given text and attachment set" do @@ -15,4 +16,23 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do assert res == "
Sakura Mana – Turned on by a Se…" end + + describe "it confirms the password given is the current users password" do + test "with no credentials" do + assert Utils.confirm_current_password(nil, %{"password" => "test"}) == + {:error, "Invalid credentials."} + end + + test "with incorrect password given" do + {:ok, user} = UserBuilder.insert() + + assert Utils.confirm_current_password(user, %{"password" => ""}) == + {:error, "Invalid password."} + end + + test "with correct password given" do + {:ok, user} = UserBuilder.insert() + assert Utils.confirm_current_password(user, %{"password" => "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 896fe246d..a9350d189 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -800,4 +800,40 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do user = Repo.get!(User, user.id) assert user.bio == "Hello,
World! I
am a test." end + + describe "POST /api/account/delete_account" do + setup [:valid_user] + + test "without credentials", %{conn: conn} do + conn = post(conn, "/api/account/delete_account") + 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/account/delete_account", %{ + "password" => "" + }) + + assert json_response(conn, 403) == %{ + "error" => "Invalid password.", + "request" => "/api/account/delete_account" + } + end + + test "with credentials and valid password", %{conn: conn, user: current_user} do + conn = + conn + |> with_credentials(current_user.nickname, "test") + |> post("/api/account/delete_account", %{ + "password" => "test" + }) + + assert json_response(conn, 200) == %{"status" => "success"} + fetched_user = Repo.get(User, current_user.id) + assert fetched_user.info == %{"deactivated" => true} + end + end end -- cgit v1.2.3 From 5bfb7b4ce6c23f84c27643e9871b78b867f86b7e Mon Sep 17 00:00:00 2001 From: Syldexia Date: Sun, 13 May 2018 14:24:15 +0100 Subject: Moved account deletion stuff to somewhere that hopefully makes more sense --- test/web/twitter_api/twitter_api_controller_test.exs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'test') diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index a9350d189..170dda145 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -801,11 +801,11 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do assert user.bio == "Hello,
World! I
am a test." end - describe "POST /api/account/delete_account" do + describe "POST /api/pleroma/delete_account" do setup [:valid_user] test "without credentials", %{conn: conn} do - conn = post(conn, "/api/account/delete_account") + conn = post(conn, "/api/pleroma/delete_account") assert json_response(conn, 403) == %{"error" => "Invalid credentials."} end @@ -813,23 +813,16 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do conn = conn |> with_credentials(current_user.nickname, "test") - |> post("/api/account/delete_account", %{ - "password" => "" - }) + |> post("/api/pleroma/delete_account", %{"password" => "hi"}) - assert json_response(conn, 403) == %{ - "error" => "Invalid password.", - "request" => "/api/account/delete_account" - } + assert json_response(conn, 200) == %{"error" => "Invalid password."} end test "with credentials and valid password", %{conn: conn, user: current_user} do conn = conn |> with_credentials(current_user.nickname, "test") - |> post("/api/account/delete_account", %{ - "password" => "test" - }) + |> post("/api/pleroma/delete_account", %{"password" => "test"}) assert json_response(conn, 200) == %{"status" => "success"} fetched_user = Repo.get(User, current_user.id) -- cgit v1.2.3 From 98b36d359a1a8c10ef9877902258d46b68331363 Mon Sep 17 00:00:00 2001 From: Syldexia Date: Sun, 13 May 2018 14:56:59 +0100 Subject: Fixed formatting and test --- test/web/common_api/common_api_utils_test.exs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs index d59864c43..23cce471f 100644 --- a/test/web/common_api/common_api_utils_test.exs +++ b/test/web/common_api/common_api_utils_test.exs @@ -18,19 +18,14 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do end describe "it confirms the password given is the current users password" do - test "with no credentials" do - assert Utils.confirm_current_password(nil, %{"password" => "test"}) == - {:error, "Invalid credentials."} - end - - test "with incorrect password given" do + test "incorrect password given" do {:ok, user} = UserBuilder.insert() assert Utils.confirm_current_password(user, %{"password" => ""}) == {:error, "Invalid password."} end - test "with correct password given" do + test "correct password given" do {:ok, user} = UserBuilder.insert() assert Utils.confirm_current_password(user, %{"password" => "test"}) == {:ok, user} end -- cgit v1.2.3 From 1d4bbec6b3239bb83b500a6a90e6686cb682cfac Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 16 May 2018 17:55:20 +0200 Subject: Fix User search. Now uses a trigram based search. This is a lot faster and gives better results. Closes #185. --- .../mastodon_api/mastodon_api_controller_test.exs | 23 +++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 882c92682..8d79c96b1 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -609,16 +609,29 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do test "account search", %{conn: conn} do user = insert(:user) - _user_two = insert(:user, %{nickname: "shp@shitposter.club"}) + user_two = insert(:user, %{nickname: "shp@shitposter.club"}) user_three = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"}) - conn = + results = + conn + |> assign(:user, user) + |> get("/api/v1/accounts/search", %{"q" => "shp"}) + |> json_response(200) + + result_ids = for result <- results, do: result["acct"] + + assert user_two.nickname in result_ids + assert user_three.nickname in result_ids + + results = conn |> assign(:user, user) |> get("/api/v1/accounts/search", %{"q" => "2hu"}) + |> json_response(200) - assert [account] = json_response(conn, 200) - assert account["id"] == to_string(user_three.id) + result_ids = for result <- results, do: result["acct"] + + assert user_three.nickname in result_ids end test "search", %{conn: conn} do @@ -642,7 +655,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do assert results = json_response(conn, 200) - [account] = results["accounts"] + [account | _] = results["accounts"] assert account["id"] == to_string(user_three.id) assert results["hashtags"] == [] -- cgit v1.2.3 From f32e19f66881ed0939d83e2810c29081d5b11e16 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 19 May 2018 06:11:45 +0000 Subject: webfinger: add tests --- test/fixtures/httpoison_mock/kaniini@gerzilla.de.json | 1 + test/support/httpoison_mock.ex | 12 ++++++++++++ test/web/web_finger/web_finger_test.exs | 8 ++++++++ 3 files changed, 21 insertions(+) create mode 100644 test/fixtures/httpoison_mock/kaniini@gerzilla.de.json (limited to 'test') diff --git a/test/fixtures/httpoison_mock/kaniini@gerzilla.de.json b/test/fixtures/httpoison_mock/kaniini@gerzilla.de.json new file mode 100644 index 000000000..be2f69b18 --- /dev/null +++ b/test/fixtures/httpoison_mock/kaniini@gerzilla.de.json @@ -0,0 +1 @@ +{"subject":"acct:kaniini","aliases":["https:\/\/gerzilla.de\/channel\/kaniini","https:\/\/gerzilla.de\/~kaniini","acct:kaniini@gerzilla.de"],"properties":{"http:\/\/webfinger.net\/ns\/name":"kaniini","http:\/\/xmlns.com\/foaf\/0.1\/name":"kaniini","https:\/\/w3id.org\/security\/v1#publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAvXCDkQPw+1N8B2CUd5s2\nbYvjHt+t7soMNfUiRy0qGbgW46S45k5lCq1KpbFIX3sgGZ4OWjnXVbvjCJi4kl5M\nfm5DBXzpuu05AmjVl8hqk4GejajiE\/1Nq0uWHPiOSFWispUjCzzCu65V+IsiE5JU\nvcL6WEf\/pYNRq7gYqyT693F7+cO5\/rVv9OScx5UOxbIuU1VXYhdHCqAMDJWadC89\nhePrcD3HOQKl06W2tDxHcWk6QjrdsUQGbNOgK\/QIN9gSxA+rCFEvH5O0HAhI0aXq\ncOB+vysJUFLeQOAqmAKvKS5V6RqE1GqqT0pDWHack4EmQi0gkgVzo+45xoP6wfDl\nWwG88w21LNxGvGHuN4I8mg6cEoApqKQBSOj086UtfDfSlPC1B+PRD2phE5etucHd\nF\/RIWN3SxVzU9BKIiaDm2gwOpvI8QuorQb6HDtZFO5NsSN3PnMnSywPe7kXl\/469\nuQRYXrseqyOVIi6WjhvXkyWVKVE5CBz+S8wXHfKph+9YOyUcJeAVMijp9wrjBlMc\noSzOGu79oM7tpMSq\/Xo6ePJ\/glNOwZR+OKrg92Qp9BGTKDNwGrxuxP\/9KwWtGLNf\nOMTtIkxtC3ubhxL3lBxOd7l+Bmum0UJV2f8ogkCgvTpIz05jMoyU8qWl6kkWNQlY\nDropXWaOfy7Lac+G4qlfSgsCAwEAAQ==\n-----END PUBLIC KEY-----\n","http:\/\/purl.org\/zot\/federation":"zot,activitypub"},"links":[{"rel":"http:\/\/webfinger.net\/rel\/avatar","type":"image\/png","href":"https:\/\/gerzilla.de\/photo\/profile\/l\/281"},{"rel":"http:\/\/microformats.org\/profile\/hcard","type":"text\/html","href":"https:\/\/gerzilla.de\/hcard\/kaniini"},{"rel":"http:\/\/webfinger.net\/rel\/profile-page","href":"https:\/\/gerzilla.de\/profile\/kaniini"},{"rel":"http:\/\/schemas.google.com\/g\/2010#updates-from","type":"application\/atom+xml","href":"https:\/\/gerzilla.de\/ofeed\/kaniini"},{"rel":"http:\/\/webfinger.net\/rel\/blog","href":"https:\/\/gerzilla.de\/channel\/kaniini"},{"rel":"http:\/\/ostatus.org\/schema\/1.0\/subscribe","template":"https:\/\/gerzilla.de\/follow?f=&url={uri}"},{"rel":"http:\/\/purl.org\/zot\/protocol","href":"https:\/\/gerzilla.de\/.well-known\/zot-info?address=kaniini@gerzilla.de"},{"rel":"http:\/\/purl.org\/openwebauth\/v1","type":"application\/x-zot+json","href":"https:\/\/gerzilla.de\/owa"},{"rel":"magic-public-key","href":"data:application\/magic-public-key,RSA.AL1wg5ED8PtTfAdglHebNm2L4x7fre7KDDX1IkctKhm4FuOkuOZOZQqtSqWxSF97IBmeDlo511W74wiYuJJeTH5uQwV86brtOQJo1ZfIapOBno2o4hP9TatLlhz4jkhVorKVIws8wruuVfiLIhOSVL3C-lhH_6WDUau4GKsk-vdxe_nDuf61b_TknMeVDsWyLlNVV2IXRwqgDAyVmnQvPYXj63A9xzkCpdOltrQ8R3FpOkI63bFEBmzToCv0CDfYEsQPqwhRLx-TtBwISNGl6nDgfr8rCVBS3kDgKpgCrykuVekahNRqqk9KQ1h2nJOBJkItIJIFc6PuOcaD-sHw5VsBvPMNtSzcRrxh7jeCPJoOnBKAKaikAUjo9POlLXw30pTwtQfj0Q9qYROXrbnB3Rf0SFjd0sVc1PQSiImg5toMDqbyPELqK0G-hw7WRTuTbEjdz5zJ0ssD3u5F5f-OvbkEWF67HqsjlSIulo4b15MllSlROQgc_kvMFx3yqYfvWDslHCXgFTIo6fcK4wZTHKEszhru_aDO7aTEqv16Onjyf4JTTsGUfjiq4PdkKfQRkygzcBq8bsT__SsFrRizXzjE7SJMbQt7m4cS95QcTne5fgZrptFCVdn_KIJAoL06SM9OYzKMlPKlpepJFjUJWA66KV1mjn8uy2nPhuKpX0oL.AQAB"},{"rel":"self","type":"application\/ld+json; profile=\"https:\/\/www.w3.org\/ns\/activitystreams\"","href":"https:\/\/gerzilla.de\/channel\/kaniini"}]} diff --git a/test/support/httpoison_mock.ex b/test/support/httpoison_mock.ex index 4a5a9ea85..e733afa59 100644 --- a/test/support/httpoison_mock.ex +++ b/test/support/httpoison_mock.ex @@ -3,6 +3,18 @@ defmodule HTTPoisonMock do def get(url, body \\ [], headers \\ []) + def get( + "http://gerzilla.de/.well-known/webfinger?resource=acct:kaniini@gerzilla.de", + [Accept: "application/xrd+xml,application/jrd+json"], + follow_redirect: true + ) do + {:ok, + %Response{ + status_code: 200, + body: File.read!("test/fixtures/httpoison_mock/kaniini@gerzilla.de.json") + }} + end + def get( "http://framatube.org/.well-known/webfinger?resource=acct:framasoft@framatube.org", [Accept: "application/xrd+xml,application/jrd+json"], diff --git a/test/web/web_finger/web_finger_test.exs b/test/web/web_finger/web_finger_test.exs index 69216f393..2d6ff2656 100644 --- a/test/web/web_finger/web_finger_test.exs +++ b/test/web/web_finger/web_finger_test.exs @@ -49,6 +49,14 @@ defmodule Pleroma.Web.WebFingerTest do {:ok, _data} = WebFinger.finger(user) end + test "returns the ActivityPub actor URI for an ActivityPub user with the ld+json mimetype" do + user = "kaniini@gerzilla.de" + + {:ok, data} = WebFinger.finger(user) + + assert data["ap_id"] == "https://gerzilla.de/channel/kaniini" + end + test "returns the correctly for json ostatus users" do user = "winterdienst@gnusocial.de" -- cgit v1.2.3 From 19c96c8a19aece5419bc0be5ea3e2945887828b7 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 19 May 2018 08:06:23 +0000 Subject: tests: add tests for Transmogrifier.maybe_fix_user_object() --- test/web/activity_pub/transmogrifier_test.exs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'test') diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index a3408da9d..b02d80cce 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -420,4 +420,15 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do assert Repo.get(WebsubClientSubscription, ws2.id) end end + + describe "actor rewriting" do + test "it fixes the actor URL property to be a proper URI" do + data = %{ + "url" => %{"href" => "http://example.com"} + } + + rewritten = Transmogrifier.maybe_fix_user_object(data) + assert rewritten["url"] == "http://example.com" + end + end end -- cgit v1.2.3 From 4033ed671443bbb4111b45473696dc8a23fe9873 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 19 May 2018 08:25:45 +0000 Subject: tests: add test for hubzilla follow activity too --- .../kaniini@hubzilla.example.org.json | 1 + test/fixtures/hubzilla-follow-activity.json | 31 ++++++++++++++++++++++ test/support/httpoison_mock.ex | 8 ++++++ test/web/activity_pub/transmogrifier_test.exs | 18 +++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 test/fixtures/httpoison_mock/kaniini@hubzilla.example.org.json create mode 100644 test/fixtures/hubzilla-follow-activity.json (limited to 'test') diff --git a/test/fixtures/httpoison_mock/kaniini@hubzilla.example.org.json b/test/fixtures/httpoison_mock/kaniini@hubzilla.example.org.json new file mode 100644 index 000000000..11c79e11e --- /dev/null +++ b/test/fixtures/httpoison_mock/kaniini@hubzilla.example.org.json @@ -0,0 +1 @@ +{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1","https://hubzilla.example.org/apschema/v1.2"],"type":"Person","id":"https://hubzilla.example.org/channel/kaniini","preferredUsername":"kaniini","name":"kaniini","icon":{"type":"Image","mediaType":"image/jpeg","url":"https://hubzilla.example.org/photo/profile/l/281","height":300,"width":300},"url":{"type":"Link","mediaType":"text/html","href":"https://hubzilla.example.org/channel/kaniini"},"inbox":"https://hubzilla.example.org/inbox/kaniini","outbox":"https://hubzilla.example.org/outbox/kaniini","followers":"https://hubzilla.example.org/followers/kaniini","following":"https://hubzilla.example.org/following/kaniini","endpoints":{"sharedInbox":"https://hubzilla.example.org/inbox"},"publicKey":{"id":"https://hubzilla.example.org/channel/kaniini/public_key_pem","owner":"https://hubzilla.example.org/channel/kaniini","publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAvXCDkQPw+1N8B2CUd5s2\nbYvjHt+t7soMNfUiRy0qGbgW46S45k5lCq1KpbFIX3sgGZ4OWjnXVbvjCJi4kl5M\nfm5DBXzpuu05AmjVl8hqk4GejajiE/1Nq0uWHPiOSFWispUjCzzCu65V+IsiE5JU\nvcL6WEf/pYNRq7gYqyT693F7+cO5/rVv9OScx5UOxbIuU1VXYhdHCqAMDJWadC89\nhePrcD3HOQKl06W2tDxHcWk6QjrdsUQGbNOgK/QIN9gSxA+rCFEvH5O0HAhI0aXq\ncOB+vysJUFLeQOAqmAKvKS5V6RqE1GqqT0pDWHack4EmQi0gkgVzo+45xoP6wfDl\nWwG88w21LNxGvGHuN4I8mg6cEoApqKQBSOj086UtfDfSlPC1B+PRD2phE5etucHd\nF/RIWN3SxVzU9BKIiaDm2gwOpvI8QuorQb6HDtZFO5NsSN3PnMnSywPe7kXl/469\nuQRYXrseqyOVIi6WjhvXkyWVKVE5CBz+S8wXHfKph+9YOyUcJeAVMijp9wrjBlMc\noSzOGu79oM7tpMSq/Xo6ePJ/glNOwZR+OKrg92Qp9BGTKDNwGrxuxP/9KwWtGLNf\nOMTtIkxtC3ubhxL3lBxOd7l+Bmum0UJV2f8ogkCgvTpIz05jMoyU8qWl6kkWNQlY\nDropXWaOfy7Lac+G4qlfSgsCAwEAAQ==\n-----END PUBLIC KEY-----\n"},"nomadicLocations":[{"id":"https://hubzilla.example.org/locs/kaniini","type":"nomadicLocation","locationAddress":"acct:kaniini@hubzilla.example.org","locationPrimary":true,"locationDeleted":false}],"signature":{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1"],"type":"RsaSignature2017","nonce":"6b981a2f3bdcffc20252e3b131d4a4569fd2dea9fac543e5196136302f492694","creator":"https://hubzilla.example.org/channel/kaniini/public_key_pem","created":"2018-05-19T08:19:13Z","signatureValue":"ezpT4iCIUzJSeJa/Jsf4EkgbX9enWZG/0eliLXZcvkeCX9mZabaX9LMQRViP2GSlAJBHJu+UqK5LWaoWw9pYkQQHUL+43w2DeBxQicEcPqpT46j6pHuWptfwB8YHTC2/Pb56Y/jseU37j+FW8xVmcGZk4cPqJRLQNojwJlQiFOpBEd4Cel6081W12Pep578+6xBL+h92RJsWznA1gE/NV9dkCqoAoNdiORJg68sVTm0yYxPit2D/DLwXUFeBhC47EZtY3DtAOf7rADGwbquXKug/wtEI47R4p9dJvMWERSVW9O2FmDk8deUjRR3qO1iYGce8O+uMnnBHmuTcToRUHH7mxfMdqjfbcZ9DGBjKtLPSOyVPT9rENeyX8fsksmX0XhfHsNSWkmeDaU5/Au3IY75gDewiGzmzLOpRc6GUnHHro7lMpyMuo3lLZKjNVsFZbx+sXCYwORz5GAMuwIt/iCUdrsQsF5aycqfUAZrFBPguH6DVjbMUqyLvS78sDKiWqgWVhq9VDKse+WuQaJLGBDJNF9APoA6NDMjjIBZfmkGf2mV7ubIYihoOncUjahFqxU5306cNxAcdj2uNcwkgX4BCnBe/L2YsvMHhZrupzDewWWy4fxhktyoZ7VhLSl1I7fMPytjOpb9EIvng4DHGX2t+hKfon2rCGfECPavwiTM="}} diff --git a/test/fixtures/hubzilla-follow-activity.json b/test/fixtures/hubzilla-follow-activity.json new file mode 100644 index 000000000..2fcc70029 --- /dev/null +++ b/test/fixtures/hubzilla-follow-activity.json @@ -0,0 +1,31 @@ +{ + "type": "Follow", + "signature": { + "type": "RsaSignature2017", + "signatureValue": "Kn1/UkAQGJVaXBfWLAHcnwHg8YMAUqlEaBuYLazAG+pz5hqivsyrBmPV186Xzr+B4ZLExA9+SnOoNx/GOz4hBm0kAmukNSILAsUd84tcJ2yT9zc1RKtembK4WiwOw7li0+maeDN0HaB6t+6eTqsCWmtiZpprhXD8V1GGT8yG7X24fQ9oFGn+ng7lasbcCC0988Y1eGqNe7KryxcPuQz57YkDapvtONzk8gyLTkZMV4De93MyRHq6GVjQVIgtiYabQAxrX6Q8C+4P/jQoqdWJHEe+MY5JKyNaT/hMPt2Md1ok9fZQBGHlErk22/zy8bSN19GdG09HmIysBUHRYpBLig==", + "creator": "https://hubzilla.example.org/channel/kaniini#main-key", + "created": "2018-02-17T13:29:31Z" + }, + "object": "https://localtesting.pleroma.lol/users/lain", + "nickname": "lain", + "id": "https://hubzilla.example.org/channel/kaniini#follows/2", + "actor": { + "id": "https://hubzilla.example.org/channel/kaniini" + }, + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1", + { + "toot": "http://joinmastodon.org/ns#", + "sensitive": "as:sensitive", + "ostatus": "http://ostatus.org#", + "movedTo": "as:movedTo", + "manuallyApprovesFollowers": "as:manuallyApprovesFollowers", + "inReplyToAtomUri": "ostatus:inReplyToAtomUri", + "conversation": "ostatus:conversation", + "atomUri": "ostatus:atomUri", + "Hashtag": "as:Hashtag", + "Emoji": "toot:Emoji" + } + ] +} diff --git a/test/support/httpoison_mock.ex b/test/support/httpoison_mock.ex index 4a5a9ea85..ad5171492 100644 --- a/test/support/httpoison_mock.ex +++ b/test/support/httpoison_mock.ex @@ -628,6 +628,14 @@ defmodule HTTPoisonMock do }} end + def get("https://hubzilla.example.org/channel/kaniini", [Accept: "application/activity+json"], _) do + {:ok, + %Response{ + status_code: 200, + body: File.read!("test/fixtures/httpoison_mock/kaniini@hubzilla.example.org.json") + }} + end + def get("https://masto.quad.moe/users/_HellPie", [Accept: "application/activity+json"], _) do {:ok, %Response{ diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index b02d80cce..d8579ecfe 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -1,6 +1,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do use Pleroma.DataCase alias Pleroma.Web.ActivityPub.Transmogrifier + alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.OStatus alias Pleroma.Activity alias Pleroma.User @@ -118,6 +119,23 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do assert User.following?(User.get_by_ap_id(data["actor"]), user) end + test "it works for incoming follow requests from hubzilla" do + user = insert(:user) + + data = + File.read!("test/fixtures/hubzilla-follow-activity.json") + |> Poison.decode!() + |> Map.put("object", user.ap_id) + |> Utils.normalize_params() + + {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) + + assert data["actor"] == "https://hubzilla.example.org/channel/kaniini" + assert data["type"] == "Follow" + assert data["id"] == "https://hubzilla.example.org/channel/kaniini#follows/2" + assert User.following?(User.get_by_ap_id(data["actor"]), user) + end + test "it works for incoming likes" do user = insert(:user) {:ok, activity} = CommonAPI.post(user, %{"status" => "hello"}) -- cgit v1.2.3 From 6e8de2faae46f3dcaf6881ab40664da0057551e4 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 19 May 2018 08:37:04 +0000 Subject: run mix format --- test/support/httpoison_mock.ex | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/support/httpoison_mock.ex b/test/support/httpoison_mock.ex index ad5171492..6bbae70e1 100644 --- a/test/support/httpoison_mock.ex +++ b/test/support/httpoison_mock.ex @@ -628,7 +628,11 @@ defmodule HTTPoisonMock do }} end - def get("https://hubzilla.example.org/channel/kaniini", [Accept: "application/activity+json"], _) do + def get( + "https://hubzilla.example.org/channel/kaniini", + [Accept: "application/activity+json"], + _ + ) do {:ok, %Response{ status_code: 200, -- cgit v1.2.3 From 725b05d04aecaa00d5b79c81958267444bf3c91d Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 19 May 2018 08:48:15 +0000 Subject: run mix format --- test/support/httpoison_mock.ex | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/support/httpoison_mock.ex b/test/support/httpoison_mock.ex index e733afa59..a1a542103 100644 --- a/test/support/httpoison_mock.ex +++ b/test/support/httpoison_mock.ex @@ -8,11 +8,11 @@ defmodule HTTPoisonMock do [Accept: "application/xrd+xml,application/jrd+json"], follow_redirect: true ) do - {:ok, - %Response{ - status_code: 200, - body: File.read!("test/fixtures/httpoison_mock/kaniini@gerzilla.de.json") - }} + {:ok, + %Response{ + status_code: 200, + body: File.read!("test/fixtures/httpoison_mock/kaniini@gerzilla.de.json") + }} end def get( -- cgit v1.2.3 From df95118c819ae15f0de43519f2f9f9753ac60ec2 Mon Sep 17 00:00:00 2001 From: lain Date: Sat, 19 May 2018 11:27:14 +0200 Subject: Fix linking problem. --- test/formatter_test.exs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test') diff --git a/test/formatter_test.exs b/test/formatter_test.exs index 2cf1f3f8e..e89b36663 100644 --- a/test/formatter_test.exs +++ b/test/formatter_test.exs @@ -78,6 +78,13 @@ defmodule Pleroma.FormatterTest do "https://en.wikipedia.org/wiki/Duff's_device" assert Formatter.add_links({[], text}) |> Formatter.finalize() == expected + + text = "https://pleroma.com https://pleroma.com/sucks" + + expected = + "https://pleroma.com https://pleroma.com/sucks" + + assert Formatter.add_links({[], text}) |> Formatter.finalize() == expected end end -- cgit v1.2.3 From d1366f8d46959229fdae398fe7920f6894d9d02a Mon Sep 17 00:00:00 2001 From: Syldexia Date: Sat, 19 May 2018 13:35:49 +0100 Subject: Modified deleting an account to run as a task --- test/web/twitter_api/twitter_api_controller_test.exs | 2 -- 1 file changed, 2 deletions(-) (limited to 'test') diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 170dda145..02aba0bc8 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -825,8 +825,6 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do |> post("/api/pleroma/delete_account", %{"password" => "test"}) assert json_response(conn, 200) == %{"status" => "success"} - fetched_user = Repo.get(User, current_user.id) - assert fetched_user.info == %{"deactivated" => true} end end end -- cgit v1.2.3 From 6f39ecc41be77298ae375ca0a2f51ae7dc29fbbf Mon Sep 17 00:00:00 2001 From: Thog Date: Sat, 19 May 2018 15:22:43 +0200 Subject: Support Undo like activities (Fix #139) --- test/fixtures/mastodon-undo-like.json | 34 ++++++++++++++++++++++++ test/web/activity_pub/activity_pub_test.exs | 2 +- test/web/activity_pub/transmogrifier_test.exs | 37 +++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/mastodon-undo-like.json (limited to 'test') diff --git a/test/fixtures/mastodon-undo-like.json b/test/fixtures/mastodon-undo-like.json new file mode 100644 index 000000000..0cbed30ff --- /dev/null +++ b/test/fixtures/mastodon-undo-like.json @@ -0,0 +1,34 @@ +{ + "type": "Undo", + "signature": { + "type": "RsaSignature2017", + "signatureValue": "fdxMfQSMwbC6wP6sh6neS/vM5879K67yQkHTbiT5Npr5wAac0y6+o3Ij+41tN3rL6wfuGTosSBTHOtta6R4GCOOhCaCSLMZKypnp1VltCzLDoyrZELnYQIC8gpUXVmIycZbREk22qWUe/w7DAFaKK4UscBlHDzeDVcA0K3Se5Sluqi9/Zh+ldAnEzj/rSEPDjrtvf5wGNf3fHxbKSRKFt90JvKK6hS+vxKUhlRFDf6/SMETw+EhwJSNW4d10yMUakqUWsFv4Acq5LW7l+HpYMvlYY1FZhNde1+uonnCyuQDyvzkff8zwtEJmAXC4RivO/VVLa17SmqheJZfI8oluVg==", + "creator": "http://mastodon.example.org/users/admin#main-key", + "created": "2018-05-19T16:36:58Z" + }, + "object": { + "type": "Like", + "object": "http://localtesting.pleroma.lol/objects/eb92579d-3417-42a8-8652-2492c2d4f454", + "id": "http://mastodon.example.org/users/admin#likes/2", + "actor": "http://mastodon.example.org/users/admin" + }, + "nickname": "lain", + "id": "http://mastodon.example.org/users/admin#likes/2/undo", + "actor": "http://mastodon.example.org/users/admin", + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1", + { + "toot": "http://joinmastodon.org/ns#", + "sensitive": "as:sensitive", + "ostatus": "http://ostatus.org#", + "movedTo": "as:movedTo", + "manuallyApprovesFollowers": "as:manuallyApprovesFollowers", + "inReplyToAtomUri": "ostatus:inReplyToAtomUri", + "conversation": "ostatus:conversation", + "atomUri": "ostatus:atomUri", + "Hashtag": "as:Hashtag", + "Emoji": "toot:Emoji" + } + ] +} \ No newline at end of file diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index c1ba626b7..9adce84b5 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -277,7 +277,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do {:ok, like_activity, object} = ActivityPub.like(user, object) assert object.data["like_count"] == 1 - {:ok, object} = ActivityPub.unlike(user, object) + {:ok, _, _, object} = ActivityPub.unlike(user, object) assert object.data["like_count"] == 0 assert Repo.get(Activity, like_activity.id) == nil diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index d8579ecfe..a0af75a69 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -153,6 +153,43 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do assert data["object"] == activity.data["object"]["id"] end + test "it returns an error for incoming unlikes wihout a like activity" do + user = insert(:user) + {:ok, activity} = CommonAPI.post(user, %{"status" => "leave a like pls"}) + + data = + File.read!("test/fixtures/mastodon-undo-like.json") + |> Poison.decode!() + |> Map.put("object", activity.data["object"]["id"]) + + assert Transmogrifier.handle_incoming(data) == :error + end + + test "it works for incoming unlikes with an existing like activity" do + user = insert(:user) + {:ok, activity} = CommonAPI.post(user, %{"status" => "leave a like pls"}) + + like_data = + File.read!("test/fixtures/mastodon-like.json") + |> Poison.decode!() + |> Map.put("object", activity.data["object"]["id"]) + + {:ok, %Activity{data: like_data, local: false}} = Transmogrifier.handle_incoming(like_data) + + data = + File.read!("test/fixtures/mastodon-undo-like.json") + |> Poison.decode!() + |> Map.put("object", like_data) + |> Map.put("actor", like_data["actor"]) + + {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) + + assert data["actor"] == "http://mastodon.example.org/users/admin" + assert data["type"] == "Undo" + assert data["id"] == "http://mastodon.example.org/users/admin#likes/2/undo" + assert data["object"]["id"] == "http://mastodon.example.org/users/admin#likes/2" + end + test "it works for incoming announces" do data = File.read!("test/fixtures/mastodon-announce.json") |> Poison.decode!() -- cgit v1.2.3 From 434601a5c367bb2d41115e3060f5d5b70572da39 Mon Sep 17 00:00:00 2001 From: lain Date: Sun, 20 May 2018 16:15:18 +0200 Subject: Return private / direct posts on user timelines, too. --- .../mastodon_api/mastodon_api_controller_test.exs | 43 ++++++++++++++++++---- 1 file changed, 36 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 8d79c96b1..435462769 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -354,18 +354,47 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do describe "user timelines" do test "gets a users statuses", %{conn: conn} do - _note = insert(:note_activity) - note_two = insert(:note_activity) + user_one = insert(:user) + user_two = insert(:user) + user_three = insert(:user) - user = User.get_by_ap_id(note_two.data["actor"]) + {:ok, user_three} = User.follow(user_three, user_one) - conn = + {:ok, activity} = CommonAPI.post(user_one, %{"status" => "HI!!!"}) + + {:ok, direct_activity} = + CommonAPI.post(user_one, %{ + "status" => "Hi, @#{user_two.nickname}.", + "visibility" => "direct" + }) + + {:ok, private_activity} = + CommonAPI.post(user_one, %{"status" => "private", "visibility" => "private"}) + + resp = conn - |> get("/api/v1/accounts/#{user.id}/statuses") + |> get("/api/v1/accounts/#{user_one.id}/statuses") - assert [%{"id" => id}] = json_response(conn, 200) + assert [%{"id" => id}] = json_response(resp, 200) + assert id == to_string(activity.id) + + resp = + conn + |> assign(:user, user_two) + |> get("/api/v1/accounts/#{user_one.id}/statuses") + + assert [%{"id" => id_one}, %{"id" => id_two}] = json_response(resp, 200) + assert id_one == to_string(direct_activity.id) + assert id_two == to_string(activity.id) + + resp = + conn + |> assign(:user, user_three) + |> get("/api/v1/accounts/#{user_one.id}/statuses") - assert id == to_string(note_two.id) + assert [%{"id" => id_one}, %{"id" => id_two}] = json_response(resp, 200) + assert id_one == to_string(private_activity.id) + assert id_two == to_string(activity.id) end test "unimplemented pinned statuses feature", %{conn: conn} do -- cgit v1.2.3 From ff007af0c2f229fa20cd4b83b94de89cd9fce29c Mon Sep 17 00:00:00 2001 From: lain Date: Sun, 20 May 2018 18:01:24 +0200 Subject: Return visilility in twitter api, too. --- test/web/twitter_api/views/activity_view_test.exs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs index 7f2017d3c..5b2a7466b 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -18,7 +18,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do user = insert(:user) other_user = insert(:user, %{nickname: "shp"}) - {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"}) + {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"}) result = ActivityView.render("activity.json", activity: activity) @@ -47,7 +47,8 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do "tags" => [], "text" => "Hey @shp!", "uri" => activity.data["object"]["id"], - "user" => UserView.render("show.json", %{user: user}) + "user" => UserView.render("show.json", %{user: user}), + "visibility" => "direct" } assert result == expected -- cgit v1.2.3 From 413de8e4bcacc363958673d33787195823f7fe87 Mon Sep 17 00:00:00 2001 From: lain Date: Sun, 20 May 2018 19:26:09 +0200 Subject: More fixes. --- test/web/twitter_api/representers/activity_representer_test.exs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs index bb47d4409..16c6e7b0d 100644 --- a/test/web/twitter_api/representers/activity_representer_test.exs +++ b/test/web/twitter_api/representers/activity_representer_test.exs @@ -154,7 +154,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do "tags" => ["nsfw", "content", "mentioning"], "activity_type" => "post", "possibly_sensitive" => true, - "uri" => activity.data["object"]["id"] + "uri" => activity.data["object"]["id"], + "visibility" => "direct" } assert ActivityRepresenter.to_map(activity, %{ -- cgit v1.2.3 From 75cfd9d34dc4be83a1ad4329f93d5121a7968b09 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 21 May 2018 12:38:12 +0000 Subject: webfinger: fix finding the XRD uri for statusnet instances --- test/fixtures/httpoison_mock/status.alpicola.com_host_meta | 2 ++ test/support/httpoison_mock.ex | 8 ++++++++ test/web/web_finger/web_finger_test.exs | 6 ++++++ 3 files changed, 16 insertions(+) create mode 100644 test/fixtures/httpoison_mock/status.alpicola.com_host_meta (limited to 'test') 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 @@ + +status.alpicola.comResource Descriptor \ No newline at end of file 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/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 -- cgit v1.2.3