Expose seconds_valid in Pleroma Captcha API endpoint
authorMark Felder <feld@FreeBSD.org>
Wed, 29 Jul 2020 21:07:22 +0000 (16:07 -0500)
committerMark Felder <feld@FreeBSD.org>
Wed, 29 Jul 2020 21:07:22 +0000 (16:07 -0500)
CHANGELOG.md
docs/API/pleroma_api.md
lib/pleroma/captcha/kocaptcha.ex
lib/pleroma/captcha/native.ex
test/captcha_test.exs
test/support/captcha_mock.ex

index 7d5256600df8986d5e5995d8667feddb28f0341b..52f917720b4b62fb60decb240c5a1c55a1fb6886 100644 (file)
@@ -33,6 +33,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
   contents has been renamed to `hide_notification_contents`
 - Mastodon API: Added `pleroma.metadata.post_formats` to /api/v1/instance
 - Mastodon API (legacy): Allow query parameters for `/api/v1/domain_blocks`, e.g. `/api/v1/domain_blocks?domain=badposters.zone`
+- **Breaking:** Pleroma API: `/api/pleroma/captcha` responses now include `seconds_valid` with an integer value.
 </details>
 
 <details>
index 5bd38ad364d9db7be00fbb0750a9de3ddbe1e1e8..b29f4d5a065e1e3cdb0d7e995b89c1c1b22d5ff2 100644 (file)
@@ -50,7 +50,7 @@ Request parameters can be passed via [query strings](https://en.wikipedia.org/wi
 * Authentication: not required
 * Params: none
 * Response: Provider specific JSON, the only guaranteed parameter is `type`
-* Example response: `{"type": "kocaptcha", "token": "whatever", "url": "https://captcha.kotobank.ch/endpoint"}`
+* Example response: `{"type": "kocaptcha", "token": "whatever", "url": "https://captcha.kotobank.ch/endpoint", seconds_valid: 300}`
 
 ## `/api/pleroma/delete_account`
 ### Delete an account
index 6bc2fa158a2045182b9641c2f04166e168eaded7..337506647b373c21b9532bb924464982eeceaefb 100644 (file)
@@ -21,7 +21,8 @@ defmodule Pleroma.Captcha.Kocaptcha do
           type: :kocaptcha,
           token: json_resp["token"],
           url: endpoint <> json_resp["url"],
-          answer_data: json_resp["md5"]
+          answer_data: json_resp["md5"],
+          seconds_valid: Pleroma.Config.get([Pleroma.Captcha, :seconds_valid])
         }
     end
   end
index a90631d61be6e66b78cfbf4b30886aa788849427..8d604d2b2c00dd5af16759c7e8130bdc791914ce 100644 (file)
@@ -17,7 +17,8 @@ defmodule Pleroma.Captcha.Native do
           type: :native,
           token: token(),
           url: "data:image/png;base64," <> Base.encode64(img_binary),
-          answer_data: answer_data
+          answer_data: answer_data,
+          seconds_valid: Pleroma.Config.get([Pleroma.Captcha, :seconds_valid])
         }
     end
   end
index 1ab9019ab756d4caee7d46463f31566d6c730901..1b9f4a12f5be8b3055cc2d49fb7ad492db7da429 100644 (file)
@@ -41,7 +41,8 @@ defmodule Pleroma.CaptchaTest do
                answer_data: answer,
                token: ^token,
                url: ^url,
-               type: :kocaptcha
+               type: :kocaptcha,
+               seconds_valid: 300
              } = new
 
       assert Kocaptcha.validate(token, "7oEy8c", answer) == :ok
@@ -56,7 +57,8 @@ defmodule Pleroma.CaptchaTest do
                answer_data: answer,
                token: token,
                type: :native,
-               url: "data:image/png;base64," <> _
+               url: "data:image/png;base64," <> _,
+               seconds_valid: 300
              } = new
 
       assert is_binary(answer)
index 7b0c1d5af72c7e3957e124b40b7011901febf7c9..2ed2ba3b405a751113b0b90682dae18423b442a4 100644 (file)
@@ -16,7 +16,8 @@ defmodule Pleroma.Captcha.Mock do
       type: :mock,
       token: "afa1815e14e29355e6c8f6b143a39fa2",
       answer_data: @solution,
-      url: "https://example.org/captcha.png"
+      url: "https://example.org/captcha.png",
+      seconds_valid: 300
     }
 
   @impl Service