logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma
commit: 34a1ce00ecc6f19827638fc311e4e76d3c4cb162
parent: a2ca3b86053d0f74106bc65fddd7073d12423bbe
Author: Roger Braun <roger@rogerbraun.net>
Date:   Wed, 10 May 2017 18:45:55 +0200

Set valid_until date.

Diffstat:

Mlib/pleroma/web/websub/websub_controller.ex6++++--
Mtest/web/websub/websub_controller_test.exs5++---
2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/lib/pleroma/web/websub/websub_controller.ex b/lib/pleroma/web/websub/websub_controller.ex @@ -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) diff --git a/test/web/websub/websub_controller_test.exs b/test/web/websub/websub_controller_test.exs @@ -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