diff options
author | Roger Braun <roger@rogerbraun.net> | 2017-04-21 03:59:11 +0200 |
---|---|---|
committer | Roger Braun <roger@rogerbraun.net> | 2017-04-21 03:59:11 +0200 |
commit | 424e0e77792361d8f43a085c7cd3b2e9d566a22d (patch) | |
tree | c007aa0d4f44b7d1aee3d3afd5ab2fe20f983959 /test | |
parent | 1b9cc721a0d49d786b4864c2b8aceaf49b9ff088 (diff) | |
download | pleroma-424e0e77792361d8f43a085c7cd3b2e9d566a22d.tar.gz |
Add Websub verification.
Diffstat (limited to 'test')
-rw-r--r-- | test/support/factory.ex | 10 | ||||
-rw-r--r-- | test/web/websub/websub_test.exs | 44 |
2 files changed, 54 insertions, 0 deletions
diff --git a/test/support/factory.ex b/test/support/factory.ex index 3fc9cf710..401fdfda3 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -64,4 +64,14 @@ defmodule Pleroma.Factory do data: data } end + + def websub_subscription_factory do + %Pleroma.Web.Websub.WebsubServerSubscription{ + topic: "http://example.org", + callback: "http://example/org/callback", + secret: "here's a secret", + valid_until: NaiveDateTime.add(NaiveDateTime.utc_now, 100), + state: "requested" + } + 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 |