Skip to content

Commit 04ea15c

Browse files
committed
test: add test case + supporting fixtures for url privilege check
We would have noticed sooner that `.urlban` was broken if it had test coverage. Now it does.
1 parent f637035 commit 04ea15c

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

test/builtins/test_builtins_url.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,22 @@ def callback(bot, trigger, match):
7676
return sopel
7777

7878

79+
PRELOADED_CONFIG = """
80+
[core]
81+
owner = testnick
82+
nick = TestBot
83+
enable =
84+
coretasks
85+
url
86+
"""
87+
88+
89+
@pytest.fixture
90+
def preloadedbot(configfactory, botfactory):
91+
tmpconfig = configfactory('preloaded.cfg', PRELOADED_CONFIG)
92+
return botfactory.preloaded(tmpconfig, ['url'])
93+
94+
7995
@pytest.mark.parametrize("site", INVALID_URLS)
8096
def test_find_title_invalid(site):
8197
# All local for invalid ones
@@ -114,3 +130,30 @@ def test_url_triggers_rules_and_auto_title(mockbot):
114130
labels = sorted(result[0].get_rule_label() for result in results)
115131
expected = ['handle_urls_https', 'title_auto']
116132
assert labels == expected
133+
134+
135+
@pytest.mark.parametrize('level, result', (
136+
('NOTHING', False),
137+
('VOICE', False),
138+
('HALFOP', False),
139+
('OP', True),
140+
('ADMIN', True),
141+
('OWNER', True),
142+
))
143+
def test_url_ban_privilege(preloadedbot, ircfactory, triggerfactory, level, result):
144+
"""Make sure the urlban command privilege check functions correctly."""
145+
irc = ircfactory(preloadedbot)
146+
irc.channel_joined('#test', [
147+
'Unothing', 'Uvoice', 'Uhalfop', 'Uop', 'Uadmin', 'Uowner'])
148+
irc.mode_set('#test', '+vhoaq', [
149+
'Uvoice', 'Uhalfop', 'Uop', 'Uadmin', 'Uowner'])
150+
151+
nick = f'U{level.title()}'
152+
user = level.lower()
153+
line = f':{nick}!{user}@example.com PRIVMSG #test :.urlban *'
154+
wrapper = triggerfactory.wrapper(preloadedbot, line)
155+
match = triggerfactory(preloadedbot, line)
156+
157+
# parameter matrix assumes the default `url.exclude_required_access` config
158+
# value, which was 'OP' at the time of test creation
159+
assert url._user_can_change_excludes(wrapper, match) == result

0 commit comments

Comments
 (0)