Add tests for incoming unfollow over OStatus
authorFrancis Dinh <normandy@firemail.cc>
Mon, 21 May 2018 09:11:13 +0000 (05:11 -0400)
committerFrancis Dinh <normandy@firemail.cc>
Mon, 21 May 2018 09:11:13 +0000 (05:11 -0400)
lib/pleroma/web/ostatus/activity_representer.ex
test/fixtures/unfollow.xml [new file with mode: 0644]
test/web/ostatus/ostatus_test.exs

index a9c2b89b4d9b1c8bde5e43928085c61a8d3e4d6e..4179d86c9b354adb1501c5de6d3cae3a6a805183 100644 (file)
@@ -247,6 +247,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
 
     mentions = (activity.recipients || []) |> get_mentions
     follow_activity = Activity.get_by_ap_id(follow_activity["id"])
+
     [
       {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/activity']},
       {:"activity:verb", ['http://activitystrea.ms/schema/1.0/unfollow']},
diff --git a/test/fixtures/unfollow.xml b/test/fixtures/unfollow.xml
new file mode 100644 (file)
index 0000000..7a8f8fd
--- /dev/null
@@ -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>
index 3e7cf01556e764fd41742e7b5acad336c25db079..f095e41dd1e26514603396682cee77a32269e380 100644 (file)
@@ -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)