1 defmodule Pleroma.Web.Websub.WebsubControllerTest do
2 use Pleroma.Web.ConnCase
4 alias Pleroma.Web.Websub.WebsubClientSubscription
5 alias Pleroma.{Repo, Activity}
6 alias Pleroma.Web.Websub
8 test "websub subscription request", %{conn: conn} do
11 path = Pleroma.Web.OStatus.pubsub_path(user)
14 "hub.callback": "http://example.org/sub",
15 "hub.mode": "subscribe",
16 "hub.topic": Pleroma.Web.OStatus.feed_path(user),
17 "hub.secret": "a random secret",
18 "hub.lease_seconds": "100"
24 assert response(conn, 202) == "Accepted"
27 test "websub subscription confirmation", %{conn: conn} do
28 websub = insert(:websub_client_subscription)
31 "hub.mode" => "subscribe",
32 "hub.topic" => websub.topic,
33 "hub.challenge" => "some challenge",
34 "hub.lease_seconds" => 100
38 |> get("/push/subscriptions/#{websub.id}", params)
40 websub = Repo.get(WebsubClientSubscription, websub.id)
42 assert response(conn, 200) == "some challenge"
43 assert websub.state == "accepted"
48 test "handles incoming feed updates", %{conn: conn} do
49 websub = insert(:websub_client_subscription)
51 signature = Websub.sign(websub.secret, doc)
54 |> put_req_header("x-hub-signature", "sha1=" <> signature)
55 |> put_req_header("content-type", "application/atom+xml")
56 |> post("/push/subscriptions/#{websub.id}", doc)
58 assert response(conn, 200) == "OK"
60 assert length(Repo.all(Activity)) == 1
63 test "rejects incoming feed updates with the wrong signature", %{conn: conn} do
64 websub = insert(:websub_client_subscription)
66 signature = Websub.sign("wrong secret", doc)
69 |> put_req_header("x-hub-signature", "sha1=" <> signature)
70 |> put_req_header("content-type", "application/atom+xml")
71 |> post("/push/subscriptions/#{websub.id}", doc)
73 assert response(conn, 500) == "Error"
75 assert length(Repo.all(Activity)) == 0
79 defmodule Pleroma.Web.OStatusMock do
80 import Pleroma.Factory
81 def handle_incoming(_doc) do
82 insert(:note_activity)