From ec34de0c1fd58942c8ecefddef92696750b70420 Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Sun, 2 Dec 2018 16:58:38 +0300 Subject: WebSub fix test --- test/web/websub/websub_test.exs | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'test/web/websub') diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs index da7bc9112..0b8bfda2d 100644 --- a/test/web/websub/websub_test.exs +++ b/test/web/websub/websub_test.exs @@ -10,6 +10,18 @@ defmodule Pleroma.Web.WebsubTest do alias Pleroma.Web.Websub.{WebsubServerSubscription, WebsubClientSubscription} import Pleroma.Factory alias Pleroma.Web.Router.Helpers + import Tesla.Mock + + setup do + mock fn + %{method: :get, url: "https://mastodon.social/users/lambadalambda.atom"} -> + %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.atom")} + %{method: :post, url: "http://example.org/needs_refresh"} -> + %Tesla.Env{status: 200, body: ""} + end + + :ok + end test "a verification of a request that is accepted" do sub = insert(:websub_subscription) @@ -26,8 +38,8 @@ defmodule Pleroma.Web.WebsubTest do assert String.to_integer(seconds) > 0 {:ok, - %HTTPoison.Response{ - status_code: 200, + %Tesla.Env{ + status: 200, body: challenge }} end @@ -41,8 +53,8 @@ defmodule Pleroma.Web.WebsubTest do getter = fn _path, _headers, _options -> {:ok, - %HTTPoison.Response{ - status_code: 500, + %Tesla.Env{ + status: 500, body: "" }} end @@ -113,12 +125,7 @@ defmodule Pleroma.Web.WebsubTest do test "discovers the hub and canonical url" do topic = "https://mastodon.social/users/lambadalambda.atom" - getter = fn ^topic -> - doc = File.read!("test/fixtures/lambadalambda.atom") - {:ok, %{status_code: 200, body: doc}} - end - - {:ok, discovered} = Websub.gather_feed_data(topic, getter) + {:ok, discovered} = Websub.gather_feed_data(topic) expected = %{ "hub" => "https://mastodon.social/api/push", @@ -158,7 +165,7 @@ defmodule Pleroma.Web.WebsubTest do websub.id ) - {:ok, %{status_code: 202}} + {:ok, %{status: 202}} end task = Task.async(fn -> Websub.request_subscription(websub, poster) end) @@ -209,6 +216,7 @@ defmodule Pleroma.Web.WebsubTest do insert(:websub_client_subscription, %{ valid_until: NaiveDateTime.add(now, 2 * day), topic: "http://example.org/still_good", + hub: "http://example.org/still_good", state: "accepted" }) @@ -216,6 +224,7 @@ defmodule Pleroma.Web.WebsubTest do insert(:websub_client_subscription, %{ valid_until: NaiveDateTime.add(now, day - 100), topic: "http://example.org/needs_refresh", + hub: "http://example.org/needs_refresh", state: "accepted" }) -- cgit v1.2.3 From 87109482f336422186981c80eb3c3023637f09e8 Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Sun, 2 Dec 2018 17:08:36 +0300 Subject: status_code -> status --- test/web/websub/websub_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/web/websub') diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs index 0b8bfda2d..f3d2da81a 100644 --- a/test/web/websub/websub_test.exs +++ b/test/web/websub/websub_test.exs @@ -184,7 +184,7 @@ defmodule Pleroma.Web.WebsubTest do websub = insert(:websub_client_subscription, %{hub: hub, topic: topic}) poster = fn ^hub, {:form, _data}, _headers -> - {:ok, %{status_code: 202}} + {:ok, %{status: 202}} end {:error, websub} = Websub.request_subscription(websub, poster, 1000) @@ -193,7 +193,7 @@ defmodule Pleroma.Web.WebsubTest do websub = insert(:websub_client_subscription, %{hub: hub, topic: topic}) poster = fn ^hub, {:form, _data}, _headers -> - {:ok, %{status_code: 400}} + {:ok, %{status: 400}} end {:error, websub} = Websub.request_subscription(websub, poster, 1000) -- cgit v1.2.3 From c508d41c349c3034211f41281cfe60c70a020575 Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Sun, 2 Dec 2018 18:17:26 +0300 Subject: add http requests mock --- test/web/websub/websub_test.exs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'test/web/websub') diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs index f3d2da81a..47d1a88e1 100644 --- a/test/web/websub/websub_test.exs +++ b/test/web/websub/websub_test.exs @@ -13,13 +13,7 @@ defmodule Pleroma.Web.WebsubTest do import Tesla.Mock setup do - mock fn - %{method: :get, url: "https://mastodon.social/users/lambadalambda.atom"} -> - %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.atom")} - %{method: :post, url: "http://example.org/needs_refresh"} -> - %Tesla.Env{status: 200, body: ""} - end - + mock(fn env -> apply(HttpRequestMock, :request, [env]) end) :ok end -- cgit v1.2.3 From c81c74d84715b25447840cf8536ac4ba0a4e98f1 Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 10 Dec 2018 19:13:53 +0100 Subject: Treat warnings as errors outside of tests. --- test/web/websub/websub_test.exs | 6 ------ 1 file changed, 6 deletions(-) (limited to 'test/web/websub') diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs index 47d1a88e1..fd559743f 100644 --- a/test/web/websub/websub_test.exs +++ b/test/web/websub/websub_test.exs @@ -1,9 +1,3 @@ -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 -- cgit v1.2.3 From 3c08d229db423052d0dd88b8a36fb39b0ae81ead Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 23 Dec 2018 20:11:29 +0000 Subject: tests: add legal boilerplate --- test/web/websub/websub_controller_test.exs | 4 ++++ test/web/websub/websub_test.exs | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'test/web/websub') diff --git a/test/web/websub/websub_controller_test.exs b/test/web/websub/websub_controller_test.exs index d861c241f..9cbcda063 100644 --- a/test/web/websub/websub_controller_test.exs +++ b/test/web/websub/websub_controller_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.Websub.WebsubControllerTest do use Pleroma.Web.ConnCase import Pleroma.Factory diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs index fd559743f..9751d161d 100644 --- a/test/web/websub/websub_test.exs +++ b/test/web/websub/websub_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.WebsubTest do use Pleroma.DataCase alias Pleroma.Web.Websub -- cgit v1.2.3 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') 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') 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') 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 From 8bb7e19b3814e261e66c2d3592d146f72d4ce623 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sun, 10 Feb 2019 22:57:38 +0100 Subject: test: de-group alias/es --- test/web/websub/websub_controller_test.exs | 3 ++- test/web/websub/websub_test.exs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'test/web/websub') diff --git a/test/web/websub/websub_controller_test.exs b/test/web/websub/websub_controller_test.exs index 6492df2a0..04fb4a5a3 100644 --- a/test/web/websub/websub_controller_test.exs +++ b/test/web/websub/websub_controller_test.exs @@ -6,7 +6,8 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do use Pleroma.Web.ConnCase import Pleroma.Factory alias Pleroma.Web.Websub.WebsubClientSubscription - alias Pleroma.{Repo, Activity} + alias Pleroma.Activity + alias Pleroma.Repo alias Pleroma.Web.Websub test "websub subscription request", %{conn: conn} do diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs index 9751d161d..9a9b9df02 100644 --- a/test/web/websub/websub_test.exs +++ b/test/web/websub/websub_test.exs @@ -5,7 +5,8 @@ defmodule Pleroma.Web.WebsubTest do use Pleroma.DataCase alias Pleroma.Web.Websub - alias Pleroma.Web.Websub.{WebsubServerSubscription, WebsubClientSubscription} + alias Pleroma.Web.Websub.WebsubServerSubscription + alias Pleroma.Web.Websub.WebsubClientSubscription import Pleroma.Factory alias Pleroma.Web.Router.Helpers import Tesla.Mock -- cgit v1.2.3 From 74579115a73d697aed67abe2dc8ea1a664c89c5b Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 11 Feb 2019 00:08:48 +0100 Subject: =?UTF-8?q?test:=20Change=20`lenght(=E2=80=A6)=20=3D=3D=200`=20to?= =?UTF-8?q?=20`Enum.empty=3F(=E2=80=A6)`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/web/websub/websub_controller_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/web/websub') diff --git a/test/web/websub/websub_controller_test.exs b/test/web/websub/websub_controller_test.exs index 04fb4a5a3..87b01d89b 100644 --- a/test/web/websub/websub_controller_test.exs +++ b/test/web/websub/websub_controller_test.exs @@ -81,7 +81,7 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do assert response(conn, 500) == "Error" - assert length(Repo.all(Activity)) == 0 + assert Enum.empty?(Repo.all(Activity)) end end end -- cgit v1.2.3 From a3a9cec4835738216800d2cebd295fb8dbf10f34 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 5 Mar 2019 03:52:23 +0100 Subject: [Credo] fix Credo.Check.Readability.AliasOrder --- test/web/websub/websub_controller_test.exs | 2 +- test/web/websub/websub_test.exs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'test/web/websub') diff --git a/test/web/websub/websub_controller_test.exs b/test/web/websub/websub_controller_test.exs index 87b01d89b..1e69ed01a 100644 --- a/test/web/websub/websub_controller_test.exs +++ b/test/web/websub/websub_controller_test.exs @@ -5,10 +5,10 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do use Pleroma.Web.ConnCase import Pleroma.Factory - alias Pleroma.Web.Websub.WebsubClientSubscription alias Pleroma.Activity alias Pleroma.Repo alias Pleroma.Web.Websub + alias Pleroma.Web.Websub.WebsubClientSubscription test "websub subscription request", %{conn: conn} do user = insert(:user) diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs index 9a9b9df02..74386d7db 100644 --- a/test/web/websub/websub_test.exs +++ b/test/web/websub/websub_test.exs @@ -4,11 +4,13 @@ defmodule Pleroma.Web.WebsubTest do use Pleroma.DataCase + + alias Pleroma.Web.Router.Helpers alias Pleroma.Web.Websub - alias Pleroma.Web.Websub.WebsubServerSubscription alias Pleroma.Web.Websub.WebsubClientSubscription + alias Pleroma.Web.Websub.WebsubServerSubscription + import Pleroma.Factory - alias Pleroma.Web.Router.Helpers import Tesla.Mock setup do -- cgit v1.2.3