From d99650270b980c006690a7051a2d5cffe07779f1 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Fri, 25 Jan 2019 20:38:54 +0300 Subject: [#534] Federation reachability filtering tests. --- test/web/websub/websub_controller_test.exs | 84 +++++++++++++++++++----------- 1 file changed, 53 insertions(+), 31 deletions(-) (limited to 'test/web/websub/websub_controller_test.exs') diff --git a/test/web/websub/websub_controller_test.exs b/test/web/websub/websub_controller_test.exs index 9cbcda063..c445ed676 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} + alias Pleroma.{Repo, Activity, Instances} alias Pleroma.Web.Websub test "websub subscription request", %{conn: conn} do @@ -50,35 +50,57 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do assert_in_delta NaiveDateTime.diff(websub.valid_until, NaiveDateTime.utc_now()), 100, 5 end - test "handles incoming feed updates", %{conn: conn} do - 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") - |> post("/push/subscriptions/#{websub.id}", doc) - - assert response(conn, 200) == "OK" - - assert length(Repo.all(Activity)) == 1 - end - - test "rejects incoming feed updates with the wrong signature", %{conn: conn} do - websub = insert(:websub_client_subscription) - doc = "some stuff" - signature = Websub.sign("wrong secret", doc) - - conn = - conn - |> put_req_header("x-hub-signature", "sha1=" <> signature) - |> put_req_header("content-type", "application/atom+xml") - |> post("/push/subscriptions/#{websub.id}", doc) - - assert response(conn, 500) == "Error" - - assert length(Repo.all(Activity)) == 0 + describe "websub_incoming" do + test "handles incoming feed updates", %{conn: conn} do + 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") + |> post("/push/subscriptions/#{websub.id}", doc) + + assert response(conn, 200) == "OK" + + assert length(Repo.all(Activity)) == 1 + end + + test "rejects incoming feed updates with the wrong signature", %{conn: conn} do + websub = insert(:websub_client_subscription) + doc = "some stuff" + signature = Websub.sign("wrong secret", doc) + + conn = + conn + |> put_req_header("x-hub-signature", "sha1=" <> signature) + |> put_req_header("content-type", "application/atom+xml") + |> post("/push/subscriptions/#{websub.id}", doc) + + assert response(conn, 500) == "Error" + + 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_unreachable(sender_url, Instances.reachability_datetime_threshold()) + 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 -- cgit v1.2.3 From 1d2f41642cfec5710055bcf8409778bb362beecb Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Mon, 28 Jan 2019 15:25:06 +0300 Subject: [#534] Various tweaks. Tests for Instances and Instance. --- test/web/websub/websub_controller_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/web/websub/websub_controller_test.exs') diff --git a/test/web/websub/websub_controller_test.exs b/test/web/websub/websub_controller_test.exs index c445ed676..cb19d6fe6 100644 --- a/test/web/websub/websub_controller_test.exs +++ b/test/web/websub/websub_controller_test.exs @@ -85,7 +85,7 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do test "it clears `unreachable` federation status of the sender", %{conn: conn} do sender_url = "https://pleroma.soykaf.com" - Instances.set_unreachable(sender_url, Instances.reachability_datetime_threshold()) + Instances.set_consistently_unreachable(sender_url) refute Instances.reachable?(sender_url) websub = insert(:websub_client_subscription) -- cgit v1.2.3 From 92753b0cd9cfcdc5edb64a5e55ad27f73079f9e0 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Tue, 29 Jan 2019 13:12:28 +0300 Subject: [#534] Made federation push sender be determined basing on content instead of `referer` header. Updated tests. --- test/web/websub/websub_controller_test.exs | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) (limited to 'test/web/websub/websub_controller_test.exs') 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 -- cgit v1.2.3