summaryrefslogtreecommitdiff
path: root/test/web/websub
diff options
context:
space:
mode:
Diffstat (limited to 'test/web/websub')
-rw-r--r--test/web/websub/websub_controller_test.exs30
-rw-r--r--test/web/websub/websub_test.exs44
2 files changed, 74 insertions, 0 deletions
diff --git a/test/web/websub/websub_controller_test.exs b/test/web/websub/websub_controller_test.exs
new file mode 100644
index 000000000..4eff598d6
--- /dev/null
+++ b/test/web/websub/websub_controller_test.exs
@@ -0,0 +1,30 @@
+defmodule Pleroma.Web.Websub.WebsubControllerTest do
+ use Pleroma.Web.ConnCase
+ import Pleroma.Factory
+ alias Pleroma.Repo
+ alias Pleroma.Web.Websub.WebsubServerSubscription
+
+ 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": "subscription",
+ "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"
+ subscription = Repo.one!(WebsubServerSubscription)
+ assert subscription.topic == Pleroma.Web.OStatus.feed_path(user)
+ assert subscription.state == "requested"
+ assert subscription.secret == "a random secret"
+ assert subscription.valid_until == NaiveDateTime.add(subscription.inserted_at, 100)
+ end
+end
diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs
new file mode 100644
index 000000000..93a44fe46
--- /dev/null
+++ b/test/web/websub/websub_test.exs
@@ -0,0 +1,44 @@
+defmodule Pleroma.Web.WebsubTest do
+ use Pleroma.DataCase
+ alias Pleroma.Web.Websub
+ 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 is_number(seconds)
+
+ {: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)
+ topic = sub.topic
+
+ getter = fn (_path, _headers, _options) ->
+ {:ok, %HTTPoison.Response{
+ status_code: 500,
+ body: ""
+ }}
+ end
+
+ {:error, sub} = Websub.verify(sub, getter)
+ assert sub.state == "rejected"
+ end
+end