forked from AkkomaGang/akkoma
WebSub fix test
This commit is contained in:
parent
3ce16e5a56
commit
ec34de0c1f
3 changed files with 22 additions and 13 deletions
|
@ -25,7 +25,6 @@
|
||||||
|
|
||||||
config :pleroma, :websub, Pleroma.Web.WebsubMock
|
config :pleroma, :websub, Pleroma.Web.WebsubMock
|
||||||
config :pleroma, :ostatus, Pleroma.Web.OStatusMock
|
config :pleroma, :ostatus, Pleroma.Web.OStatusMock
|
||||||
config :pleroma, :httpoison, HTTPoisonMock
|
|
||||||
config :tesla, adapter: Tesla.Mock
|
config :tesla, adapter: Tesla.Mock
|
||||||
|
|
||||||
try do
|
try do
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
defmodule Pleroma.HTTP.Connection do
|
defmodule Pleroma.HTTP.Connection do
|
||||||
@hackney_options [pool: :default]
|
@hackney_options [pool: :default]
|
||||||
|
@adapter Application.get_env(:tesla, :adapter)
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Configure a client connection
|
Configure a client connection
|
||||||
|
@ -10,7 +11,7 @@ defmodule Pleroma.HTTP.Connection do
|
||||||
"""
|
"""
|
||||||
@spec new(Keyword.t()) :: Tesla.Env.client()
|
@spec new(Keyword.t()) :: Tesla.Env.client()
|
||||||
def new(opts \\ []) do
|
def new(opts \\ []) do
|
||||||
Tesla.client([], {Tesla.Adapter.Hackney, hackney_options(opts)})
|
Tesla.client([], {@adapter, hackney_options(opts)})
|
||||||
end
|
end
|
||||||
|
|
||||||
# fetch Hackney options
|
# fetch Hackney options
|
||||||
|
|
|
@ -10,6 +10,18 @@ defmodule Pleroma.Web.WebsubTest do
|
||||||
alias Pleroma.Web.Websub.{WebsubServerSubscription, WebsubClientSubscription}
|
alias Pleroma.Web.Websub.{WebsubServerSubscription, WebsubClientSubscription}
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
alias Pleroma.Web.Router.Helpers
|
alias Pleroma.Web.Router.Helpers
|
||||||
|
import Tesla.Mock
|
||||||
|
|
||||||
|
setup do
|
||||||
|
mock fn
|
||||||
|
%{method: :get, url: "https://mastodon.social/users/lambadalambda.atom"} ->
|
||||||
|
%Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.atom")}
|
||||||
|
%{method: :post, url: "http://example.org/needs_refresh"} ->
|
||||||
|
%Tesla.Env{status: 200, body: ""}
|
||||||
|
end
|
||||||
|
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
test "a verification of a request that is accepted" do
|
test "a verification of a request that is accepted" do
|
||||||
sub = insert(:websub_subscription)
|
sub = insert(:websub_subscription)
|
||||||
|
@ -26,8 +38,8 @@ test "a verification of a request that is accepted" do
|
||||||
assert String.to_integer(seconds) > 0
|
assert String.to_integer(seconds) > 0
|
||||||
|
|
||||||
{:ok,
|
{:ok,
|
||||||
%HTTPoison.Response{
|
%Tesla.Env{
|
||||||
status_code: 200,
|
status: 200,
|
||||||
body: challenge
|
body: challenge
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
@ -41,8 +53,8 @@ test "a verification of a request that doesn't return 200" do
|
||||||
|
|
||||||
getter = fn _path, _headers, _options ->
|
getter = fn _path, _headers, _options ->
|
||||||
{:ok,
|
{:ok,
|
||||||
%HTTPoison.Response{
|
%Tesla.Env{
|
||||||
status_code: 500,
|
status: 500,
|
||||||
body: ""
|
body: ""
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
@ -113,12 +125,7 @@ test "initiate a subscription for a given user and topic" do
|
||||||
test "discovers the hub and canonical url" do
|
test "discovers the hub and canonical url" do
|
||||||
topic = "https://mastodon.social/users/lambadalambda.atom"
|
topic = "https://mastodon.social/users/lambadalambda.atom"
|
||||||
|
|
||||||
getter = fn ^topic ->
|
{:ok, discovered} = Websub.gather_feed_data(topic)
|
||||||
doc = File.read!("test/fixtures/lambadalambda.atom")
|
|
||||||
{:ok, %{status_code: 200, body: doc}}
|
|
||||||
end
|
|
||||||
|
|
||||||
{:ok, discovered} = Websub.gather_feed_data(topic, getter)
|
|
||||||
|
|
||||||
expected = %{
|
expected = %{
|
||||||
"hub" => "https://mastodon.social/api/push",
|
"hub" => "https://mastodon.social/api/push",
|
||||||
|
@ -158,7 +165,7 @@ test "calls the hub, requests topic" do
|
||||||
websub.id
|
websub.id
|
||||||
)
|
)
|
||||||
|
|
||||||
{:ok, %{status_code: 202}}
|
{:ok, %{status: 202}}
|
||||||
end
|
end
|
||||||
|
|
||||||
task = Task.async(fn -> Websub.request_subscription(websub, poster) end)
|
task = Task.async(fn -> Websub.request_subscription(websub, poster) end)
|
||||||
|
@ -209,6 +216,7 @@ test "it renews subscriptions that have less than a day of time left" do
|
||||||
insert(:websub_client_subscription, %{
|
insert(:websub_client_subscription, %{
|
||||||
valid_until: NaiveDateTime.add(now, 2 * day),
|
valid_until: NaiveDateTime.add(now, 2 * day),
|
||||||
topic: "http://example.org/still_good",
|
topic: "http://example.org/still_good",
|
||||||
|
hub: "http://example.org/still_good",
|
||||||
state: "accepted"
|
state: "accepted"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -216,6 +224,7 @@ test "it renews subscriptions that have less than a day of time left" do
|
||||||
insert(:websub_client_subscription, %{
|
insert(:websub_client_subscription, %{
|
||||||
valid_until: NaiveDateTime.add(now, day - 100),
|
valid_until: NaiveDateTime.add(now, day - 100),
|
||||||
topic: "http://example.org/needs_refresh",
|
topic: "http://example.org/needs_refresh",
|
||||||
|
hub: "http://example.org/needs_refresh",
|
||||||
state: "accepted"
|
state: "accepted"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue