mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2026-02-15 17:16:57 +00:00
Elixir 1.19 MRFTest: Replace matchable_regexes with regexes_match! func
This commit is contained in:
parent
467a3728d9
commit
fef11eb280
1 changed files with 13 additions and 13 deletions
|
|
@ -10,22 +10,25 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
|
|||
|
||||
alias Pleroma.Web.ActivityPub.MRF
|
||||
|
||||
defp regexes_match!([],[]), do: true
|
||||
|
||||
defp regexes_match!([authority | authority_rest], [checked | checked_rest]) do
|
||||
authority.source == checked.source and regexes_match!(authority_rest, checked_rest)
|
||||
end
|
||||
|
||||
defp regexes_match!(_, _), do: false
|
||||
|
||||
test "subdomains_regex/1" do
|
||||
regexes = MRF.subdomains_regex(["unsafe.tld", "*.unsafe.tld"])
|
||||
matchable_regexes = Enum.map(regexes, fn r -> r.source end)
|
||||
|
||||
assert matchable_regexes == [
|
||||
~r/^unsafe.tld$/i.source,
|
||||
~r/^(.*\.)*unsafe.tld$/i.source
|
||||
]
|
||||
assert regexes_match!(regexes, [~r/^unsafe.tld$/i, ~r/^(.*\.)*unsafe.tld$/i])
|
||||
end
|
||||
|
||||
describe "subdomain_match/2" do
|
||||
test "common domains" do
|
||||
regexes = MRF.subdomains_regex(["unsafe.tld", "unsafe2.tld"])
|
||||
matchable_regexes = Enum.map(regexes, fn r -> r.source end)
|
||||
|
||||
assert matchable_regexes == [~r/^unsafe.tld$/i.source, ~r/^unsafe2.tld$/i.source]
|
||||
assert regexes_match!(regexes, [~r/^unsafe.tld$/i, ~r/^unsafe2.tld$/i])
|
||||
|
||||
assert MRF.subdomain_match?(regexes, "unsafe.tld")
|
||||
assert MRF.subdomain_match?(regexes, "unsafe2.tld")
|
||||
|
|
@ -35,9 +38,8 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
|
|||
|
||||
test "wildcard domains with one subdomain" do
|
||||
regexes = MRF.subdomains_regex(["*.unsafe.tld"])
|
||||
matchable_regexes = Enum.map(regexes, fn r -> r.source end)
|
||||
|
||||
assert matchable_regexes == [~r/^(.*\.)*unsafe.tld$/i.source]
|
||||
assert regexes_match!(regexes, [~r/^(.*\.)*unsafe.tld$/i])
|
||||
|
||||
assert MRF.subdomain_match?(regexes, "unsafe.tld")
|
||||
assert MRF.subdomain_match?(regexes, "sub.unsafe.tld")
|
||||
|
|
@ -47,9 +49,8 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
|
|||
|
||||
test "wildcard domains with two subdomains" do
|
||||
regexes = MRF.subdomains_regex(["*.unsafe.tld"])
|
||||
matchable_regexes = Enum.map(regexes, fn r -> r.source end)
|
||||
|
||||
assert matchable_regexes == [~r/^(.*\.)*unsafe.tld$/i.source]
|
||||
assert regexes_match!(regexes, [~r/^(.*\.)*unsafe.tld$/i])
|
||||
|
||||
assert MRF.subdomain_match?(regexes, "unsafe.tld")
|
||||
assert MRF.subdomain_match?(regexes, "sub.sub.unsafe.tld")
|
||||
|
|
@ -59,9 +60,8 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
|
|||
|
||||
test "matches are case-insensitive" do
|
||||
regexes = MRF.subdomains_regex(["UnSafe.TLD", "UnSAFE2.Tld"])
|
||||
matchable_regexes = Enum.map(regexes, fn r -> r.source end)
|
||||
|
||||
assert matchable_regexes == [~r/^UnSafe.TLD$/i.source, ~r/^UnSAFE2.Tld$/i.source]
|
||||
assert regexes_match!(regexes, [~r/^UnSafe.TLD$/i, ~r/^UnSAFE2.Tld$/i])
|
||||
|
||||
assert MRF.subdomain_match?(regexes, "UNSAFE.TLD")
|
||||
assert MRF.subdomain_match?(regexes, "UNSAFE2.TLD")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue