Make captcha (kocaptcha) stateless
[akkoma] / test / captcha_test.exs
1 defmodule Pleroma.CaptchaTest do
2 use ExUnit.Case
3
4 import Tesla.Mock
5
6 alias Pleroma.Captcha.Kocaptcha
7
8 @ets_options [:ordered_set, :private, :named_table, {:read_concurrency, true}]
9
10 describe "Kocaptcha" do
11 setup do
12 ets_name = Kocaptcha.Ets
13 ^ets_name = :ets.new(ets_name, @ets_options)
14
15 mock(fn
16 %{method: :get, url: "https://captcha.kotobank.ch/new"} ->
17 json(%{
18 md5: "63615261b77f5354fb8c4e4986477555",
19 token: "afa1815e14e29355e6c8f6b143a39fa2",
20 url: "/captchas/afa1815e14e29355e6c8f6b143a39fa2.png"
21 })
22 end)
23
24 :ok
25 end
26
27 test "new and validate" do
28 new = Kocaptcha.new()
29 assert new[:type] == :kocaptcha
30 assert new[:token] == "afa1815e14e29355e6c8f6b143a39fa2"
31
32 assert new[:url] ==
33 "https://captcha.kotobank.ch/captchas/afa1815e14e29355e6c8f6b143a39fa2.png"
34
35 assert Kocaptcha.validate(
36 new[:token],
37 "7oEy8c",
38 new[:answer_data]
39 ) == :ok
40 end
41 end
42 end