Merge branch 'fix/status_expires_in_validation' into 'develop'
authorfeld <feld@feld.me>
Thu, 13 Feb 2020 14:03:59 +0000 (14:03 +0000)
committerfeld <feld@feld.me>
Thu, 13 Feb 2020 14:03:59 +0000 (14:03 +0000)
Fix `status.expires_in` validation

See merge request pleroma/pleroma!2203

lib/pleroma/activity_expiration.ex
test/web/mastodon_api/controllers/status_controller_test.exs

index 7ea5c48ca25564c4066266306692b0a43cd9001d..a58a493f79fd6df6ea8018392d55cff3f6f4da2c 100644 (file)
@@ -62,6 +62,6 @@ defmodule Pleroma.ActivityExpiration do
   def expires_late_enough?(scheduled_at) do
     now = NaiveDateTime.utc_now()
     diff = NaiveDateTime.diff(scheduled_at, now, :millisecond)
-    diff >= @min_activity_lifetime
+    diff > @min_activity_lifetime
   end
 end
index 83138d7ef9b2bd07fdc8d93e3d72f5cb53054100..810f371cb756078f5ea21348e0cf4ac40ac19001 100644 (file)
@@ -121,6 +121,32 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
                NaiveDateTime.to_iso8601(expiration.scheduled_at)
     end
 
+    test "it fails to create a status if `expires_in` is less or equal than an hour", %{
+      conn: conn
+    } do
+      # 1 hour
+      expires_in = 60 * 60
+
+      assert %{"error" => "Expiry date is too soon"} =
+               conn
+               |> post("api/v1/statuses", %{
+                 "status" => "oolong",
+                 "expires_in" => expires_in
+               })
+               |> json_response(422)
+
+      # 30 minutes
+      expires_in = 30 * 60
+
+      assert %{"error" => "Expiry date is too soon"} =
+               conn
+               |> post("api/v1/statuses", %{
+                 "status" => "oolong",
+                 "expires_in" => expires_in
+               })
+               |> json_response(422)
+    end
+
     test "posting an undefined status with an attachment", %{user: user, conn: conn} do
       file = %Plug.Upload{
         content_type: "image/jpg",