1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.CaptchaTest do
10 alias Pleroma.Captcha.Kocaptcha
11 alias Pleroma.Captcha.Native
13 @ets_options [:ordered_set, :private, :named_table, {:read_concurrency, true}]
15 describe "Kocaptcha" do
17 ets_name = Kocaptcha.Ets
18 ^ets_name = :ets.new(ets_name, @ets_options)
21 %{method: :get, url: "https://captcha.kotobank.ch/new"} ->
23 md5: "63615261b77f5354fb8c4e4986477555",
24 token: "afa1815e14e29355e6c8f6b143a39fa2",
25 url: "/captchas/afa1815e14e29355e6c8f6b143a39fa2.png"
32 test "new and validate" do
34 assert new[:type] == :kocaptcha
35 assert new[:token] == "afa1815e14e29355e6c8f6b143a39fa2"
38 "https://captcha.kotobank.ch/captchas/afa1815e14e29355e6c8f6b143a39fa2.png"
40 assert Kocaptcha.validate(
49 test "new and validate" do
56 url: "data:image/png;base64," <> _
59 assert is_binary(answer)
60 assert :ok = Native.validate(token, answer, answer)
61 assert {:error, "Invalid CAPTCHA"} == Native.validate(token, answer, answer <> "foobar")