aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/fixtures/mastodon-block-activity.json29
-rw-r--r--test/fixtures/mastodon-reject-activity.json34
-rw-r--r--test/fixtures/mastodon-unblock-activity.json34
-rw-r--r--test/fixtures/mastodon-unfollow-activity.json34
-rw-r--r--test/fixtures/unfollow.xml68
-rw-r--r--test/list_test.exs77
-rw-r--r--test/support/factory.ex3
-rw-r--r--test/user_test.exs9
-rw-r--r--test/web/activity_pub/activity_pub_test.exs35
-rw-r--r--test/web/activity_pub/transmogrifier_test.exs233
-rw-r--r--test/web/common_api/common_api_test.exs13
-rw-r--r--test/web/common_api/common_api_utils_test.exs5
-rw-r--r--test/web/mastodon_api/list_view_test.exs19
-rw-r--r--test/web/mastodon_api/mastodon_api_controller_test.exs119
-rw-r--r--test/web/ostatus/ostatus_test.exs24
-rw-r--r--test/web/twitter_api/twitter_api_controller_test.exs79
-rw-r--r--test/web/twitter_api/twitter_api_test.exs4
-rw-r--r--test/web/twitter_api/views/notification_view_test.exs2
-rw-r--r--test/web/twitter_api/views/user_view_test.exs2
19 files changed, 810 insertions, 13 deletions
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-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/fixtures/mastodon-unblock-activity.json b/test/fixtures/mastodon-unblock-activity.json
new file mode 100644
index 000000000..f4a2d30dd
--- /dev/null
+++ b/test/fixtures/mastodon-unblock-activity.json
@@ -0,0 +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": "Block",
+ "object": "http://localtesting.pleroma.lol/users/lain",
+ "nickname": "lain",
+ "id": "http://mastodon.example.org/users/admin#blocks/2",
+ "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/fixtures/mastodon-unfollow-activity.json b/test/fixtures/mastodon-unfollow-activity.json
new file mode 100644
index 000000000..ae5ab7c66
--- /dev/null
+++ b/test/fixtures/mastodon-unfollow-activity.json
@@ -0,0 +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",
+ "id": "http://mastodon.example.org/users/admin#follow/2/undo"
+}
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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:georss="http://www.georss.org/georss" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:media="http://purl.org/syndication/atommedia" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:ostatus="http://ostatus.org/schema/1.0" xmlns:statusnet="http://status.net/schema/api/1/">
+ <generator uri="https://gnu.io/social" version="1.0.2-dev">GNU social</generator>
+ <id>https://social.heldscal.la/api/statuses/user_timeline/23211.atom</id>
+ <title>lambadalambda timeline</title>
+ <subtitle>Updates from lambadalambda on social.heldscal.la!</subtitle>
+ <logo>https://social.heldscal.la/avatar/23211-96-20170416114255.jpeg</logo>
+ <updated>2017-05-07T09:54:49+00:00</updated>
+<author>
+ <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
+ <uri>https://social.heldscal.la/user/23211</uri>
+ <name>lambadalambda</name>
+ <summary>Call me Deacon Blues.</summary>
+ <link rel="alternate" type="text/html" href="https://social.heldscal.la/lambadalambda"/>
+ <link rel="avatar" type="image/jpeg" media:width="236" media:height="236" href="https://social.heldscal.la/avatar/23211-original-20170416114255.jpeg"/>
+ <link rel="avatar" type="image/jpeg" media:width="96" media:height="96" href="https://social.heldscal.la/avatar/23211-96-20170416114255.jpeg"/>
+ <link rel="avatar" type="image/jpeg" media:width="48" media:height="48" href="https://social.heldscal.la/avatar/23211-48-20170416114255.jpeg"/>
+ <link rel="avatar" type="image/jpeg" media:width="24" media:height="24" href="https://social.heldscal.la/avatar/23211-24-20170416114257.jpeg"/>
+ <poco:preferredUsername>lambadalambda</poco:preferredUsername>
+ <poco:displayName>Constance Variable</poco:displayName>
+ <poco:note>Call me Deacon Blues.</poco:note>
+ <poco:address>
+ <poco:formatted>Berlin</poco:formatted>
+ </poco:address>
+ <poco:urls>
+ <poco:type>homepage</poco:type>
+ <poco:value>https://heldscal.la</poco:value>
+ <poco:primary>true</poco:primary>
+ </poco:urls>
+ <followers url="https://social.heldscal.la/lambadalambda/subscribers"></followers>
+ <statusnet:profile_info local_id="23211"></statusnet:profile_info>
+</author>
+ <link href="https://social.heldscal.la/lambadalambda" rel="alternate" type="text/html"/>
+ <link href="https://social.heldscal.la/main/sup" rel="http://api.friendfeed.com/2008/03#sup" type="application/json"/>
+ <link href="https://social.heldscal.la/main/push/hub" rel="hub"/>
+ <link href="https://social.heldscal.la/main/salmon/user/23211" rel="salmon"/>
+ <link href="https://social.heldscal.la/main/salmon/user/23211" rel="http://salmon-protocol.org/ns/salmon-replies"/>
+ <link href="https://social.heldscal.la/main/salmon/user/23211" rel="http://salmon-protocol.org/ns/salmon-mention"/>
+ <link href="https://social.heldscal.la/api/statuses/user_timeline/23211.atom" rel="self" type="application/atom+xml"/>
+<entry>
+ <id>undo:tag:social.heldscal.la,2017-05-07:subscription:23211:person:44803:2017-05-07T09:54:48+00:00</id>
+ <title>Constance Variable (lambadalambda@social.heldscal.la)'s status on Sunday, 07-May-2017 09:54:49 UTC</title>
+ <content type="html">&lt;a href=&quot;https://social.heldscal.la/lambadalambda&quot;&gt;Constance Variable&lt;/a&gt; stopped following &lt;a href=&quot;https://pawoo.net/@pekorino&quot;&gt;mono&lt;/a&gt;.</content>
+ <link rel="alternate" type="text/html" href="https://social.heldscal.la/notice/2092981"/>
+ <activity:verb>http://activitystrea.ms/schema/1.0/unfollow</activity:verb>
+ <published>2017-05-07T09:54:49+00:00</published>
+ <updated>2017-05-07T09:54:49+00:00</updated>
+ <activity:object>
+ <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
+ <id>https://pawoo.net/users/pekorino</id>
+ <title>mono</title>
+ <summary>http://shitposter.club/mono 孤独のグルメ</summary>
+ <link rel="alternate" type="text/html" href="https://pawoo.net/@pekorino"/>
+ <link rel="avatar" type="image/png" media:width="96" media:height="96" href="http://social.heldscal.la/theme/neo-gnu/default-avatar-profile.png"/>
+ <link rel="avatar" type="image/png" media:width="48" media:height="48" href="http://social.heldscal.la/theme/neo-gnu/default-avatar-stream.png"/>
+ <link rel="avatar" type="image/png" media:width="24" media:height="24" href="http://social.heldscal.la/theme/neo-gnu/default-avatar-mini.png"/>
+ <poco:preferredUsername>pekorino</poco:preferredUsername>
+ <poco:displayName>mono</poco:displayName>
+ <poco:note>http://shitposter.club/mono 孤独のグルメ</poco:note>
+ </activity:object>
+ <link rel="ostatus:conversation" href="https://social.heldscal.la/conversation/1079786"/>
+ <ostatus:conversation href="https://social.heldscal.la/conversation/1079786" local_id="1079786" ref="tag:social.heldscal.la,2017-05-07:objectType=thread:nonce=6e80caf94e03029f">tag:social.heldscal.la,2017-05-07:objectType=thread:nonce=6e80caf94e03029f</ostatus:conversation>
+ <link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
+ <link rel="self" type="application/atom+xml" href="https://social.heldscal.la/api/statuses/show/2092981.atom"/>
+ <link rel="edit" type="application/atom+xml" href="https://social.heldscal.la/api/statuses/show/2092981.atom"/>
+ <statusnet:notice_info local_id="2092981" source="activity"></statusnet:notice_info>
+</entry>
+</feed>
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/support/factory.ex b/test/support/factory.ex
index 47626cb3e..5cf456e3c 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -122,7 +122,8 @@ defmodule Pleroma.Factory do
}
%Pleroma.Activity{
- data: data
+ data: data,
+ actor: follower.ap_id
}
end
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)
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 9adce84b5..081c202b1 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -425,7 +425,40 @@ 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 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
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index a0af75a69..384844095 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -2,13 +2,12 @@ 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
alias Pleroma.Repo
alias Pleroma.Web.Websub.WebsubClientSubscription
- alias Pleroma.Web.Websub.WebsubServerSubscription
- import Ecto.Query
import Pleroma.Factory
alias Pleroma.Web.CommonAPI
@@ -283,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
@@ -315,6 +314,234 @@ 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 with an existing follow" 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["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"] == "http://mastodon.example.org/users/admin"
+
+ blocker = User.get_by_ap_id(data["actor"])
+
+ assert User.blocks?(blocker, user)
+ end
+
+ test "it works for incoming unblocks with an existing block" 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"] == "http://mastodon.example.org/users/admin"
+
+ blocker = User.get_by_ap_id(data["actor"])
+
+ 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
+
+ {: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)
+
+ 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)
+
+ {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
+ refute activity.local
+
+ assert activity.data["object"] == follow_activity.data["id"]
+
+ 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} = Transmogrifier.handle_incoming(accept_data)
+ assert activity.data["object"] == follow_activity.data["id"]
+
+ 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} = Transmogrifier.handle_incoming(accept_data)
+ assert activity.data["object"] == follow_activity.data["id"]
+
+ follower = Repo.get(User, follower.id)
+
+ 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 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}})
+
+ {: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} = Transmogrifier.handle_incoming(reject_data)
+ refute activity.local
+
+ 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
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..a5da271b3
--- /dev/null
+++ b/test/web/common_api/common_api_test.exs
@@ -0,0 +1,13 @@
+defmodule Pleroma.Web.CommonAPI.Test do
+ use Pleroma.DataCase
+ alias Pleroma.Web.CommonAPI
+
+ import Pleroma.Factory
+
+ test "it de-duplicates tags" do
+ user = insert(:user)
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu #2HU"})
+
+ assert activity.data["object"]["tag"] == ["2hu"]
+ end
+end
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index 23cce471f..f39472ee3 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -21,13 +21,12 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
test "incorrect password given" do
{:ok, user} = UserBuilder.insert()
- assert Utils.confirm_current_password(user, %{"password" => ""}) ==
- {:error, "Invalid password."}
+ assert Utils.confirm_current_password(user, "") == {:error, "Invalid password."}
end
test "correct password given" do
{:ok, user} = UserBuilder.insert()
- assert Utils.confirm_current_password(user, %{"password" => "test"}) == {:ok, user}
+ assert Utils.confirm_current_password(user, "test") == {:ok, user}
end
end
end
diff --git a/test/web/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 72f948230..553581be4 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -229,6 +229,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)
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)
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 02aba0bc8..c2ea41aa3 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -8,6 +8,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
alias Pleroma.Web.TwitterAPI.NotificationView
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.TwitterAPI.TwitterAPI
+ alias Comeonin.Pbkdf2
import Pleroma.Factory
@@ -443,7 +444,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 =
@@ -801,6 +802,82 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert user.bio == "Hello,<br>World! I<br> am a test."
end
+ describe "POST /api/pleroma/change_password" do
+ setup [:valid_user]
+
+ test "without credentials", %{conn: conn} do
+ conn = post(conn, "/api/pleroma/change_password")
+ assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
+ end
+
+ test "with credentials and invalid password", %{conn: conn, user: current_user} do
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/pleroma/change_password", %{
+ "password" => "hi",
+ "new_password" => "newpass",
+ "new_password_confirmation" => "newpass"
+ })
+
+ assert json_response(conn, 200) == %{"error" => "Invalid password."}
+ end
+
+ test "with credentials, valid password and new password and confirmation not matching", %{
+ conn: conn,
+ user: current_user
+ } do
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/pleroma/change_password", %{
+ "password" => "test",
+ "new_password" => "newpass",
+ "new_password_confirmation" => "notnewpass"
+ })
+
+ assert json_response(conn, 200) == %{
+ "error" => "New password does not match confirmation."
+ }
+ end
+
+ test "with credentials, valid password and invalid new password", %{
+ conn: conn,
+ user: current_user
+ } do
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/pleroma/change_password", %{
+ "password" => "test",
+ "new_password" => "",
+ "new_password_confirmation" => ""
+ })
+
+ assert json_response(conn, 200) == %{
+ "error" => "New password can't be blank."
+ }
+ end
+
+ test "with credentials, valid password and matching new password and confirmation", %{
+ conn: conn,
+ user: current_user
+ } do
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/pleroma/change_password", %{
+ "password" => "test",
+ "new_password" => "newpass",
+ "new_password_confirmation" => "newpass"
+ })
+
+ assert json_response(conn, 200) == %{"status" => "success"}
+ fetched_user = Repo.get(User, current_user.id)
+ assert Pbkdf2.checkpw("newpass", fetched_user.password_hash) == true
+ end
+ end
+
describe "POST /api/pleroma/delete_account" do
setup [:valid_user]
diff --git a/test/web/twitter_api/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"] == []
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"