projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix nodeinfo handling
[akkoma]
/
test
/
web
/
websub
/
websub_test.exs
diff --git
a/test/web/websub/websub_test.exs
b/test/web/websub/websub_test.exs
index da7bc9112ec8131bf18c1911f2832da4faeca1a6..46ca545de7be258db102542fae6d2def3d2ce63e 100644
(file)
--- a/
test/web/websub/websub_test.exs
+++ b/
test/web/websub/websub_test.exs
@@
-1,15
+1,25
@@
-defmodule Pleroma.Web.WebsubMock do
- def verify(sub) do
- {:ok, sub}
- end
-end
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.WebsubTest do
use Pleroma.DataCase
defmodule Pleroma.Web.WebsubTest do
use Pleroma.DataCase
+ use Oban.Testing, repo: Pleroma.Repo
+
+ alias Pleroma.Tests.ObanHelpers
+ alias Pleroma.Web.Router.Helpers
alias Pleroma.Web.Websub
alias Pleroma.Web.Websub
- alias Pleroma.Web.Websub.{WebsubServerSubscription, WebsubClientSubscription}
+ alias Pleroma.Web.Websub.WebsubClientSubscription
+ alias Pleroma.Web.Websub.WebsubServerSubscription
+ alias Pleroma.Workers.SubscriberWorker
+
import Pleroma.Factory
import Pleroma.Factory
- alias Pleroma.Web.Router.Helpers
+ import Tesla.Mock
+
+ setup do
+ mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
test "a verification of a request that is accepted" do
sub = insert(:websub_subscription)
test "a verification of a request that is accepted" do
sub = insert(:websub_subscription)
@@
-26,8
+36,8
@@
defmodule Pleroma.Web.WebsubTest do
assert String.to_integer(seconds) > 0
{:ok,
assert String.to_integer(seconds) > 0
{:ok,
- %
HTTPoison.Response
{
- status
_code
: 200,
+ %
Tesla.Env
{
+ status: 200,
body: challenge
}}
end
body: challenge
}}
end
@@
-41,8
+51,8
@@
defmodule Pleroma.Web.WebsubTest do
getter = fn _path, _headers, _options ->
{:ok,
getter = fn _path, _headers, _options ->
{:ok,
- %
HTTPoison.Response
{
- status
_code
: 500,
+ %
Tesla.Env
{
+ status: 500,
body: ""
}}
end
body: ""
}}
end
@@
-113,12
+123,7
@@
defmodule Pleroma.Web.WebsubTest do
test "discovers the hub and canonical url" do
topic = "https://mastodon.social/users/lambadalambda.atom"
test "discovers the hub and canonical url" do
topic = "https://mastodon.social/users/lambadalambda.atom"
- getter = fn ^topic ->
- doc = File.read!("test/fixtures/lambadalambda.atom")
- {:ok, %{status_code: 200, body: doc}}
- end
-
- {:ok, discovered} = Websub.gather_feed_data(topic, getter)
+ {:ok, discovered} = Websub.gather_feed_data(topic)
expected = %{
"hub" => "https://mastodon.social/api/push",
expected = %{
"hub" => "https://mastodon.social/api/push",
@@
-158,7
+163,7
@@
defmodule Pleroma.Web.WebsubTest do
websub.id
)
websub.id
)
- {:ok, %{status
_code
: 202}}
+ {:ok, %{status: 202}}
end
task = Task.async(fn -> Websub.request_subscription(websub, poster) end)
end
task = Task.async(fn -> Websub.request_subscription(websub, poster) end)
@@
-177,7
+182,7
@@
defmodule Pleroma.Web.WebsubTest do
websub = insert(:websub_client_subscription, %{hub: hub, topic: topic})
poster = fn ^hub, {:form, _data}, _headers ->
websub = insert(:websub_client_subscription, %{hub: hub, topic: topic})
poster = fn ^hub, {:form, _data}, _headers ->
- {:ok, %{status
_code
: 202}}
+ {:ok, %{status: 202}}
end
{:error, websub} = Websub.request_subscription(websub, poster, 1000)
end
{:error, websub} = Websub.request_subscription(websub, poster, 1000)
@@
-186,7
+191,7
@@
defmodule Pleroma.Web.WebsubTest do
websub = insert(:websub_client_subscription, %{hub: hub, topic: topic})
poster = fn ^hub, {:form, _data}, _headers ->
websub = insert(:websub_client_subscription, %{hub: hub, topic: topic})
poster = fn ^hub, {:form, _data}, _headers ->
- {:ok, %{status
_code
: 400}}
+ {:ok, %{status: 400}}
end
{:error, websub} = Websub.request_subscription(websub, poster, 1000)
end
{:error, websub} = Websub.request_subscription(websub, poster, 1000)
@@
-209,6
+214,7
@@
defmodule Pleroma.Web.WebsubTest do
insert(:websub_client_subscription, %{
valid_until: NaiveDateTime.add(now, 2 * day),
topic: "http://example.org/still_good",
insert(:websub_client_subscription, %{
valid_until: NaiveDateTime.add(now, 2 * day),
topic: "http://example.org/still_good",
+ hub: "http://example.org/still_good",
state: "accepted"
})
state: "accepted"
})
@@
-216,10
+222,12
@@
defmodule Pleroma.Web.WebsubTest do
insert(:websub_client_subscription, %{
valid_until: NaiveDateTime.add(now, day - 100),
topic: "http://example.org/needs_refresh",
insert(:websub_client_subscription, %{
valid_until: NaiveDateTime.add(now, day - 100),
topic: "http://example.org/needs_refresh",
+ hub: "http://example.org/needs_refresh",
state: "accepted"
})
_refresh = Websub.refresh_subscriptions()
state: "accepted"
})
_refresh = Websub.refresh_subscriptions()
+ ObanHelpers.perform(all_enqueued(worker: SubscriberWorker))
assert still_good == Repo.get(WebsubClientSubscription, still_good.id)
refute needs_refresh == Repo.get(WebsubClientSubscription, needs_refresh.id)
assert still_good == Repo.get(WebsubClientSubscription, still_good.id)
refute needs_refresh == Repo.get(WebsubClientSubscription, needs_refresh.id)