logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

mrf_test.exs (2698B)


  1. defmodule Pleroma.Web.ActivityPub.MRFTest do
  2. use ExUnit.Case, async: true
  3. use Pleroma.Tests.Helpers
  4. alias Pleroma.Web.ActivityPub.MRF
  5. test "subdomains_regex/1" do
  6. assert MRF.subdomains_regex(["unsafe.tld", "*.unsafe.tld"]) == [
  7. ~r/^unsafe.tld$/i,
  8. ~r/^(.*\.)*unsafe.tld$/i
  9. ]
  10. end
  11. describe "subdomain_match/2" do
  12. test "common domains" do
  13. regexes = MRF.subdomains_regex(["unsafe.tld", "unsafe2.tld"])
  14. assert regexes == [~r/^unsafe.tld$/i, ~r/^unsafe2.tld$/i]
  15. assert MRF.subdomain_match?(regexes, "unsafe.tld")
  16. assert MRF.subdomain_match?(regexes, "unsafe2.tld")
  17. refute MRF.subdomain_match?(regexes, "example.com")
  18. end
  19. test "wildcard domains with one subdomain" do
  20. regexes = MRF.subdomains_regex(["*.unsafe.tld"])
  21. assert regexes == [~r/^(.*\.)*unsafe.tld$/i]
  22. assert MRF.subdomain_match?(regexes, "unsafe.tld")
  23. assert MRF.subdomain_match?(regexes, "sub.unsafe.tld")
  24. refute MRF.subdomain_match?(regexes, "anotherunsafe.tld")
  25. refute MRF.subdomain_match?(regexes, "unsafe.tldanother")
  26. end
  27. test "wildcard domains with two subdomains" do
  28. regexes = MRF.subdomains_regex(["*.unsafe.tld"])
  29. assert regexes == [~r/^(.*\.)*unsafe.tld$/i]
  30. assert MRF.subdomain_match?(regexes, "unsafe.tld")
  31. assert MRF.subdomain_match?(regexes, "sub.sub.unsafe.tld")
  32. refute MRF.subdomain_match?(regexes, "sub.anotherunsafe.tld")
  33. refute MRF.subdomain_match?(regexes, "sub.unsafe.tldanother")
  34. end
  35. test "matches are case-insensitive" do
  36. regexes = MRF.subdomains_regex(["UnSafe.TLD", "UnSAFE2.Tld"])
  37. assert regexes == [~r/^UnSafe.TLD$/i, ~r/^UnSAFE2.Tld$/i]
  38. assert MRF.subdomain_match?(regexes, "UNSAFE.TLD")
  39. assert MRF.subdomain_match?(regexes, "UNSAFE2.TLD")
  40. assert MRF.subdomain_match?(regexes, "unsafe.tld")
  41. assert MRF.subdomain_match?(regexes, "unsafe2.tld")
  42. refute MRF.subdomain_match?(regexes, "EXAMPLE.COM")
  43. refute MRF.subdomain_match?(regexes, "example.com")
  44. end
  45. end
  46. describe "describe/0" do
  47. test "it works as expected with noop policy" do
  48. clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.NoOpPolicy])
  49. expected = %{
  50. mrf_policies: ["NoOpPolicy"],
  51. exclusions: false
  52. }
  53. {:ok, ^expected} = MRF.describe()
  54. end
  55. test "it works as expected with mock policy" do
  56. clear_config([:mrf, :policies], [MRFModuleMock])
  57. expected = %{
  58. mrf_policies: ["MRFModuleMock"],
  59. mrf_module_mock: "some config data",
  60. exclusions: false
  61. }
  62. {:ok, ^expected} = MRF.describe()
  63. end
  64. end
  65. end