Only have one subscription per callback.
This commit is contained in:
parent
1feb193731
commit
8fb73c28bb
6 changed files with 107 additions and 48 deletions
|
|
@ -1,6 +1,12 @@
|
|||
defmodule Pleroma.Web.WebsubMock do
|
||||
def verify(sub) do
|
||||
{:ok, sub}
|
||||
end
|
||||
end
|
||||
defmodule Pleroma.Web.WebsubTest do
|
||||
use Pleroma.DataCase
|
||||
alias Pleroma.Web.Websub
|
||||
alias Pleroma.Web.Websub.WebsubServerSubscription
|
||||
import Pleroma.Factory
|
||||
|
||||
test "a verification of a request that is accepted" do
|
||||
|
|
@ -29,7 +35,6 @@ defmodule Pleroma.Web.WebsubTest do
|
|||
|
||||
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{
|
||||
|
|
@ -41,4 +46,45 @@ defmodule Pleroma.Web.WebsubTest do
|
|||
{:error, sub} = Websub.verify(sub, getter)
|
||||
assert sub.state == "rejected"
|
||||
end
|
||||
|
||||
test "an incoming subscription request" do
|
||||
user = insert(:user)
|
||||
|
||||
data = %{
|
||||
"hub.callback" => "http://example.org/sub",
|
||||
"hub.mode" => "subscription",
|
||||
"hub.topic" => Pleroma.Web.OStatus.feed_path(user),
|
||||
"hub.secret" => "a random secret",
|
||||
"hub.lease_seconds" => "100"
|
||||
}
|
||||
|
||||
|
||||
{:ok, subscription } = Websub.incoming_subscription_request(user, data)
|
||||
assert subscription.topic == Pleroma.Web.OStatus.feed_path(user)
|
||||
assert subscription.state == "requested"
|
||||
assert subscription.secret == "a random secret"
|
||||
assert subscription.callback == "http://example.org/sub"
|
||||
end
|
||||
|
||||
test "an incoming subscription request for an existing subscription" do
|
||||
user = insert(:user)
|
||||
sub = insert(:websub_subscription, state: "accepted", topic: Pleroma.Web.OStatus.feed_path(user))
|
||||
|
||||
data = %{
|
||||
"hub.callback" => sub.callback,
|
||||
"hub.mode" => "subscription",
|
||||
"hub.topic" => Pleroma.Web.OStatus.feed_path(user),
|
||||
"hub.secret" => "a random secret",
|
||||
"hub.lease_seconds" => "100"
|
||||
}
|
||||
|
||||
|
||||
{:ok, subscription } = Websub.incoming_subscription_request(user, data)
|
||||
assert subscription.topic == Pleroma.Web.OStatus.feed_path(user)
|
||||
assert subscription.state == sub.state
|
||||
assert subscription.secret == "a random secret"
|
||||
assert subscription.callback == sub.callback
|
||||
assert length(Repo.all(WebsubServerSubscription)) == 1
|
||||
assert subscription.id == sub.id
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue