aboutsummaryrefslogtreecommitdiff
path: root/test/web
diff options
context:
space:
mode:
authorIvan Tashkinov <ivantashkinov@gmail.com>2019-01-29 13:12:28 +0300
committerIvan Tashkinov <ivantashkinov@gmail.com>2019-01-29 13:12:28 +0300
commit92753b0cd9cfcdc5edb64a5e55ad27f73079f9e0 (patch)
tree606de2d652366d27ce34faebf3ad4274facfd15d /test/web
parentd3f9e6f6fed382ede8e314c370c21e84a119f65a (diff)
downloadpleroma-92753b0cd9cfcdc5edb64a5e55ad27f73079f9e0.tar.gz
[#534] Made federation push sender be determined basing on content instead of `referer` header. Updated tests.
Diffstat (limited to 'test/web')
-rw-r--r--test/web/activity_pub/activity_pub_controller_test.exs16
-rw-r--r--test/web/instances/instances_test.exs18
-rw-r--r--test/web/ostatus/incoming_documents/delete_handling_test.exs7
-rw-r--r--test/web/ostatus/ostatus_controller_test.exs20
-rw-r--r--test/web/ostatus/ostatus_test.exs18
-rw-r--r--test/web/websub/websub_controller_test.exs22
6 files changed, 51 insertions, 50 deletions
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index eca5c134d..d3dd160dd 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -145,17 +145,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
end
test "it clears `unreachable` federation status of the sender", %{conn: conn} do
- sender_url = "https://pleroma.soykaf.com"
+ data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
+
+ sender_url = data["actor"]
Instances.set_consistently_unreachable(sender_url)
refute Instances.reachable?(sender_url)
- data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
-
conn =
conn
|> assign(:valid_signature, true)
|> put_req_header("content-type", "application/activity+json")
- |> put_req_header("referer", sender_url)
|> post("/inbox", data)
assert "ok" == json_response(conn, 200)
@@ -210,10 +209,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
end
test "it clears `unreachable` federation status of the sender", %{conn: conn} do
- sender_host = "pleroma.soykaf.com"
- Instances.set_consistently_unreachable(sender_host)
- refute Instances.reachable?(sender_host)
-
user = insert(:user)
data =
@@ -221,11 +216,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|> Poison.decode!()
|> Map.put("bcc", [user.ap_id])
+ sender_host = URI.parse(data["actor"]).host
+ Instances.set_consistently_unreachable(sender_host)
+ refute Instances.reachable?(sender_host)
+
conn =
conn
|> assign(:valid_signature, true)
|> put_req_header("content-type", "application/activity+json")
- |> put_req_header("referer", "https://#{sender_host}")
|> post("/users/#{user.nickname}/inbox", data)
assert "ok" == json_response(conn, 200)
diff --git a/test/web/instances/instances_test.exs b/test/web/instances/instances_test.exs
index a2fdf1019..adb8560a7 100644
--- a/test/web/instances/instances_test.exs
+++ b/test/web/instances/instances_test.exs
@@ -39,6 +39,11 @@ defmodule Pleroma.InstancesTest do
assert Instances.reachable?(url)
assert Instances.reachable?(URI.parse(url).host)
end
+
+ test "returns true on non-binary input" do
+ assert Instances.reachable?(nil)
+ assert Instances.reachable?(1)
+ end
end
describe "filter_reachable/1" do
@@ -71,6 +76,19 @@ defmodule Pleroma.InstancesTest do
Instances.set_reachable(url)
assert Instances.reachable?(url)
end
+
+ test "returns error status on non-binary input" do
+ assert {:error, _} = Instances.set_reachable(nil)
+ assert {:error, _} = Instances.set_reachable(1)
+ end
+ end
+
+ # Note: implementation-specific (e.g. Instance) details of set_unreachable/1 should be tested in implementation-specific tests
+ describe "set_unreachable/1" do
+ test "returns error status on non-binary input" do
+ assert {:error, _} = Instances.set_unreachable(nil)
+ assert {:error, _} = Instances.set_unreachable(1)
+ end
end
describe "set_consistently_unreachable/1" do
diff --git a/test/web/ostatus/incoming_documents/delete_handling_test.exs b/test/web/ostatus/incoming_documents/delete_handling_test.exs
index c8fbff6cc..d97cd79f4 100644
--- a/test/web/ostatus/incoming_documents/delete_handling_test.exs
+++ b/test/web/ostatus/incoming_documents/delete_handling_test.exs
@@ -2,9 +2,16 @@ defmodule Pleroma.Web.OStatus.DeleteHandlingTest do
use Pleroma.DataCase
import Pleroma.Factory
+ import Tesla.Mock
+
alias Pleroma.{Repo, Activity, Object}
alias Pleroma.Web.OStatus
+ setup do
+ mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
+
describe "deletions" do
test "it removes the mentioned activity" do
note = insert(:note_activity)
diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs
index cba12b3f7..3145ca9a1 100644
--- a/test/web/ostatus/ostatus_controller_test.exs
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -5,7 +5,7 @@
defmodule Pleroma.Web.OStatus.OStatusControllerTest do
use Pleroma.Web.ConnCase
import Pleroma.Factory
- alias Pleroma.{User, Repo, Object, Instances}
+ alias Pleroma.{User, Repo, Object}
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.OStatus.ActivityRepresenter
@@ -59,24 +59,6 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
assert response(conn, 200)
end
-
- test "it clears `unreachable` federation status of the sender", %{conn: conn} do
- sender_url = "https://pleroma.soykaf.com"
- Instances.set_consistently_unreachable(sender_url)
- refute Instances.reachable?(sender_url)
-
- user = insert(:user)
- salmon = File.read!("test/fixtures/salmon.xml")
-
- conn =
- conn
- |> put_req_header("content-type", "application/atom+xml")
- |> put_req_header("referer", sender_url)
- |> post("/users/#{user.nickname}/salmon", salmon)
-
- assert response(conn, 200)
- assert Instances.reachable?(sender_url)
- end
end
test "gets a feed", %{conn: conn} do
diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs
index 403cc7095..0c63dd84d 100644
--- a/test/web/ostatus/ostatus_test.exs
+++ b/test/web/ostatus/ostatus_test.exs
@@ -6,7 +6,7 @@ defmodule Pleroma.Web.OStatusTest do
use Pleroma.DataCase
alias Pleroma.Web.OStatus
alias Pleroma.Web.XML
- alias Pleroma.{Object, Repo, User, Activity}
+ alias Pleroma.{Object, Repo, User, Activity, Instances}
import Pleroma.Factory
import ExUnit.CaptureLog
@@ -311,6 +311,22 @@ defmodule Pleroma.Web.OStatusTest do
refute User.following?(follower, followed)
end
+ test "it clears `unreachable` federation status of the sender" do
+ incoming_reaction_xml = File.read!("test/fixtures/share-gs.xml")
+ doc = XML.parse_document(incoming_reaction_xml)
+ actor_uri = XML.string_from_xpath("//author/uri[1]", doc)
+ reacted_to_author_uri = XML.string_from_xpath("//author/uri[2]", doc)
+
+ Instances.set_consistently_unreachable(actor_uri)
+ Instances.set_consistently_unreachable(reacted_to_author_uri)
+ refute Instances.reachable?(actor_uri)
+ refute Instances.reachable?(reacted_to_author_uri)
+
+ {:ok, _} = OStatus.handle_incoming(incoming_reaction_xml)
+ assert Instances.reachable?(actor_uri)
+ refute Instances.reachable?(reacted_to_author_uri)
+ end
+
describe "new remote user creation" do
test "returns local users" do
local_user = insert(:user)
diff --git a/test/web/websub/websub_controller_test.exs b/test/web/websub/websub_controller_test.exs
index cb19d6fe6..6492df2a0 100644
--- a/test/web/websub/websub_controller_test.exs
+++ b/test/web/websub/websub_controller_test.exs
@@ -6,7 +6,7 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do
use Pleroma.Web.ConnCase
import Pleroma.Factory
alias Pleroma.Web.Websub.WebsubClientSubscription
- alias Pleroma.{Repo, Activity, Instances}
+ alias Pleroma.{Repo, Activity}
alias Pleroma.Web.Websub
test "websub subscription request", %{conn: conn} do
@@ -82,25 +82,5 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do
assert length(Repo.all(Activity)) == 0
end
-
- test "it clears `unreachable` federation status of the sender", %{conn: conn} do
- sender_url = "https://pleroma.soykaf.com"
- Instances.set_consistently_unreachable(sender_url)
- refute Instances.reachable?(sender_url)
-
- websub = insert(:websub_client_subscription)
- doc = "some stuff"
- signature = Websub.sign(websub.secret, doc)
-
- conn =
- conn
- |> put_req_header("x-hub-signature", "sha1=" <> signature)
- |> put_req_header("content-type", "application/atom+xml")
- |> put_req_header("referer", sender_url)
- |> post("/push/subscriptions/#{websub.id}", doc)
-
- assert response(conn, 200) == "OK"
- assert Instances.reachable?(sender_url)
- end
end
end