aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/fixtures/incoming_note_activity.xml40
-rw-r--r--test/fixtures/user_full.xml10
-rw-r--r--test/fixtures/user_name_only.xml5
-rw-r--r--test/support/factory.ex6
-rw-r--r--test/web/ostatus/activity_representer_test.exs2
-rw-r--r--test/web/ostatus/feed_representer_test.exs3
-rw-r--r--test/web/ostatus/ostatus_test.exs55
7 files changed, 118 insertions, 3 deletions
diff --git a/test/fixtures/incoming_note_activity.xml b/test/fixtures/incoming_note_activity.xml
new file mode 100644
index 000000000..e54b25e39
--- /dev/null
+++ b/test/fixtures/incoming_note_activity.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8" ?><entry xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:georss="http://www.georss.org/georss" xmlns:ostatus="http://ostatus.org/schema/1.0" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:media="http://purl.org/syndication/atommedia" xmlns:statusnet="http://status.net/schema/api/1/">
+ <activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
+ <id>tag:gs.example.org:4040,2017-04-23:noticeId=29:objectType=note</id>
+ <title>New note by lambda</title>
+ <content type="html">@&lt;a href=&quot;http://pleroma.example.org:4000/users/lain3&quot; class=&quot;h-card mention&quot;&gt;lain3&lt;/a&gt;</content>
+ <link rel="alternate" type="text/html" href="http://gs.example.org:4040/index.php/notice/29"/>
+ <status_net notice_id="29"></status_net>
+ <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
+ <published>2017-04-23T14:51:03+00:00</published>
+ <updated>2017-04-23T14:51:03+00:00</updated>
+ <author>
+ <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
+ <uri>http://gs.example.org:4040/index.php/user/1</uri>
+ <name>lambda</name>
+ <link rel="alternate" type="text/html" href="http://gs.example.org:4040/index.php/lambda"/>
+ <link rel="avatar" type="image/png" media:width="96" media:height="96" href="http://gs.example.org:4040/theme/neo-gnu/default-avatar-profile.png"/>
+ <link rel="avatar" type="image/png" media:width="48" media:height="48" href="http://gs.example.org:4040/theme/neo-gnu/default-avatar-stream.png"/>
+ <link rel="avatar" type="image/png" media:width="24" media:height="24" href="http://gs.example.org:4040/theme/neo-gnu/default-avatar-mini.png"/>
+ <poco:preferredUsername>lambda</poco:preferredUsername>
+ <poco:displayName>lambda</poco:displayName>
+ <followers url="http://gs.example.org:4040/index.php/lambda/subscribers"></followers>
+ <statusnet:profile_info local_id="1"></statusnet:profile_info>
+ </author>
+ <link rel="ostatus:conversation" href="tag:gs.example.org:4040,2017-04-23:objectType=thread:nonce=f09e22f58abd5c7b"/>
+ <ostatus:conversation>tag:gs.example.org:4040,2017-04-23:objectType=thread:nonce=f09e22f58abd5c7b</ostatus:conversation>
+ <link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="http://pleroma.example.org:4000/users/lain3"/>
+ <link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
+ <source>
+ <id>http://gs.example.org:4040/index.php/api/statuses/user_timeline/1.atom</id>
+ <title>lambda</title>
+ <link rel="alternate" type="text/html" href="http://gs.example.org:4040/index.php/lambda"/>
+ <link rel="self" type="application/atom+xml" href="http://gs.example.org:4040/index.php/api/statuses/user_timeline/1.atom"/>
+ <link rel="license" href="https://creativecommons.org/licenses/by/3.0/"/>
+ <icon>http://gs.example.org:4040/theme/neo-gnu/default-avatar-profile.png</icon>
+ <updated>2017-04-23T14:51:03+00:00</updated>
+ </source>
+ <link rel="self" type="application/atom+xml" href="http://gs.example.org:4040/index.php/api/statuses/show/29.atom"/>
+ <link rel="edit" type="application/atom+xml" href="http://gs.example.org:4040/index.php/api/statuses/show/29.atom"/>
+ <statusnet:notice_info local_id="29" source="web"></statusnet:notice_info>
+</entry>
diff --git a/test/fixtures/user_full.xml b/test/fixtures/user_full.xml
new file mode 100644
index 000000000..8eee8c686
--- /dev/null
+++ b/test/fixtures/user_full.xml
@@ -0,0 +1,10 @@
+<author>
+ <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
+ <uri>http://gs.example.org:4040/index.php/user/1</uri>
+ <name>lambda</name>
+ <link rel="avatar" type="image/png" media:width="96" media:height="96" href="http://gs.example.org:4040/theme/neo-gnu/default-avatar-profile.png"/>
+ <link rel="avatar" type="image/png" media:width="48" media:height="48" href="http://gs.example.org:4040/theme/neo-gnu/default-avatar-stream.png"/>
+ <link rel="avatar" type="image/png" media:width="24" media:height="24" href="http://gs.example.org:4040/theme/neo-gnu/default-avatar-mini.png"/>
+ <poco:preferredUsername>Constance Variable</poco:preferredUsername>
+ <poco:displayName>lambadalambda</poco:displayName>
+</author>
diff --git a/test/fixtures/user_name_only.xml b/test/fixtures/user_name_only.xml
new file mode 100644
index 000000000..6d895d5c2
--- /dev/null
+++ b/test/fixtures/user_name_only.xml
@@ -0,0 +1,5 @@
+<author>
+ <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
+ <uri>http://gs.example.org:4040/index.php/user/1</uri>
+ <name>lambda</name>
+</author>
diff --git a/test/support/factory.ex b/test/support/factory.ex
index d7c16f0e0..d037be4a6 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -24,7 +24,8 @@ defmodule Pleroma.Factory do
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
"published_at" => DateTime.utc_now() |> DateTime.to_iso8601,
"likes" => [],
- "like_count" => 0
+ "like_count" => 0,
+ "context" => "2hu"
}
%Pleroma.Object{
@@ -40,7 +41,8 @@ defmodule Pleroma.Factory do
"actor" => note.data["actor"],
"to" => note.data["to"],
"object" => note.data,
- "published_at" => DateTime.utc_now() |> DateTime.to_iso8601
+ "published_at" => DateTime.utc_now() |> DateTime.to_iso8601,
+ "context" => note.data["context"]
}
%Pleroma.Activity{
diff --git a/test/web/ostatus/activity_representer_test.exs b/test/web/ostatus/activity_representer_test.exs
index 61df41a1d..10f9a9d0b 100644
--- a/test/web/ostatus/activity_representer_test.exs
+++ b/test/web/ostatus/activity_representer_test.exs
@@ -23,6 +23,8 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
<content type="html">#{note_activity.data["object"]["content"]}</content>
<published>#{inserted_at}</published>
<updated>#{updated_at}</updated>
+ <ostatus:conversation>#{note_activity.data["context"]}</ostatus:conversation>
+ <link href="#{note_activity.data["context"]}" rel="ostatus:conversation" />
"""
tuple = ActivityRepresenter.to_simple_form(note_activity, user)
diff --git a/test/web/ostatus/feed_representer_test.exs b/test/web/ostatus/feed_representer_test.exs
index 9a02d8c16..ef0f4d5ff 100644
--- a/test/web/ostatus/feed_representer_test.exs
+++ b/test/web/ostatus/feed_representer_test.exs
@@ -22,11 +22,12 @@ defmodule Pleroma.Web.OStatus.FeedRepresenterTest do
|> :xmerl.export_simple_content(:xmerl_xml)
expected = """
- <feed xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:poco="http://portablecontacts.net/spec/1.0">
+ <feed xmlns="http://www.w3.org/2005/Atom" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:ostatus="http://ostatus.org/schema/1.0">
<id>#{OStatus.feed_path(user)}</id>
<title>#{user.nickname}'s timeline</title>
<updated>#{most_recent_update}</updated>
<link rel="hub" href="#{OStatus.pubsub_path(user)}" />
+ <link rel="salmon" href="#{OStatus.salmon_path(user)}" />
<link rel="self" href="#{OStatus.feed_path(user)}" />
<author>
#{user_xml}
diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs
new file mode 100644
index 000000000..dffebf5a7
--- /dev/null
+++ b/test/web/ostatus/ostatus_test.exs
@@ -0,0 +1,55 @@
+defmodule Pleroma.Web.OStatusTest do
+ use Pleroma.DataCase
+ alias Pleroma.Web.OStatus
+
+ test "handle incoming notes" do
+ incoming = File.read!("test/fixtures/incoming_note_activity.xml")
+ {:ok, activity} = OStatus.handle_incoming(incoming)
+
+ assert activity.data["type"] == "Create"
+ assert activity.data["object"]["type"] == "Note"
+ assert activity.data["published"] == "2017-04-23T14:51:03+00:00"
+ assert activity.data["context"] == "tag:gs.example.org:4040,2017-04-23:objectType=thread:nonce=f09e22f58abd5c7b"
+ assert "http://pleroma.example.org:4000/users/lain3" in activity.data["to"]
+ end
+
+ describe "new remote user creation" do
+ test "make new user or find them based on an 'author' xml doc" do
+ incoming = File.read!("test/fixtures/user_name_only.xml")
+ {doc, _rest} = :xmerl_scan.string(to_charlist(incoming))
+
+ {:ok, user} = OStatus.find_or_make_user(doc)
+
+ assert user.name == "lambda"
+ assert user.nickname == "lambda"
+ assert user.local == false
+ assert user.info["ostatus_uri"] == "http://gs.example.org:4040/index.php/user/1"
+ assert user.info["system"] == "ostatus"
+ assert user.ap_id == "http://gs.example.org:4040/index.php/user/1"
+
+ {:ok, user_again} = OStatus.find_or_make_user(doc)
+
+ assert user == user_again
+ end
+
+ test "tries to use the information in poco fields" do
+ incoming = File.read!("test/fixtures/user_full.xml")
+ {doc, _rest} = :xmerl_scan.string(to_charlist(incoming))
+
+ {:ok, user} = OStatus.find_or_make_user(doc)
+
+ assert user.name == "Constance Variable"
+ assert user.nickname == "lambadalambda"
+ assert user.local == false
+ assert user.info["ostatus_uri"] == "http://gs.example.org:4040/index.php/user/1"
+ assert user.info["system"] == "ostatus"
+ assert user.ap_id == "http://gs.example.org:4040/index.php/user/1"
+
+ assert List.first(user.avatar["url"])["href"] == "http://gs.example.org:4040/theme/neo-gnu/default-avatar-profile.png"
+
+ {:ok, user_again} = OStatus.find_or_make_user(doc)
+
+ assert user == user_again
+ end
+ end
+end