36ea822990959574ddbbbad54d2a7628e45cdcca
[akkoma] / test / web / websub / websub_test.exs
1 defmodule Pleroma.Web.WebsubTest do
2 use Pleroma.DataCase
3 alias Pleroma.Web.Websub
4 import Pleroma.Factory
5
6 test "a verification of a request that is accepted" do
7 sub = insert(:websub_subscription)
8 topic = sub.topic
9
10 getter = fn (_path, _headers, options) ->
11 %{
12 "hub.challenge": challenge,
13 "hub.lease_seconds": seconds,
14 "hub.topic": ^topic,
15 "hub.mode": "subscribe"
16 } = Keyword.get(options, :params)
17
18 assert String.to_integer(seconds) > 0
19
20 {:ok, %HTTPoison.Response{
21 status_code: 200,
22 body: challenge
23 }}
24 end
25
26 {:ok, sub} = Websub.verify(sub, getter)
27 assert sub.state == "active"
28 end
29
30 test "a verification of a request that doesn't return 200" do
31 sub = insert(:websub_subscription)
32 topic = sub.topic
33
34 getter = fn (_path, _headers, _options) ->
35 {:ok, %HTTPoison.Response{
36 status_code: 500,
37 body: ""
38 }}
39 end
40
41 {:error, sub} = Websub.verify(sub, getter)
42 assert sub.state == "rejected"
43 end
44 end