aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/fixtures/salmon.xml2
-rw-r--r--test/support/factory.ex12
-rw-r--r--test/web/ostatus/activity_representer_test.exs43
-rw-r--r--test/web/ostatus/feed_representer_test.exs45
-rw-r--r--test/web/ostatus/ostatus_controller_test.exs15
-rw-r--r--test/web/ostatus/user_representer_test.exs31
-rw-r--r--test/web/salmon/salmon_test.exs19
-rw-r--r--test/web/twitter_api/twitter_api_controller_test.exs37
-rw-r--r--test/web/web_finger/web_finger_test.exs11
-rw-r--r--test/web/websub/websub_controller_test.exs23
-rw-r--r--test/web/websub/websub_test.exs90
-rw-r--r--test/xml_builder_test.exs59
12 files changed, 378 insertions, 9 deletions
diff --git a/test/fixtures/salmon.xml b/test/fixtures/salmon.xml
new file mode 100644
index 000000000..fadcd3219
--- /dev/null
+++ b/test/fixtures/salmon.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<me:env xmlns:me="http://salmon-protocol.org/ns/magic-env"><me:data type="application/atom+xml">PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiID8-PGVudHJ5IHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDA1L0F0b20iIHhtbG5zOnRocj0iaHR0cDovL3B1cmwub3JnL3N5bmRpY2F0aW9uL3RocmVhZC8xLjAiIHhtbG5zOmFjdGl2aXR5PSJodHRwOi8vYWN0aXZpdHlzdHJlYS5tcy9zcGVjLzEuMC8iIHhtbG5zOmdlb3Jzcz0iaHR0cDovL3d3dy5nZW9yc3Mub3JnL2dlb3JzcyIgeG1sbnM6b3N0YXR1cz0iaHR0cDovL29zdGF0dXMub3JnL3NjaGVtYS8xLjAiIHhtbG5zOnBvY289Imh0dHA6Ly9wb3J0YWJsZWNvbnRhY3RzLm5ldC9zcGVjLzEuMCIgeG1sbnM6bWVkaWE9Imh0dHA6Ly9wdXJsLm9yZy9zeW5k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A2ZGU5PC9pZD4KICA8dGl0bGU-TmV3IG5vdGUgYnkgbGFpbjI8L3RpdGxlPgogIDxjb250ZW50IHR5cGU9Imh0bWwiPkhlbGxvLjwvY29udGVudD4KICA8bGluayByZWw9ImFsdGVybmF0ZSIgdHlwZT0idGV4dC9odG1sIiBocmVmPSJodHRwOi8vcGxlcm9tYS5leGFtcGxlLm9yZzo0MDAwL29iamVjdHMvZTI4OTZmYzEtNjU4Yi00MmE3LWEzNjItZTI1OGQzOTA2ZGU5Ii8-CiAgPHN0YXR1c19uZXQgbm90aWNlX2lkPSI4Ij48L3N0YXR1c19uZXQ-CiA8L2FjdGl2aXR5Om9iamVjdD4KPC9lbnRyeT4K</me:data><me:encoding>base64url</me:encoding><me:alg>RSA-SHA256</me:alg><me:sig>ZXXHgp_ihTZIJnnFiQuJD0TSvo4OIqrpblHHQQwfpCy-85mtTf0QO1LclX3P3Ra8BqAmhs7j9nDxuEGLuVLTt53DvMP-pOjCtWYDKBbEZQtFIVnCcvBzGPW1HmimdN49M3VtAohbhfVilTrApQpGnI6kHvx7G1fQdQxHRtMsdNI=</me:sig></me:env> \ No newline at end of file
diff --git a/test/support/factory.ex b/test/support/factory.ex
index b7dead7f6..1662d4cd6 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -3,7 +3,7 @@ defmodule Pleroma.Factory do
def user_factory do
user = %Pleroma.User{
- name: sequence(:name, &"Test User #{&1}"),
+ name: sequence(:name, &"Test テスト User #{&1}"),
email: sequence(:email, &"user#{&1}@example.com"),
nickname: sequence(:nickname, &"nick#{&1}"),
password_hash: Comeonin.Pbkdf2.hashpwsalt("test"),
@@ -81,4 +81,14 @@ defmodule Pleroma.Factory do
data: data
}
end
+
+ def websub_subscription_factory do
+ %Pleroma.Web.Websub.WebsubServerSubscription{
+ topic: "http://example.org",
+ callback: "http://example/org/callback",
+ secret: "here's a secret",
+ valid_until: NaiveDateTime.add(NaiveDateTime.utc_now, 100),
+ state: "requested"
+ }
+ end
end
diff --git a/test/web/ostatus/activity_representer_test.exs b/test/web/ostatus/activity_representer_test.exs
new file mode 100644
index 000000000..61df41a1d
--- /dev/null
+++ b/test/web/ostatus/activity_representer_test.exs
@@ -0,0 +1,43 @@
+defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.Web.OStatus.ActivityRepresenter
+ alias Pleroma.{User, Activity}
+
+ import Pleroma.Factory
+
+ test "a note activity" do
+ note_activity = insert(:note_activity)
+ updated_at = note_activity.updated_at
+ |> NaiveDateTime.to_iso8601
+ inserted_at = note_activity.inserted_at
+ |> NaiveDateTime.to_iso8601
+
+ user = User.get_cached_by_ap_id(note_activity.data["actor"])
+
+ expected = """
+ <activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
+ <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
+ <id>#{note_activity.data["object"]["id"]}</id>
+ <title>New note by #{user.nickname}</title>
+ <content type="html">#{note_activity.data["object"]["content"]}</content>
+ <published>#{inserted_at}</published>
+ <updated>#{updated_at}</updated>
+ """
+
+ tuple = ActivityRepresenter.to_simple_form(note_activity, user)
+
+ res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary
+
+ assert clean(res) == clean(expected)
+ end
+
+ test "an unknown activity" do
+ tuple = ActivityRepresenter.to_simple_form(%Activity{}, nil)
+ assert is_nil(tuple)
+ end
+
+ defp clean(string) do
+ String.replace(string, ~r/\s/, "")
+ end
+end
diff --git a/test/web/ostatus/feed_representer_test.exs b/test/web/ostatus/feed_representer_test.exs
new file mode 100644
index 000000000..9a02d8c16
--- /dev/null
+++ b/test/web/ostatus/feed_representer_test.exs
@@ -0,0 +1,45 @@
+defmodule Pleroma.Web.OStatus.FeedRepresenterTest do
+ use Pleroma.DataCase
+ import Pleroma.Factory
+ alias Pleroma.User
+ alias Pleroma.Web.OStatus.{FeedRepresenter, UserRepresenter, ActivityRepresenter}
+ alias Pleroma.Web.OStatus
+
+ test "returns a feed of the last 20 items of the user" do
+ note_activity = insert(:note_activity)
+ user = User.get_cached_by_ap_id(note_activity.data["actor"])
+
+ tuple = FeedRepresenter.to_simple_form(user, [note_activity], [user])
+
+ most_recent_update = note_activity.updated_at
+ |> NaiveDateTime.to_iso8601
+
+ res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> to_string
+ user_xml = UserRepresenter.to_simple_form(user)
+ |> :xmerl.export_simple_content(:xmerl_xml)
+
+ entry_xml = ActivityRepresenter.to_simple_form(note_activity, user)
+ |> :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">
+ <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="self" href="#{OStatus.feed_path(user)}" />
+ <author>
+ #{user_xml}
+ </author>
+ <entry>
+ #{entry_xml}
+ </entry>
+ </feed>
+ """
+ assert clean(res) == clean(expected)
+ end
+
+ defp clean(string) do
+ String.replace(string, ~r/\s/, "")
+ end
+end
diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs
new file mode 100644
index 000000000..229cd9b1e
--- /dev/null
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -0,0 +1,15 @@
+defmodule Pleroma.Web.OStatus.OStatusControllerTest do
+ use Pleroma.Web.ConnCase
+ import Pleroma.Factory
+ alias Pleroma.User
+
+ test "gets a feed", %{conn: conn} do
+ note_activity = insert(:note_activity)
+ user = User.get_cached_by_ap_id(note_activity.data["actor"])
+
+ conn = conn
+ |> get("/users/#{user.nickname}/feed.atom")
+
+ assert response(conn, 200)
+ end
+end
diff --git a/test/web/ostatus/user_representer_test.exs b/test/web/ostatus/user_representer_test.exs
new file mode 100644
index 000000000..a4afc2cf7
--- /dev/null
+++ b/test/web/ostatus/user_representer_test.exs
@@ -0,0 +1,31 @@
+defmodule Pleroma.Web.OStatus.UserRepresenterTest do
+ use Pleroma.DataCase
+ alias Pleroma.Web.OStatus.UserRepresenter
+
+ import Pleroma.Factory
+ alias Pleroma.User
+
+ test "returns a user with id, uri, name and link" do
+ user = build(:user, nickname: "レイン")
+ tuple = UserRepresenter.to_simple_form(user)
+
+ res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> to_string
+
+ expected = """
+ <id>#{user.ap_id}</id>
+ <activity:object>http://activitystrea.ms/schema/1.0/person</activity:object>
+ <uri>#{user.ap_id}</uri>
+ <poco:preferredUsername>#{user.nickname}</poco:preferredUsername>
+ <poco:displayName>#{user.name}</poco:displayName>
+ <poco:note>#{user.bio}</poco:note>
+ <name>#{user.nickname}</name>
+ <link rel="avatar" href="#{User.avatar_url(user)}" />
+ """
+
+ assert clean(res) == clean(expected)
+ end
+
+ defp clean(string) do
+ String.replace(string, ~r/\s/, "")
+ end
+end
diff --git a/test/web/salmon/salmon_test.exs b/test/web/salmon/salmon_test.exs
new file mode 100644
index 000000000..4ebb32081
--- /dev/null
+++ b/test/web/salmon/salmon_test.exs
@@ -0,0 +1,19 @@
+defmodule Pleroma.Web.Salmon.SalmonTest do
+ use Pleroma.DataCase
+ alias Pleroma.Web.Salmon
+
+ @magickey "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwQhh-1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
+
+ @wrong_magickey "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwQhh-1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAA"
+
+ test "decodes a salmon" do
+ {:ok, salmon} = File.read("test/fixtures/salmon.xml")
+ {:ok, doc} = Salmon.decode_and_validate(@magickey, salmon)
+ assert Regex.match?(~r/xml/, doc)
+ end
+
+ test "errors on wrong magic key" do
+ {:ok, salmon} = File.read("test/fixtures/salmon.xml")
+ assert Salmon.decode_and_validate(@wrong_magickey, salmon) == :error
+ end
+end
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 0761d0566..6c249be7d 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -31,10 +31,21 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
end
test "with credentials", %{conn: conn, user: user} do
- conn = conn
- |> with_credentials(user.nickname, "test")
- |> post("/api/statuses/update.json", %{ status: "Nice meme." })
+ conn_with_creds = conn |> with_credentials(user.nickname, "test")
+ request_path = "/api/statuses/update.json"
+
+ error_response = %{"request" => request_path,
+ "error" => "Client must provide a 'status' parameter with a value."}
+ conn = conn_with_creds |> post(request_path)
+ assert json_response(conn, 400) == error_response
+
+ conn = conn_with_creds |> post(request_path, %{ status: "" })
+ assert json_response(conn, 400) == error_response
+
+ conn = conn_with_creds |> post(request_path, %{ status: " " })
+ assert json_response(conn, 400) == error_response
+ conn = conn_with_creds |> post(request_path, %{ status: "Nice meme." })
assert json_response(conn, 200) == ActivityRepresenter.to_map(Repo.one(Activity), %{user: user})
end
end
@@ -139,7 +150,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
setup [:valid_user]
test "without any params", %{conn: conn} do
conn = get(conn, "/api/statuses/user_timeline.json")
- assert json_response(conn, 400) == %{"error" => "You need to specify screen_name or user_id"}
+ assert json_response(conn, 400) == %{"error" => "You need to specify screen_name or user_id", "request" => "/api/statuses/user_timeline.json"}
end
test "with user_id", %{conn: conn} do
@@ -320,11 +331,21 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
test "with credentials", %{conn: conn, user: current_user} do
note_activity = insert(:note_activity)
- conn = conn
- |> with_credentials(current_user.nickname, "test")
- |> post("/api/statuses/retweet/#{note_activity.id}.json")
+ request_path = "/api/statuses/retweet/#{note_activity.id}.json"
- assert json_response(conn, 200)
+ user = Repo.get_by(User, ap_id: note_activity.data["actor"])
+ response = conn
+ |> with_credentials(user.nickname, "test")
+ |> post(request_path)
+ assert json_response(response, 400) == %{"error" => "You cannot repeat your own notice.",
+ "request" => request_path}
+
+ response = conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post(request_path)
+ activity = Repo.get(Activity, note_activity.id)
+ activity_user = Repo.get_by(User, ap_id: note_activity.data["actor"])
+ assert json_response(response, 200) == ActivityRepresenter.to_map(activity, %{user: activity_user, for: current_user})
end
end
diff --git a/test/web/web_finger/web_finger_test.exs b/test/web/web_finger/web_finger_test.exs
new file mode 100644
index 000000000..8a3007ff9
--- /dev/null
+++ b/test/web/web_finger/web_finger_test.exs
@@ -0,0 +1,11 @@
+defmodule Pleroma.Web.WebFingerTest do
+ use Pleroma.DataCase
+
+ describe "host meta" do
+ test "returns a link to the xml lrdd" do
+ host_info = Pleroma.Web.WebFinger.host_meta
+
+ assert String.contains?(host_info, Pleroma.Web.base_url)
+ end
+ end
+end
diff --git a/test/web/websub/websub_controller_test.exs b/test/web/websub/websub_controller_test.exs
new file mode 100644
index 000000000..8368cafea
--- /dev/null
+++ b/test/web/websub/websub_controller_test.exs
@@ -0,0 +1,23 @@
+defmodule Pleroma.Web.Websub.WebsubControllerTest do
+ use Pleroma.Web.ConnCase
+ import Pleroma.Factory
+
+ test "websub subscription request", %{conn: conn} do
+ user = insert(:user)
+
+ path = Pleroma.Web.OStatus.pubsub_path(user)
+
+ data = %{
+ "hub.callback": "http://example.org/sub",
+ "hub.mode": "subscribe",
+ "hub.topic": Pleroma.Web.OStatus.feed_path(user),
+ "hub.secret": "a random secret",
+ "hub.lease_seconds": "100"
+ }
+
+ conn = conn
+ |> post(path, data)
+
+ assert response(conn, 202) == "Accepted"
+ end
+end
diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs
new file mode 100644
index 000000000..334ba03fc
--- /dev/null
+++ b/test/web/websub/websub_test.exs
@@ -0,0 +1,90 @@
+defmodule Pleroma.Web.WebsubMock do
+ def verify(sub) do
+ {:ok, sub}
+ end
+end
+defmodule Pleroma.Web.WebsubTest do
+ use Pleroma.DataCase
+ alias Pleroma.Web.Websub
+ alias Pleroma.Web.Websub.WebsubServerSubscription
+ import Pleroma.Factory
+
+ test "a verification of a request that is accepted" do
+ sub = insert(:websub_subscription)
+ topic = sub.topic
+
+ getter = fn (_path, _headers, options) ->
+ %{
+ "hub.challenge": challenge,
+ "hub.lease_seconds": seconds,
+ "hub.topic": ^topic,
+ "hub.mode": "subscribe"
+ } = Keyword.get(options, :params)
+
+ assert String.to_integer(seconds) > 0
+
+ {:ok, %HTTPoison.Response{
+ status_code: 200,
+ body: challenge
+ }}
+ end
+
+ {:ok, sub} = Websub.verify(sub, getter)
+ assert sub.state == "active"
+ end
+
+ test "a verification of a request that doesn't return 200" do
+ sub = insert(:websub_subscription)
+
+ getter = fn (_path, _headers, _options) ->
+ {:ok, %HTTPoison.Response{
+ status_code: 500,
+ body: ""
+ }}
+ end
+
+ {:error, sub} = Websub.verify(sub, getter)
+ assert sub.state == "rejected"
+ end
+
+ test "an incoming subscription request" do
+ user = insert(:user)
+
+ data = %{
+ "hub.callback" => "http://example.org/sub",
+ "hub.mode" => "subscribe",
+ "hub.topic" => Pleroma.Web.OStatus.feed_path(user),
+ "hub.secret" => "a random secret",
+ "hub.lease_seconds" => "100"
+ }
+
+
+ {:ok, subscription } = Websub.incoming_subscription_request(user, data)
+ assert subscription.topic == Pleroma.Web.OStatus.feed_path(user)
+ assert subscription.state == "requested"
+ assert subscription.secret == "a random secret"
+ assert subscription.callback == "http://example.org/sub"
+ end
+
+ test "an incoming subscription request for an existing subscription" do
+ user = insert(:user)
+ sub = insert(:websub_subscription, state: "accepted", topic: Pleroma.Web.OStatus.feed_path(user))
+
+ data = %{
+ "hub.callback" => sub.callback,
+ "hub.mode" => "subscribe",
+ "hub.topic" => Pleroma.Web.OStatus.feed_path(user),
+ "hub.secret" => "a random secret",
+ "hub.lease_seconds" => "100"
+ }
+
+
+ {:ok, subscription } = Websub.incoming_subscription_request(user, data)
+ assert subscription.topic == Pleroma.Web.OStatus.feed_path(user)
+ assert subscription.state == sub.state
+ assert subscription.secret == "a random secret"
+ assert subscription.callback == sub.callback
+ assert length(Repo.all(WebsubServerSubscription)) == 1
+ assert subscription.id == sub.id
+ end
+end
diff --git a/test/xml_builder_test.exs b/test/xml_builder_test.exs
new file mode 100644
index 000000000..f502a0f0e
--- /dev/null
+++ b/test/xml_builder_test.exs
@@ -0,0 +1,59 @@
+defmodule Pleroma.XmlBuilderTest do
+ use Pleroma.DataCase
+ alias Pleroma.XmlBuilder
+
+ test "Build a basic xml string from a tuple" do
+ data = { :feed, %{ xmlns: "http://www.w3.org/2005/Atom"}, "Some content" }
+
+ expected_xml = "<feed xmlns=\"http://www.w3.org/2005/Atom\">Some content</feed>"
+
+ assert XmlBuilder.to_xml(data) == expected_xml
+ end
+
+ test "returns a complete document" do
+ data = { :feed, %{ xmlns: "http://www.w3.org/2005/Atom"}, "Some content" }
+
+ expected_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><feed xmlns=\"http://www.w3.org/2005/Atom\">Some content</feed>"
+
+ assert XmlBuilder.to_doc(data) == expected_xml
+ end
+
+ test "Works without attributes" do
+ data = {
+ :feed,
+ "Some content"
+ }
+
+ expected_xml = "<feed>Some content</feed>"
+
+ assert XmlBuilder.to_xml(data) == expected_xml
+ end
+
+ test "It works with nested tuples" do
+ data = {
+ :feed,
+ [
+ {:guy, "brush"},
+ {:lament, %{ configuration: "puzzle" }, "pinhead" }
+ ]
+ }
+
+ expected_xml = ~s[<feed><guy>brush</guy><lament configuration="puzzle">pinhead</lament></feed>]
+
+ assert XmlBuilder.to_xml(data) == expected_xml
+ end
+
+ test "Represents NaiveDateTime as iso8601" do
+ assert XmlBuilder.to_xml(~N[2000-01-01 13:13:33]) == "2000-01-01T13:13:33"
+ end
+
+ test "Uses self-closing tags when no content is giving" do
+ data = {
+ :link,
+ %{ rel: "self" }
+ }
+
+ expected_xml = ~s[<link rel="self" />]
+ assert XmlBuilder.to_xml(data) == expected_xml
+ end
+end