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