From d8c842a7713ab2c9dd49bdabfad4f5a1b6120fcf Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Thu, 17 May 2018 22:15:57 -0400 Subject: Add support for incoming remote unfollows --- test/fixtures/mastodon-unfollow-activity.json | 33 +++++++++++++++++++++++++++ test/web/activity_pub/transmogrifier_test.exs | 24 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 test/fixtures/mastodon-unfollow-activity.json (limited to 'test') diff --git a/test/fixtures/mastodon-unfollow-activity.json b/test/fixtures/mastodon-unfollow-activity.json new file mode 100644 index 000000000..022b47acd --- /dev/null +++ b/test/fixtures/mastodon-unfollow-activity.json @@ -0,0 +1,33 @@ +{ + "@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" + } + ], + "signature": { + "type": "RsaSignature2017", + "signatureValue": "Kn1/UkAQGJVaXBfWLAHcnwHg8YMAUqlEaBuYLazAG+pz5hqivsyrBmPV186Xzr+B4ZLExA9+SnOoNx/GOz4hBm0kAmukNSILAsUd84tcJ2yT9zc1RKtembK4WiwOw7li0+maeDN0HaB6t+6eTqsCWmtiZpprhXD8V1GGT8yG7X24fQ9oFGn+ng7lasbcCC0988Y1eGqNe7KryxcPuQz57YkDapvtONzk8gyLTkZMV4De93MyRHq6GVjQVIgtiYabQAxrX6Q8C+4P/jQoqdWJHEe+MY5JKyNaT/hMPt2Md1ok9fZQBGHlErk22/zy8bSN19GdG09HmIysBUHRYpBLig==", + "creator": "http://mastodon.example.org/users/admin#main-key", + "created": "2018-02-17T13:29:31Z" + }, + "type": "Undo", + "object": { + "type": "Follow", + "object": "http://localtesting.pleroma.lol/users/lain", + "nickname": "lain", + "id": "http://mastodon.example.org/users/admin#follows/2", + "actor": "http://mastodon.example.org/users/admin" + }, + "actor": "http://mastodon.example.org/users/admin" +} diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index a3408da9d..8ed7147f4 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -260,6 +260,30 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do assert data["object"]["id"] == "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity" end + + test "it works for incomming unfollows" do + user = insert(:user) + + follow_data = + File.read!("test/fixtures/mastodon-follow-activity.json") + |> Poison.decode!() + |> Map.put("object", user.ap_id) + + {:ok, %Activity{data: _, local: false}} = Transmogrifier.handle_incoming(follow_data) + + data = + File.read!("test/fixtures/mastodon-unfollow-activity.json") + |> Poison.decode!() + |> Map.put("object", follow_data) + + {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) + + assert data["type"] == "Undo" + assert data["object"]["type"] == "Follow" + assert data["actor"] == "http://mastodon.example.org/users/admin" + + refute User.following?(User.get_by_ap_id(data["actor"]), user) + end end describe "prepare outgoing" do -- cgit v1.2.3 From e6dc15b96cb971836211a1e57be1756936456c17 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Thu, 17 May 2018 23:53:34 -0400 Subject: Undo formatting in user.ex --- test/fixtures/mastodon-unfollow-activity.json | 33 --------------------------- test/web/activity_pub/transmogrifier_test.exs | 24 ------------------- 2 files changed, 57 deletions(-) delete mode 100644 test/fixtures/mastodon-unfollow-activity.json (limited to 'test') diff --git a/test/fixtures/mastodon-unfollow-activity.json b/test/fixtures/mastodon-unfollow-activity.json deleted file mode 100644 index 022b47acd..000000000 --- a/test/fixtures/mastodon-unfollow-activity.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "@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" - } - ], - "signature": { - "type": "RsaSignature2017", - "signatureValue": "Kn1/UkAQGJVaXBfWLAHcnwHg8YMAUqlEaBuYLazAG+pz5hqivsyrBmPV186Xzr+B4ZLExA9+SnOoNx/GOz4hBm0kAmukNSILAsUd84tcJ2yT9zc1RKtembK4WiwOw7li0+maeDN0HaB6t+6eTqsCWmtiZpprhXD8V1GGT8yG7X24fQ9oFGn+ng7lasbcCC0988Y1eGqNe7KryxcPuQz57YkDapvtONzk8gyLTkZMV4De93MyRHq6GVjQVIgtiYabQAxrX6Q8C+4P/jQoqdWJHEe+MY5JKyNaT/hMPt2Md1ok9fZQBGHlErk22/zy8bSN19GdG09HmIysBUHRYpBLig==", - "creator": "http://mastodon.example.org/users/admin#main-key", - "created": "2018-02-17T13:29:31Z" - }, - "type": "Undo", - "object": { - "type": "Follow", - "object": "http://localtesting.pleroma.lol/users/lain", - "nickname": "lain", - "id": "http://mastodon.example.org/users/admin#follows/2", - "actor": "http://mastodon.example.org/users/admin" - }, - "actor": "http://mastodon.example.org/users/admin" -} diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 8ed7147f4..a3408da9d 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -260,30 +260,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do assert data["object"]["id"] == "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity" end - - test "it works for incomming unfollows" do - user = insert(:user) - - follow_data = - File.read!("test/fixtures/mastodon-follow-activity.json") - |> Poison.decode!() - |> Map.put("object", user.ap_id) - - {:ok, %Activity{data: _, local: false}} = Transmogrifier.handle_incoming(follow_data) - - data = - File.read!("test/fixtures/mastodon-unfollow-activity.json") - |> Poison.decode!() - |> Map.put("object", follow_data) - - {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) - - assert data["type"] == "Undo" - assert data["object"]["type"] == "Follow" - assert data["actor"] == "http://mastodon.example.org/users/admin" - - refute User.following?(User.get_by_ap_id(data["actor"]), user) - end end describe "prepare outgoing" do -- cgit v1.2.3 From 8d11bae0d5e649f9dc0570b24ee5c4c74b8b463f Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Thu, 17 May 2018 23:55:00 -0400 Subject: Revert "Undo formatting in user.ex" This reverts commit e6dc15b96cb971836211a1e57be1756936456c17. --- test/fixtures/mastodon-unfollow-activity.json | 33 +++++++++++++++++++++++++++ test/web/activity_pub/transmogrifier_test.exs | 24 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 test/fixtures/mastodon-unfollow-activity.json (limited to 'test') diff --git a/test/fixtures/mastodon-unfollow-activity.json b/test/fixtures/mastodon-unfollow-activity.json new file mode 100644 index 000000000..022b47acd --- /dev/null +++ b/test/fixtures/mastodon-unfollow-activity.json @@ -0,0 +1,33 @@ +{ + "@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" + } + ], + "signature": { + "type": "RsaSignature2017", + "signatureValue": "Kn1/UkAQGJVaXBfWLAHcnwHg8YMAUqlEaBuYLazAG+pz5hqivsyrBmPV186Xzr+B4ZLExA9+SnOoNx/GOz4hBm0kAmukNSILAsUd84tcJ2yT9zc1RKtembK4WiwOw7li0+maeDN0HaB6t+6eTqsCWmtiZpprhXD8V1GGT8yG7X24fQ9oFGn+ng7lasbcCC0988Y1eGqNe7KryxcPuQz57YkDapvtONzk8gyLTkZMV4De93MyRHq6GVjQVIgtiYabQAxrX6Q8C+4P/jQoqdWJHEe+MY5JKyNaT/hMPt2Md1ok9fZQBGHlErk22/zy8bSN19GdG09HmIysBUHRYpBLig==", + "creator": "http://mastodon.example.org/users/admin#main-key", + "created": "2018-02-17T13:29:31Z" + }, + "type": "Undo", + "object": { + "type": "Follow", + "object": "http://localtesting.pleroma.lol/users/lain", + "nickname": "lain", + "id": "http://mastodon.example.org/users/admin#follows/2", + "actor": "http://mastodon.example.org/users/admin" + }, + "actor": "http://mastodon.example.org/users/admin" +} diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index a3408da9d..8ed7147f4 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -260,6 +260,30 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do assert data["object"]["id"] == "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity" end + + test "it works for incomming unfollows" do + user = insert(:user) + + follow_data = + File.read!("test/fixtures/mastodon-follow-activity.json") + |> Poison.decode!() + |> Map.put("object", user.ap_id) + + {:ok, %Activity{data: _, local: false}} = Transmogrifier.handle_incoming(follow_data) + + data = + File.read!("test/fixtures/mastodon-unfollow-activity.json") + |> Poison.decode!() + |> Map.put("object", follow_data) + + {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) + + assert data["type"] == "Undo" + assert data["object"]["type"] == "Follow" + assert data["actor"] == "http://mastodon.example.org/users/admin" + + refute User.following?(User.get_by_ap_id(data["actor"]), user) + end end describe "prepare outgoing" do -- cgit v1.2.3 From 1e43de0f86ea632a313f9bf7434183a6db38f0b6 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Sat, 19 May 2018 21:23:52 -0400 Subject: Formatting and add tests for blocks/unblocks --- test/fixtures/mastodon-block-activity.json | 29 +++++++++++++++++ test/fixtures/mastodon-unblock-activity.json | 33 +++++++++++++++++++ test/web/activity_pub/transmogrifier_test.exs | 46 +++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 test/fixtures/mastodon-block-activity.json create mode 100644 test/fixtures/mastodon-unblock-activity.json (limited to 'test') diff --git a/test/fixtures/mastodon-block-activity.json b/test/fixtures/mastodon-block-activity.json new file mode 100644 index 000000000..186719d2c --- /dev/null +++ b/test/fixtures/mastodon-block-activity.json @@ -0,0 +1,29 @@ +{ + "type": "Block", + "signature": { + "type": "RsaSignature2017", + "signatureValue": "Kn1/UkAQGJVaXBfWLAHcnwHg8YMAUqlEaBuYLazAG+pz5hqivsyrBmPV186Xzr+B4ZLExA9+SnOoNx/GOz4hBm0kAmukNSILAsUd84tcJ2yT9zc1RKtembK4WiwOw7li0+maeDN0HaB6t+6eTqsCWmtiZpprhXD8V1GGT8yG7X24fQ9oFGn+ng7lasbcCC0988Y1eGqNe7KryxcPuQz57YkDapvtONzk8gyLTkZMV4De93MyRHq6GVjQVIgtiYabQAxrX6Q8C+4P/jQoqdWJHEe+MY5JKyNaT/hMPt2Md1ok9fZQBGHlErk22/zy8bSN19GdG09HmIysBUHRYpBLig==", + "creator": "http://mastodon.example.org/users/admin#main-key", + "created": "2018-02-17T13:29:31Z" + }, + "object": "http://localtesting.pleroma.lol/users/lain", + "nickname": "lain", + "id": "http://mastodon.example.org/users/admin#follows/2", + "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" + } + ] +} diff --git a/test/fixtures/mastodon-unblock-activity.json b/test/fixtures/mastodon-unblock-activity.json new file mode 100644 index 000000000..53b2f42a8 --- /dev/null +++ b/test/fixtures/mastodon-unblock-activity.json @@ -0,0 +1,33 @@ +{ + "@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" + } + ], + "signature": { + "type": "RsaSignature2017", + "signatureValue": "Kn1/UkAQGJVaXBfWLAHcnwHg8YMAUqlEaBuYLazAG+pz5hqivsyrBmPV186Xzr+B4ZLExA9+SnOoNx/GOz4hBm0kAmukNSILAsUd84tcJ2yT9zc1RKtembK4WiwOw7li0+maeDN0HaB6t+6eTqsCWmtiZpprhXD8V1GGT8yG7X24fQ9oFGn+ng7lasbcCC0988Y1eGqNe7KryxcPuQz57YkDapvtONzk8gyLTkZMV4De93MyRHq6GVjQVIgtiYabQAxrX6Q8C+4P/jQoqdWJHEe+MY5JKyNaT/hMPt2Md1ok9fZQBGHlErk22/zy8bSN19GdG09HmIysBUHRYpBLig==", + "creator": "http://mastodon.example.org/users/admin#main-key", + "created": "2018-02-17T13:29:31Z" + }, + "type": "Undo", + "object": { + "type": "Block", + "object": "http://localtesting.pleroma.lol/users/lain", + "nickname": "lain", + "id": "http://mastodon.example.org/users/admin#follows/2", + "actor": "http://mastodon.example.org/users/admin" + }, + "actor": "http://mastodon.example.org/users/admin" +} diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 8ed7147f4..0ca00a07e 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -280,10 +280,56 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do assert data["type"] == "Undo" assert data["object"]["type"] == "Follow" + assert data["object"]["object"] == user.ap_id assert data["actor"] == "http://mastodon.example.org/users/admin" refute User.following?(User.get_by_ap_id(data["actor"]), user) end + + test "it works for incoming blocks" do + user = insert(:user) + + data = + File.read!("test/fixtures/mastodon-block-activity.json") + |> Poison.decode!() + |> Map.put("object", user.ap_id) + + {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) + + assert data["type"] == "Block" + assert data["object"] == user.ap_id + assert data["actor"] == "https://mastodon.example.org/users/admin" + + blocker = User.get_by_ap_id(data["actor"]) + + assert User.blocks?(blocker, user.ap_id) + end + + test "it works for incoming unblocks" do + user = insert(:user) + + block_data = + File.read!("test/fixtures/mastodon-block-activity.json") + |> Poison.decode!() + |> Map.put("object", user.ap_id) + + {:ok, %Activity{data: _, local: false}} = Transmogrifier.handle_incoming(block_data) + + data = + File.read!("test/fixtures/mastodon-unblock-activity.json") + |> Poison.decode!() + |> Map.put("object", block_data) + + {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) + assert data["type"] == "Undo" + assert data["object"]["type"] == "Block" + assert data["object"]["object"] == user.ap_id + assert data["actor"] == "https://mastodon.example.org/users/admin" + + blocker = User.get_by_ap_id(data["actor"]) + + refute User.blocks?(blocker, user.ap_id) + end end describe "prepare outgoing" do -- cgit v1.2.3 From d46393f6efd6475bb20b6a12a7c6ebf800f6c5b5 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Sun, 20 May 2018 02:15:56 -0400 Subject: Fix test for blocks --- test/web/activity_pub/transmogrifier_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 0ca00a07e..1d38661eb 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -298,7 +298,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do assert data["type"] == "Block" assert data["object"] == user.ap_id - assert data["actor"] == "https://mastodon.example.org/users/admin" + assert data["actor"] == "http://mastodon.example.org/users/admin" blocker = User.get_by_ap_id(data["actor"]) -- cgit v1.2.3 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') 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 56de0216ae36394dba1aa9bac6c931af67233658 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Sun, 20 May 2018 19:45:05 -0400 Subject: pass user to User.blocks?/2 instead of ap_id --- test/web/activity_pub/transmogrifier_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 87fadece2..da55909bc 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -357,7 +357,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do blocker = User.get_by_ap_id(data["actor"]) - assert User.blocks?(blocker, user.ap_id) + assert User.blocks?(blocker, user) end test "it works for incoming unblocks" do -- cgit v1.2.3 From 89c5de90969cbd2b7cd5854c7209795443659062 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Sun, 20 May 2018 21:01:14 -0400 Subject: Fix unfollows --- test/fixtures/mastodon-unfollow-activity.json | 63 ++++++++++++++------------- test/web/activity_pub/activity_pub_test.exs | 2 +- 2 files changed, 33 insertions(+), 32 deletions(-) (limited to 'test') diff --git a/test/fixtures/mastodon-unfollow-activity.json b/test/fixtures/mastodon-unfollow-activity.json index 022b47acd..ae5ab7c66 100644 --- a/test/fixtures/mastodon-unfollow-activity.json +++ b/test/fixtures/mastodon-unfollow-activity.json @@ -1,33 +1,34 @@ { - "@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" - } - ], - "signature": { - "type": "RsaSignature2017", - "signatureValue": "Kn1/UkAQGJVaXBfWLAHcnwHg8YMAUqlEaBuYLazAG+pz5hqivsyrBmPV186Xzr+B4ZLExA9+SnOoNx/GOz4hBm0kAmukNSILAsUd84tcJ2yT9zc1RKtembK4WiwOw7li0+maeDN0HaB6t+6eTqsCWmtiZpprhXD8V1GGT8yG7X24fQ9oFGn+ng7lasbcCC0988Y1eGqNe7KryxcPuQz57YkDapvtONzk8gyLTkZMV4De93MyRHq6GVjQVIgtiYabQAxrX6Q8C+4P/jQoqdWJHEe+MY5JKyNaT/hMPt2Md1ok9fZQBGHlErk22/zy8bSN19GdG09HmIysBUHRYpBLig==", - "creator": "http://mastodon.example.org/users/admin#main-key", - "created": "2018-02-17T13:29:31Z" - }, - "type": "Undo", - "object": { - "type": "Follow", - "object": "http://localtesting.pleroma.lol/users/lain", - "nickname": "lain", - "id": "http://mastodon.example.org/users/admin#follows/2", - "actor": "http://mastodon.example.org/users/admin" - }, - "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" + } + ], + "signature":{ + "type":"RsaSignature2017", + "signatureValue":"Kn1/UkAQGJVaXBfWLAHcnwHg8YMAUqlEaBuYLazAG+pz5hqivsyrBmPV186Xzr+B4ZLExA9+SnOoNx/GOz4hBm0kAmukNSILAsUd84tcJ2yT9zc1RKtembK4WiwOw7li0+maeDN0HaB6t+6eTqsCWmtiZpprhXD8V1GGT8yG7X24fQ9oFGn+ng7lasbcCC0988Y1eGqNe7KryxcPuQz57YkDapvtONzk8gyLTkZMV4De93MyRHq6GVjQVIgtiYabQAxrX6Q8C+4P/jQoqdWJHEe+MY5JKyNaT/hMPt2Md1ok9fZQBGHlErk22/zy8bSN19GdG09HmIysBUHRYpBLig==", + "creator":"http://mastodon.example.org/users/admin#main-key", + "created":"2018-02-17T13:29:31Z" + }, + "type":"Undo", + "object":{ + "type":"Follow", + "object":"http://localtesting.pleroma.lol/users/lain", + "nickname":"lain", + "id":"http://mastodon.example.org/users/admin#follows/2", + "actor":"http://mastodon.example.org/users/admin" + }, + "actor":"http://mastodon.example.org/users/admin", + "id": "http://mastodon.example.org/users/admin#follow/2/undo" } diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 9adce84b5..35f0deffe 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -425,7 +425,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do assert activity.data["type"] == "Undo" assert activity.data["actor"] == follower.ap_id - assert activity.data["object"] == follow_activity.data["id"] + assert activity.data["object"]["id"] == follow_activity.data["id"] end end -- cgit v1.2.3 From cc5373b846d7f816a3e78af342468f2ea8415b8d Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Mon, 21 May 2018 05:00:58 -0400 Subject: Fix unblock handling --- test/fixtures/mastodon-unblock-activity.json | 5 +++-- test/web/activity_pub/transmogrifier_test.exs | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/fixtures/mastodon-unblock-activity.json b/test/fixtures/mastodon-unblock-activity.json index 53b2f42a8..f4a2d30dd 100644 --- a/test/fixtures/mastodon-unblock-activity.json +++ b/test/fixtures/mastodon-unblock-activity.json @@ -26,8 +26,9 @@ "type": "Block", "object": "http://localtesting.pleroma.lol/users/lain", "nickname": "lain", - "id": "http://mastodon.example.org/users/admin#follows/2", + "id": "http://mastodon.example.org/users/admin#blocks/2", "actor": "http://mastodon.example.org/users/admin" }, - "actor": "http://mastodon.example.org/users/admin" + "actor": "http://mastodon.example.org/users/admin", + "id": "http://mastodon.example.org/users/admin#blocks/2/undo" } diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index da55909bc..cf6b1d0b5 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -316,7 +316,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity" end - test "it works for incomming unfollows" do + test "it works for incomming unfollows with an existing follow" do user = insert(:user) follow_data = @@ -360,7 +360,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do assert User.blocks?(blocker, user) end - test "it works for incoming unblocks" do + test "it works for incoming unblocks with an existing block" do user = insert(:user) block_data = @@ -379,11 +379,11 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do assert data["type"] == "Undo" assert data["object"]["type"] == "Block" assert data["object"]["object"] == user.ap_id - assert data["actor"] == "https://mastodon.example.org/users/admin" + assert data["actor"] == "http://mastodon.example.org/users/admin" blocker = User.get_by_ap_id(data["actor"]) - refute User.blocks?(blocker, user.ap_id) + refute User.blocks?(blocker, user) end end -- cgit v1.2.3 From d045b96f957e0698ecd0110ca240f0527e3fea43 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Mon, 21 May 2018 05:11:13 -0400 Subject: Add tests for incoming unfollow over OStatus --- test/fixtures/unfollow.xml | 68 +++++++++++++++++++++++++++++++++++++++ test/web/ostatus/ostatus_test.exs | 24 ++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 test/fixtures/unfollow.xml (limited to 'test') diff --git a/test/fixtures/unfollow.xml b/test/fixtures/unfollow.xml new file mode 100644 index 000000000..7a8f8fd2e --- /dev/null +++ b/test/fixtures/unfollow.xml @@ -0,0 +1,68 @@ + + + GNU social + https://social.heldscal.la/api/statuses/user_timeline/23211.atom + lambadalambda timeline + Updates from lambadalambda on social.heldscal.la! + https://social.heldscal.la/avatar/23211-96-20170416114255.jpeg + 2017-05-07T09:54:49+00:00 + + http://activitystrea.ms/schema/1.0/person + https://social.heldscal.la/user/23211 + lambadalambda + Call me Deacon Blues. + + + + + + lambadalambda + Constance Variable + Call me Deacon Blues. + + Berlin + + + homepage + https://heldscal.la + true + + + + + + + + + + + + + undo:tag:social.heldscal.la,2017-05-07:subscription:23211:person:44803:2017-05-07T09:54:48+00:00 + Constance Variable (lambadalambda@social.heldscal.la)'s status on Sunday, 07-May-2017 09:54:49 UTC + <a href="https://social.heldscal.la/lambadalambda">Constance Variable</a> stopped following <a href="https://pawoo.net/@pekorino">mono</a>. + + http://activitystrea.ms/schema/1.0/unfollow + 2017-05-07T09:54:49+00:00 + 2017-05-07T09:54:49+00:00 + + http://activitystrea.ms/schema/1.0/person + https://pawoo.net/users/pekorino + mono + http://shitposter.club/mono 孤独のグルメ + + + + + pekorino + mono + http://shitposter.club/mono 孤独のグルメ + + + tag:social.heldscal.la,2017-05-07:objectType=thread:nonce=6e80caf94e03029f + + + + + + diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs index 3e7cf0155..f095e41dd 100644 --- a/test/web/ostatus/ostatus_test.exs +++ b/test/web/ostatus/ostatus_test.exs @@ -278,6 +278,30 @@ defmodule Pleroma.Web.OStatusTest do assert User.following?(follower, followed) end + test "handle incoming unfollows with existing follow" do + incoming_follow = File.read!("test/fixtures/follow.xml") + {:ok, [_activity]} = OStatus.handle_incoming(incoming_follow) + + incoming = File.read!("test/fixtures/unfollow.xml") + {:ok, [activity]} = OStatus.handle_incoming(incoming) + + assert activity.data["type"] == "Undo" + + assert activity.data["id"] == + "undo:tag:social.heldscal.la,2017-05-07:subscription:23211:person:44803:2017-05-07T09:54:48+00:00" + + assert activity.data["actor"] == "https://social.heldscal.la/user/23211" + assert is_map(activity.data["object"]) + assert activity.data["object"]["type"] == "Follow" + assert activity.data["object"]["object"] == "https://pawoo.net/users/pekorino" + refute activity.local + + follower = User.get_by_ap_id(activity.data["actor"]) + followed = User.get_by_ap_id(activity.data["object"]["object"]) + + refute User.following?(follower, followed) + end + describe "new remote user creation" do test "returns local users" do local_user = insert(:user) -- 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') 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 69aa7c213a8aa1dfa54dbcfdab0c4b10ec415df8 Mon Sep 17 00:00:00 2001 From: Syldexia Date: Mon, 21 May 2018 22:32:28 +0100 Subject: Fixed test --- test/web/common_api/common_api_utils_test.exs | 5 ++--- 1 file changed, 2 insertions(+), 3 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 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 -- cgit v1.2.3 From b2c6ae7d820fb9d6bf81c6912e3e9b10a6fa7dd2 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Tue, 22 May 2018 04:27:40 -0400 Subject: Hook up unfollow and (un)block to MastoAPI + tests --- test/web/activity_pub/activity_pub_test.exs | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 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 35f0deffe..081c202b1 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -425,10 +425,43 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do assert activity.data["type"] == "Undo" assert activity.data["actor"] == follower.ap_id + + assert is_map(activity.data["object"]) + assert activity.data["object"]["type"] == "Follow" + assert activity.data["object"]["object"] == followed.ap_id assert activity.data["object"]["id"] == follow_activity.data["id"] end end + describe "blocking / unblocking" do + test "creates a block activity" do + blocker = insert(:user) + blocked = insert(:user) + + {:ok, activity} = ActivityPub.block(blocker, blocked) + + assert activity.data["type"] == "Block" + assert activity.data["actor"] == blocker.ap_id + assert activity.data["object"] == blocked.ap_id + end + + test "creates an undo activity for the last block" do + blocker = insert(:user) + blocked = insert(:user) + + {:ok, block_activity} = ActivityPub.block(blocker, blocked) + {:ok, activity} = ActivityPub.unblock(blocker, blocked) + + assert activity.data["type"] == "Undo" + assert activity.data["actor"] == blocker.ap_id + + assert is_map(activity.data["object"]) + assert activity.data["object"]["type"] == "Block" + assert activity.data["object"]["object"] == blocked.ap_id + assert activity.data["object"]["id"] == block_activity.data["id"] + end + end + describe "deletion" do test "it creates a delete activity and deletes the original object" do note = insert(:note_activity) -- 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') 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 From 0b5bc62b33a655488afe73b35945adcbab11300d Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 23 May 2018 17:25:24 +0200 Subject: Don't save double tags in AP objects we create This crashed Mastodon workers. --- test/web/common_api/common_api_test.exs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 test/web/common_api/common_api_test.exs (limited to 'test') 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 -- cgit v1.2.3 From 1cd6194deeca32a96a31fc43c0ed27daadd65f64 Mon Sep 17 00:00:00 2001 From: lain Date: Thu, 24 May 2018 12:44:26 +0200 Subject: More efficient queries. --- test/support/factory.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test') 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 -- cgit v1.2.3 From 3dbd9809d44297c2edc8e08bde33f9ef7b998412 Mon Sep 17 00:00:00 2001 From: eal Date: Sun, 29 Apr 2018 16:02:46 +0300 Subject: MastoAPI: add lists. --- test/list_test.exs | 77 +++++++++++++ test/web/mastodon_api/list_view_test.exs | 19 ++++ .../mastodon_api/mastodon_api_controller_test.exs | 119 +++++++++++++++++++++ 3 files changed, 215 insertions(+) create mode 100644 test/list_test.exs create mode 100644 test/web/mastodon_api/list_view_test.exs (limited to 'test') diff --git a/test/list_test.exs b/test/list_test.exs new file mode 100644 index 000000000..ced012093 --- /dev/null +++ b/test/list_test.exs @@ -0,0 +1,77 @@ +defmodule Pleroma.ListTest do + alias Pleroma.{User, Repo} + use Pleroma.DataCase + + import Pleroma.Factory + import Ecto.Query + + test "creating a list" do + user = insert(:user) + {:ok, %Pleroma.List{} = list} = Pleroma.List.create("title", user) + %Pleroma.List{title: title} = Pleroma.List.get(list.id, user) + assert title == "title" + end + + test "getting a list not belonging to the user" do + user = insert(:user) + other_user = insert(:user) + {:ok, %Pleroma.List{} = list} = Pleroma.List.create("title", user) + ret = Pleroma.List.get(list.id, other_user) + assert is_nil(ret) + end + + test "adding an user to a list" do + user = insert(:user) + other_user = insert(:user) + {:ok, list} = Pleroma.List.create("title", user) + {:ok, %{following: following}} = Pleroma.List.follow(list, other_user) + assert [other_user.follower_address] == following + end + + test "removing an user from a list" do + user = insert(:user) + other_user = insert(:user) + {:ok, list} = Pleroma.List.create("title", user) + {:ok, %{following: following}} = Pleroma.List.follow(list, other_user) + {:ok, %{following: following}} = Pleroma.List.unfollow(list, other_user) + assert [] == following + end + + test "renaming a list" do + user = insert(:user) + {:ok, list} = Pleroma.List.create("title", user) + {:ok, %{title: title}} = Pleroma.List.rename(list, "new") + assert "new" == title + end + + test "deleting a list" do + user = insert(:user) + {:ok, list} = Pleroma.List.create("title", user) + {:ok, list} = Pleroma.List.delete(list) + assert is_nil(Repo.get(Pleroma.List, list.id)) + end + + test "getting users in a list" do + user = insert(:user) + other_user = insert(:user) + third_user = insert(:user) + {:ok, list} = Pleroma.List.create("title", user) + {:ok, list} = Pleroma.List.follow(list, other_user) + {:ok, list} = Pleroma.List.follow(list, third_user) + {:ok, following} = Pleroma.List.get_following(list) + assert other_user in following + assert third_user in following + end + + test "getting all lists by an user" do + user = insert(:user) + other_user = insert(:user) + {:ok, list_one} = Pleroma.List.create("title", user) + {:ok, list_two} = Pleroma.List.create("other title", user) + {:ok, list_three} = Pleroma.List.create("third title", other_user) + lists = Pleroma.List.for_user(user, %{}) + assert list_one in lists + assert list_two in lists + refute list_three in lists + end +end diff --git a/test/web/mastodon_api/list_view_test.exs b/test/web/mastodon_api/list_view_test.exs new file mode 100644 index 000000000..5e36872ed --- /dev/null +++ b/test/web/mastodon_api/list_view_test.exs @@ -0,0 +1,19 @@ +defmodule Pleroma.Web.MastodonAPI.ListViewTest do + use Pleroma.DataCase + import Pleroma.Factory + alias Pleroma.Web.MastodonAPI.ListView + alias Pleroma.List + + test "Represent a list" do + user = insert(:user) + title = "mortal enemies" + {:ok, list} = Pleroma.List.create(title, user) + + expected = %{ + id: to_string(list.id), + title: title + } + + assert expected == ListView.render("list.json", %{list: list}) + end +end diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 5293b9364..55ebe07a8 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -161,6 +161,125 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do end end + describe "lists" do + test "creating a list", %{conn: conn} do + user = insert(:user) + + conn = + conn + |> assign(:user, user) + |> post("/api/v1/lists", %{"title" => "cuties"}) + + assert %{"title" => title} = json_response(conn, 200) + assert title == "cuties" + end + + test "adding users to a list", %{conn: conn} do + user = insert(:user) + other_user = insert(:user) + {:ok, list} = Pleroma.List.create("name", user) + + conn = + conn + |> assign(:user, user) + |> post("/api/v1/lists/#{list.id}/accounts", %{"account_ids" => [other_user.id]}) + + assert %{} == json_response(conn, 200) + %Pleroma.List{following: following} = Pleroma.List.get(list.id, user) + assert following == [other_user.follower_address] + end + + test "removing users from a list", %{conn: conn} do + user = insert(:user) + other_user = insert(:user) + third_user = insert(:user) + {:ok, list} = Pleroma.List.create("name", user) + {:ok, list} = Pleroma.List.follow(list, other_user) + {:ok, list} = Pleroma.List.follow(list, third_user) + + conn = + conn + |> assign(:user, user) + |> delete("/api/v1/lists/#{list.id}/accounts", %{"account_ids" => [other_user.id]}) + + assert %{} == json_response(conn, 200) + %Pleroma.List{following: following} = Pleroma.List.get(list.id, user) + assert following == [third_user.follower_address] + end + + test "listing users in a list", %{conn: conn} do + user = insert(:user) + other_user = insert(:user) + {:ok, list} = Pleroma.List.create("name", user) + {:ok, list} = Pleroma.List.follow(list, other_user) + + conn = + conn + |> assign(:user, user) + |> get("/api/v1/lists/#{list.id}/accounts", %{"account_ids" => [other_user.id]}) + + assert [%{"id" => id}] = json_response(conn, 200) + assert id == to_string(other_user.id) + end + + test "retrieving a list", %{conn: conn} do + user = insert(:user) + {:ok, list} = Pleroma.List.create("name", user) + + conn = + conn + |> assign(:user, user) + |> get("/api/v1/lists/#{list.id}") + + assert %{"id" => id} = json_response(conn, 200) + assert id == to_string(list.id) + end + + test "renaming a list", %{conn: conn} do + user = insert(:user) + {:ok, list} = Pleroma.List.create("name", user) + + conn = + conn + |> assign(:user, user) + |> put("/api/v1/lists/#{list.id}", %{"title" => "newname"}) + + assert %{"title" => name} = json_response(conn, 200) + assert name == "newname" + end + + test "deleting a list", %{conn: conn} do + user = insert(:user) + {:ok, list} = Pleroma.List.create("name", user) + + conn = + conn + |> assign(:user, user) + |> delete("/api/v1/lists/#{list.id}") + + assert %{} = json_response(conn, 200) + assert is_nil(Repo.get(Pleroma.List, list.id)) + end + + test "list timeline", %{conn: conn} do + user = insert(:user) + other_user = insert(:user) + {:ok, activity_one} = TwitterAPI.create_status(user, %{"status" => "Marisa is cute."}) + {:ok, activity_two} = TwitterAPI.create_status(other_user, %{"status" => "Marisa is cute."}) + {:ok, list} = Pleroma.List.create("name", user) + {:ok, list} = Pleroma.List.follow(list, other_user) + + conn = + conn + |> assign(:user, user) + |> get("/api/v1/timelines/list/#{list.id}") + + assert [%{"id" => id}] = json_response(conn, 200) + + assert id == to_string(activity_two.id) + end + end + describe "notifications" do test "list of notifications", %{conn: conn} do user = insert(:user) -- cgit v1.2.3 From 8d2ee70da18bf057041260ca311127daae9a6f09 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 25 May 2018 03:14:49 +0000 Subject: testsuite: fix module name for CommonAPI.Test (was duplicated with CommonAPI.UtilsTest) --- test/web/common_api/common_api_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs index b597e6e0a..a5da271b3 100644 --- a/test/web/common_api/common_api_test.exs +++ b/test/web/common_api/common_api_test.exs @@ -1,4 +1,4 @@ -defmodule Pleroma.Web.CommonAPI.UtilsTest do +defmodule Pleroma.Web.CommonAPI.Test do use Pleroma.DataCase alias Pleroma.Web.CommonAPI -- cgit v1.2.3 From 1d88abf2d4834a6dac95c655b9d27cf50377010a Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 25 May 2018 03:16:02 +0000 Subject: user: do not allow refollowing somebody who has blocked a user --- test/user_test.exs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test') diff --git a/test/user_test.exs b/test/user_test.exs index 9506b58fa..8c8cfd673 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -46,6 +46,15 @@ defmodule Pleroma.UserTest do {:error, _} = User.follow(user, followed) end + test "can't follow a user who blocked us" do + blocker = insert(:user) + blockee = insert(:user) + + {:ok, blocker} = User.block(blocker, blockee) + + {:error, _} = User.follow(blockee, blocker) + end + # This is a somewhat useless test. # test "following a remote user will ensure a websub subscription is present" do # user = insert(:user) -- cgit v1.2.3 From 1f3eb0f470c41aa0c9757756e28b8ae9ef1a2366 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 25 May 2018 03:14:49 +0000 Subject: testsuite: fix module name for CommonAPI.Test (was duplicated with CommonAPI.UtilsTest) --- test/web/common_api/common_api_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs index b597e6e0a..a5da271b3 100644 --- a/test/web/common_api/common_api_test.exs +++ b/test/web/common_api/common_api_test.exs @@ -1,4 +1,4 @@ -defmodule Pleroma.Web.CommonAPI.UtilsTest do +defmodule Pleroma.Web.CommonAPI.Test do use Pleroma.DataCase alias Pleroma.Web.CommonAPI -- cgit v1.2.3 From 7cf3cf77cfffd1e1f6187d7a3485bf2a5d18ca00 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 25 May 2018 12:51:04 +0000 Subject: activitypub transmogrifier: cleanups and tests for incoming accepts/rejects --- test/fixtures/mastodon-reject-activity.json | 34 ++++++++ test/web/activity_pub/transmogrifier_test.exs | 109 ++++++++++++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 test/fixtures/mastodon-reject-activity.json (limited to 'test') diff --git a/test/fixtures/mastodon-reject-activity.json b/test/fixtures/mastodon-reject-activity.json new file mode 100644 index 000000000..9559d6c73 --- /dev/null +++ b/test/fixtures/mastodon-reject-activity.json @@ -0,0 +1,34 @@ +{ + "type": "Reject", + "signature": { + "type": "RsaSignature2017", + "signatureValue": "rBzK4Kqhd4g7HDS8WE5oRbWQb2R+HF/6awbUuMWhgru/xCODT0SJWSri0qWqEO4fPcpoUyz2d25cw6o+iy9wiozQb3hQNnu69AR+H5Mytc06+g10KCHexbGhbAEAw/7IzmeXELHUbaqeduaDIbdt1zw4RkwLXdqgQcGXTJ6ND1wM3WMHXQCK1m0flasIXFoBxpliPAGiElV8s0+Ltuh562GvflG3kB3WO+j+NaR0ZfG5G9N88xMj9UQlCKit5gpAE5p6syUsCU2WGBHywTumv73i3OVTIFfq+P9AdMsRuzw1r7zoKEsthW4aOzLQDi01ZjvdBz8zH6JnjDU7SMN/Ig==", + "creator": "http://mastodon.example.org/users/admin#main-key", + "created": "2018-02-17T14:36:41Z" + }, + "object": { + "type": "Follow", + "object": "http://mastodon.example.org/users/admin", + "id": "http://localtesting.pleroma.lol/users/lain#follows/4", + "actor": "http://localtesting.pleroma.lol/users/lain" + }, + "nickname": "lain", + "id": "http://mastodon.example.org/users/admin#rejects/follows/4", + "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" + } + ] +} diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index cf6b1d0b5..b51e02b08 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -2,6 +2,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do use Pleroma.DataCase alias Pleroma.Web.ActivityPub.Transmogrifier alias Pleroma.Web.ActivityPub.Utils + alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.OStatus alias Pleroma.Activity alias Pleroma.User @@ -385,6 +386,114 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do refute User.blocks?(blocker, user) end + + test "it works for incoming accepts which were pre-accepted" do + follower = insert(:user) + followed = insert(:user) + + {:ok, follower} = User.follow(follower, followed) + assert User.following?(follower, followed) == true + + accept_data = + File.read!("test/fixtures/mastodon-accept-activity.json") + |> Poison.decode!() + |> Map.put("actor", followed.ap_id) + + accept_data = + Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id)) + + {:ok, %Activity{data: _}} = Transmogrifier.handle_incoming(accept_data) + + follower = Repo.get(User, follower.id) + + assert User.following?(follower, followed) == true + end + + test "it works for incoming accepts which were orphaned" do + follower = insert(:user) + followed = insert(:user, %{info: %{"locked" => true}}) + + {:ok, follow_activity} = ActivityPub.follow(follower, followed) + + accept_data = + File.read!("test/fixtures/mastodon-accept-activity.json") + |> Poison.decode!() + |> Map.put("actor", followed.ap_id) + + accept_data = + Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id)) + + {:ok, %Activity{data: _}} = Transmogrifier.handle_incoming(accept_data) + + follower = Repo.get(User, follower.id) + + assert User.following?(follower, followed) == true + end + + test "it works for incoming accepts which are referenced by IRI only" do + follower = insert(:user) + followed = insert(:user, %{info: %{"locked" => true}}) + + {:ok, follow_activity} = ActivityPub.follow(follower, followed) + + accept_data = + File.read!("test/fixtures/mastodon-accept-activity.json") + |> Poison.decode!() + |> Map.put("actor", followed.ap_id) + |> Map.put("object", follow_activity.data["id"]) + + {:ok, %Activity{data: _}} = Transmogrifier.handle_incoming(accept_data) + + follower = Repo.get(User, follower.id) + + assert User.following?(follower, followed) == true + end + + test "it works for incoming rejects which are orphaned" do + follower = insert(:user) + followed = insert(:user, %{info: %{"locked" => true}}) + + {:ok, follower} = User.follow(follower, followed) + {:ok, follow_activity} = ActivityPub.follow(follower, followed) + + assert User.following?(follower, followed) == true + + reject_data = + File.read!("test/fixtures/mastodon-reject-activity.json") + |> Poison.decode!() + |> Map.put("actor", followed.ap_id) + + reject_data = + Map.put(reject_data, "object", Map.put(reject_data["object"], "actor", follower.ap_id)) + + {:ok, %Activity{data: _}} = Transmogrifier.handle_incoming(reject_data) + + follower = Repo.get(User, follower.id) + + assert User.following?(follower, followed) == false + end + + test "it works for incoming rejects which are referenced by IRI only" do + follower = insert(:user) + followed = insert(:user, %{info: %{"locked" => true}}) + + {:ok, follower} = User.follow(follower, followed) + {:ok, follow_activity} = ActivityPub.follow(follower, followed) + + assert User.following?(follower, followed) == true + + reject_data = + File.read!("test/fixtures/mastodon-reject-activity.json") + |> Poison.decode!() + |> Map.put("actor", followed.ap_id) + |> Map.put("object", follow_activity.data["id"]) + + {:ok, %Activity{data: _}} = Transmogrifier.handle_incoming(reject_data) + + follower = Repo.get(User, follower.id) + + assert User.following?(follower, followed) == false + end end describe "prepare outgoing" do -- cgit v1.2.3 From 1db0dc30728a64cf5a9905bcc5df5af9ff3c677b Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 26 May 2018 11:16:05 +0000 Subject: tests: add tests to verify the accept request is discarded if no follow activity could be found --- test/web/activity_pub/transmogrifier_test.exs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test') diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index b51e02b08..e4cff898d 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -394,6 +394,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do {:ok, follower} = User.follow(follower, followed) assert User.following?(follower, followed) == true + {:ok, follow_activity} = ActivityPub.follow(follower, followed) + accept_data = File.read!("test/fixtures/mastodon-accept-activity.json") |> Poison.decode!() @@ -449,6 +451,25 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do assert User.following?(follower, followed) == true end + test "it fails for incoming accepts which cannot be correlated" do + follower = insert(:user) + followed = insert(:user, %{info: %{"locked" => true}}) + + accept_data = + File.read!("test/fixtures/mastodon-accept-activity.json") + |> Poison.decode!() + |> Map.put("actor", followed.ap_id) + + accept_data = + Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id)) + + :error = Transmogrifier.handle_incoming(accept_data) + + follower = Repo.get(User, follower.id) + + refute User.following?(follower, followed) == true + end + test "it works for incoming rejects which are orphaned" do follower = insert(:user) followed = insert(:user, %{info: %{"locked" => true}}) -- cgit v1.2.3 From 3839a11ef51a7602bd4c0b5c5d1318bb9cedd213 Mon Sep 17 00:00:00 2001 From: lain Date: Sat, 26 May 2018 14:07:46 +0200 Subject: Don't treat remote accepts/rejects as local. Also, use specialized functions to get safe data. --- test/web/activity_pub/transmogrifier_test.exs | 33 +++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index e4cff898d..761d9d992 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -404,7 +404,10 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do accept_data = Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id)) - {:ok, %Activity{data: _}} = Transmogrifier.handle_incoming(accept_data) + {:ok, activity} = Transmogrifier.handle_incoming(accept_data) + refute activity.local + + assert activity.data["object"] == follow_activity.data["id"] follower = Repo.get(User, follower.id) @@ -425,7 +428,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do accept_data = Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id)) - {:ok, %Activity{data: _}} = Transmogrifier.handle_incoming(accept_data) + {:ok, activity} = Transmogrifier.handle_incoming(accept_data) + assert activity.data["object"] == follow_activity.data["id"] follower = Repo.get(User, follower.id) @@ -444,7 +448,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do |> Map.put("actor", followed.ap_id) |> Map.put("object", follow_activity.data["id"]) - {:ok, %Activity{data: _}} = Transmogrifier.handle_incoming(accept_data) + {:ok, activity} = Transmogrifier.handle_incoming(accept_data) + assert activity.data["object"] == follow_activity.data["id"] follower = Repo.get(User, follower.id) @@ -470,6 +475,25 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do refute User.following?(follower, followed) == true end + test "it fails for incoming rejects which cannot be correlated" do + follower = insert(:user) + followed = insert(:user, %{info: %{"locked" => true}}) + + accept_data = + File.read!("test/fixtures/mastodon-reject-activity.json") + |> Poison.decode!() + |> Map.put("actor", followed.ap_id) + + accept_data = + Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id)) + + :error = Transmogrifier.handle_incoming(accept_data) + + follower = Repo.get(User, follower.id) + + refute User.following?(follower, followed) == true + end + test "it works for incoming rejects which are orphaned" do follower = insert(:user) followed = insert(:user, %{info: %{"locked" => true}}) @@ -487,7 +511,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do reject_data = Map.put(reject_data, "object", Map.put(reject_data["object"], "actor", follower.ap_id)) - {:ok, %Activity{data: _}} = Transmogrifier.handle_incoming(reject_data) + {:ok, activity} = Transmogrifier.handle_incoming(reject_data) + refute activity.local follower = Repo.get(User, follower.id) -- cgit v1.2.3 From bfce29866fea3ec7ab91a6b1f20a845248fa0130 Mon Sep 17 00:00:00 2001 From: lain Date: Sat, 26 May 2018 15:07:21 +0200 Subject: Make Mastodon follow hack more explicit. --- test/web/activity_pub/transmogrifier_test.exs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 761d9d992..43395eef1 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -8,8 +8,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do alias Pleroma.User alias Pleroma.Repo alias Pleroma.Web.Websub.WebsubClientSubscription - alias Pleroma.Web.Websub.WebsubServerSubscription - import Ecto.Query import Pleroma.Factory alias Pleroma.Web.CommonAPI @@ -284,7 +282,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do |> Map.put("object", object) |> Map.put("actor", activity.data["actor"]) - {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) + {:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(data) refute Repo.get(Activity, activity.id) end @@ -401,8 +399,12 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do |> Poison.decode!() |> Map.put("actor", followed.ap_id) + object = accept_data["object"] + |> Map.put("actor", follower.ap_id) + |> Map.put("id", follow_activity.data["id"]) + accept_data = - Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id)) + Map.put(accept_data, "object", object) {:ok, activity} = Transmogrifier.handle_incoming(accept_data) refute activity.local @@ -499,7 +501,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do followed = insert(:user, %{info: %{"locked" => true}}) {:ok, follower} = User.follow(follower, followed) - {:ok, follow_activity} = ActivityPub.follow(follower, followed) + {:ok, _follow_activity} = ActivityPub.follow(follower, followed) assert User.following?(follower, followed) == true -- cgit v1.2.3 From 0a6c897c9488b26273a5fbb2de1ae1bfa0c96675 Mon Sep 17 00:00:00 2001 From: lain Date: Sat, 26 May 2018 15:11:50 +0200 Subject: Formatting. --- test/web/activity_pub/transmogrifier_test.exs | 10 +++++----- test/web/mastodon_api/mastodon_api_controller_test.exs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 43395eef1..384844095 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -399,12 +399,12 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do |> Poison.decode!() |> Map.put("actor", followed.ap_id) - object = accept_data["object"] - |> Map.put("actor", follower.ap_id) - |> Map.put("id", follow_activity.data["id"]) + object = + accept_data["object"] + |> Map.put("actor", follower.ap_id) + |> Map.put("id", follow_activity.data["id"]) - accept_data = - Map.put(accept_data, "object", object) + accept_data = Map.put(accept_data, "object", object) {:ok, activity} = Transmogrifier.handle_incoming(accept_data) refute activity.local diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 0f091b986..936d27182 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -298,7 +298,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do test "list timeline", %{conn: conn} do user = insert(:user) other_user = insert(:user) - {:ok, activity_one} = TwitterAPI.create_status(user, %{"status" => "Marisa is cute."}) + {:ok, _activity_one} = TwitterAPI.create_status(user, %{"status" => "Marisa is cute."}) {:ok, activity_two} = TwitterAPI.create_status(other_user, %{"status" => "Marisa is cute."}) {:ok, list} = Pleroma.List.create("name", user) {:ok, list} = Pleroma.List.follow(list, other_user) -- cgit v1.2.3