Skip to content

Commit

Permalink
squashme
Browse files Browse the repository at this point in the history
  • Loading branch information
half-duplex committed Nov 21, 2024
1 parent d3b0cf4 commit ce4198c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
3 changes: 1 addition & 2 deletions sopel/builtins/safety.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,10 @@ def url_handler(bot: SopelWrapper, trigger: Trigger) -> None:
safe_url,
)
bot.say(
"{} {} of {} engine{} flagged a link {} posted as malicious".format(
"{} {} of {} engines flagged a link {} posted as malicious".format(
bold(color("WARNING:", colors.RED)),
positives,
total,
"" if total == 1 else "s",
bold(trigger.nick),
)
)
Expand Down
34 changes: 13 additions & 21 deletions test/builtins/test_builtins_safety.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,20 @@

URL_TESTS = (
# Valid URLs
("http://example.com", "hxxp://example[.]com"),
("http://1.2.3.4/", "hxxp://1[.]2[.]3[.]4/"),
("http://[fd00:1234::4321]/", "hxxp://[fd00[:]1234[:][:]4321]/"),
("ftp://1.2.3.4/", "fxp://1[.]2[.]3[.]4/"),
("http://example.com", ("hxxp://example[.]com")),
("http://1.2.3.4/mgr.cgi", ("hxxp://1[.]2[.]3[.]4/mgr.cgi")),
("http://[fd00:1234::4321]/", ("hxxp://[fd00[:]1234[:][:]4321]/")),
("ftp://1.2.3.4/", ("fxp://1[.]2[.]3[.]4/")),
# Invalid, but parsed anyway
("http://<Target-IP>/", "hxxp://<Target-IP>/"),
("http://1.2.3.4.5/", "hxxp://1[.]2[.]3[.]4[.]5/"),
("http://555.555.555.555/", "hxxp://555[.]555[.]555[.]555/"),
# Fallback path
("http://[fd00:::]/", "http[:]//[fd00[:][:][:]]/"),
("http://<placeholder>/", ("hxxp://<placeholder>/")),
("http://1.2.3.4.5/", ("hxxp://1[.]2[.]3[.]4[.]5/")),
("http://555.555.555.555/", ("hxxp://555[.]555[.]555[.]555/")),
# urllib.urlparse() works in python <=3.10 but fails in 3.11
("http://[fd00:::]/", ("hxxp://[fd00[:][:][:]]/", "http[:]//[fd00[:][:][:]]/")),
("http://[placeholder]/", ("hxxp://[placeholder]/", "http[:]//[placeholder]/")),
)


@pytest.mark.parametrize("original, safed", URL_TESTS)
def test_safeify_url(original, safed):
assert safeify_url(original) == safed


def test_safeify_maybe_parsefail():
# Parse succeeds in python <=3.10 but fails in 3.11
original = "http://[Target-IP]/account_mgr.cgi"
parseok = "hxxp://[Target-IP]/account_mgr.cgi"
parsefail = "http[:]//[Target-IP]/account_mgr[.]cgi"

assert safeify_url(original) in (parseok, parsefail)
@pytest.mark.parametrize("original, safed_options", URL_TESTS)
def test_safeify_url(original, safed_options):
assert safeify_url(original) in safed_options

0 comments on commit ce4198c

Please sign in to comment.