1 defmodule Pleroma.Web.WebsubMock do
6 defmodule Pleroma.Web.WebsubTest do
8 alias Pleroma.Web.Websub
9 alias Pleroma.Web.Websub.WebsubServerSubscription
10 import Pleroma.Factory
12 test "a verification of a request that is accepted" do
13 sub = insert(:websub_subscription)
16 getter = fn (_path, _headers, options) ->
18 "hub.challenge": challenge,
19 "hub.lease_seconds": seconds,
21 "hub.mode": "subscribe"
22 } = Keyword.get(options, :params)
24 assert String.to_integer(seconds) > 0
26 {:ok, %HTTPoison.Response{
32 {:ok, sub} = Websub.verify(sub, getter)
33 assert sub.state == "active"
36 test "a verification of a request that doesn't return 200" do
37 sub = insert(:websub_subscription)
39 getter = fn (_path, _headers, _options) ->
40 {:ok, %HTTPoison.Response{
46 {:error, sub} = Websub.verify(sub, getter)
47 assert sub.state == "rejected"
50 test "an incoming subscription request" do
54 "hub.callback" => "http://example.org/sub",
55 "hub.mode" => "subscription",
56 "hub.topic" => Pleroma.Web.OStatus.feed_path(user),
57 "hub.secret" => "a random secret",
58 "hub.lease_seconds" => "100"
62 {:ok, subscription } = Websub.incoming_subscription_request(user, data)
63 assert subscription.topic == Pleroma.Web.OStatus.feed_path(user)
64 assert subscription.state == "requested"
65 assert subscription.secret == "a random secret"
66 assert subscription.callback == "http://example.org/sub"
69 test "an incoming subscription request for an existing subscription" do
71 sub = insert(:websub_subscription, state: "accepted", topic: Pleroma.Web.OStatus.feed_path(user))
74 "hub.callback" => sub.callback,
75 "hub.mode" => "subscription",
76 "hub.topic" => Pleroma.Web.OStatus.feed_path(user),
77 "hub.secret" => "a random secret",
78 "hub.lease_seconds" => "100"
82 {:ok, subscription } = Websub.incoming_subscription_request(user, data)
83 assert subscription.topic == Pleroma.Web.OStatus.feed_path(user)
84 assert subscription.state == sub.state
85 assert subscription.secret == "a random secret"
86 assert subscription.callback == sub.callback
87 assert length(Repo.all(WebsubServerSubscription)) == 1
88 assert subscription.id == sub.id