Set valid_until date.
authorRoger Braun <roger@rogerbraun.net>
Wed, 10 May 2017 16:45:55 +0000 (18:45 +0200)
committerRoger Braun <roger@rogerbraun.net>
Wed, 10 May 2017 16:45:55 +0000 (18:45 +0200)
lib/pleroma/web/websub/websub_controller.ex
test/web/websub/websub_controller_test.exs

index 4fc6932140fe777c8a8d73c56948d24af69d0085..9d3c1cd01b1061a47fae9a43994305d4be6f7397 100644 (file)
@@ -18,9 +18,11 @@ defmodule Pleroma.Web.Websub.WebsubController do
     end
   end
 
-  def websub_subscription_confirmation(conn, %{"id" => id, "hub.mode" => "subscribe", "hub.challenge" => challenge, "hub.topic" => topic}) do
+  # TODO: Extract this into the Websub module
+  def websub_subscription_confirmation(conn, %{"id" => id, "hub.mode" => "subscribe", "hub.challenge" => challenge, "hub.topic" => topic, "hub.lease_seconds" => lease_seconds}) do
     with %WebsubClientSubscription{} = websub <- Repo.get_by(WebsubClientSubscription, id: id, topic: topic) do
-      change = Ecto.Changeset.change(websub, %{state: "accepted"})
+      valid_until = NaiveDateTime.add(NaiveDateTime.utc_now, String.to_integer(lease_seconds))
+      change = Ecto.Changeset.change(websub, %{state: "accepted", valid_until: valid_until})
       {:ok, _websub} = Repo.update(change)
       conn
       |> send_resp(200, challenge)
index 8f68248a486d2e97ac2aa676f767182ae38f4c74..0aa0fdff742ce4c7c5015049621d89ceda215854 100644 (file)
@@ -31,7 +31,7 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do
       "hub.mode" => "subscribe",
       "hub.topic" => websub.topic,
       "hub.challenge" => "some challenge",
-      "hub.lease_seconds" => 100
+      "hub.lease_seconds" => "100"
     }
 
     conn = conn
@@ -41,8 +41,7 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do
 
     assert response(conn, 200) == "some challenge"
     assert websub.state == "accepted"
-
-    # TODO valid_until
+    assert_in_delta NaiveDateTime.diff(websub.valid_until, NaiveDateTime.utc_now), 100, 5
   end
 
   test "handles incoming feed updates", %{conn: conn} do