forked from AkkomaGang/akkoma
parent
2fc5fb7f5a
commit
90088cce11
3 changed files with 34 additions and 2 deletions
|
@ -161,11 +161,18 @@ defp get_policies(_), do: []
|
||||||
# - https://extra.baddomain.net/
|
# - https://extra.baddomain.net/
|
||||||
# Does NOT match the following:
|
# Does NOT match the following:
|
||||||
# - https://maybebaddomain.net/
|
# - https://maybebaddomain.net/
|
||||||
|
|
||||||
|
# *.baddomain.net
|
||||||
def subdomain_regex("*." <> domain), do: subdomain_regex(domain)
|
def subdomain_regex("*." <> domain), do: subdomain_regex(domain)
|
||||||
|
|
||||||
|
# baddomain.net
|
||||||
def subdomain_regex(domain) do
|
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
|
~r/^(.+\.)?#{Regex.escape(domain)}$/i
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
@spec subdomains_regex([String.t()]) :: [Regex.t()]
|
@spec subdomains_regex([String.t()]) :: [Regex.t()]
|
||||||
def subdomains_regex(domains) when is_list(domains) do
|
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")
|
refute MRF.subdomain_match?(regexes, "sub.unsafe.tldanother")
|
||||||
end
|
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
|
test "matches are case-insensitive" do
|
||||||
regexes = MRF.subdomains_regex(["UnSafe.TLD", "UnSAFE2.Tld"])
|
regexes = MRF.subdomains_regex(["UnSafe.TLD", "UnSAFE2.Tld"])
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ test "a basic note validates", %{note: note} do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "a note with a language validates" do
|
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!()
|
note = File.read!("test/fixtures/mastodon/note_with_language.json") |> Jason.decode!()
|
||||||
|
|
||||||
%{
|
%{
|
||||||
|
|
Loading…
Reference in a new issue