Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.2KB

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