parent
2fc5fb7f5a
commit
90088cce11
|
@ -161,11 +161,18 @@ defp get_policies(_), do: []
|
|||
# - https://extra.baddomain.net/
|
||||
# Does NOT match the following:
|
||||
# - https://maybebaddomain.net/
|
||||
|
||||
# *.baddomain.net
|
||||
def subdomain_regex("*." <> domain), do: subdomain_regex(domain)
|
||||
|
||||
# baddomain.net
|
||||
def subdomain_regex(domain) do
|
||||
if String.ends_with?(domain, ".*") do
|
||||
~r/^(.+\.)?#{Regex.escape(String.replace_suffix(domain, ".*", ""))}\.(.+)$/i
|
||||
else
|
||||
~r/^(.+\.)?#{Regex.escape(domain)}$/i
|
||||
end
|
||||
end
|
||||
|
||||
@spec subdomains_regex([String.t()]) :: [Regex.t()]
|
||||
def subdomains_regex(domains) when is_list(domains) do
|
||||
|
|
|
@ -48,6 +48,31 @@ test "wildcard domains with two subdomains" do
|
|||
refute MRF.subdomain_match?(regexes, "sub.unsafe.tldanother")
|
||||
end
|
||||
|
||||
test "wildcard on the tld" do
|
||||
regexes = MRF.subdomains_regex(["somewhere.*"])
|
||||
|
||||
assert regexes == [~r/^(.+\.)?somewhere\.(.+)$/i]
|
||||
|
||||
assert MRF.subdomain_match?(regexes, "somewhere.net")
|
||||
assert MRF.subdomain_match?(regexes, "somewhere.com")
|
||||
assert MRF.subdomain_match?(regexes, "somewhere.somewherelese.net")
|
||||
refute MRF.subdomain_match?(regexes, "somewhere")
|
||||
end
|
||||
|
||||
test "wildcards on subdomain _and_ tld" do
|
||||
regexes = MRF.subdomains_regex(["*.somewhere.*"])
|
||||
|
||||
assert regexes == [~r/^(.+\.)?somewhere\.(.+)$/i]
|
||||
|
||||
assert MRF.subdomain_match?(regexes, "somewhere.net")
|
||||
assert MRF.subdomain_match?(regexes, "somewhere.com")
|
||||
assert MRF.subdomain_match?(regexes, "sub.somewhere.net")
|
||||
assert MRF.subdomain_match?(regexes, "sub.somewhere.com")
|
||||
assert MRF.subdomain_match?(regexes, "sub.sub.somewhere.net")
|
||||
assert MRF.subdomain_match?(regexes, "sub.sub.somewhere.com")
|
||||
refute MRF.subdomain_match?(regexes, "somewhere")
|
||||
end
|
||||
|
||||
test "matches are case-insensitive" do
|
||||
regexes = MRF.subdomains_regex(["UnSafe.TLD", "UnSAFE2.Tld"])
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ test "a basic note validates", %{note: note} do
|
|||
end
|
||||
|
||||
test "a note with a language validates" do
|
||||
user = insert(:user, %{ap_id: "https://mastodon.social/users/akkoma_ap_integration_tester"})
|
||||
insert(:user, %{ap_id: "https://mastodon.social/users/akkoma_ap_integration_tester"})
|
||||
note = File.read!("test/fixtures/mastodon/note_with_language.json") |> Jason.decode!()
|
||||
|
||||
%{
|
||||
|
|
Loading…
Reference in a new issue