@@ -70,6 +70,22 @@ def callback(bot, trigger, match):
7070 return sopel
7171
7272
73+ PRELOADED_CONFIG = """
74+ [core]
75+ owner = testnick
76+ nick = TestBot
77+ enable =
78+ coretasks
79+ url
80+ """
81+
82+
83+ @pytest .fixture
84+ def preloadedbot (configfactory , botfactory ):
85+ tmpconfig = configfactory ('preloaded.cfg' , PRELOADED_CONFIG )
86+ return botfactory .preloaded (tmpconfig , ['url' ])
87+
88+
7389@pytest .mark .parametrize ("site" , INVALID_URLS )
7490def test_find_title_invalid (site ):
7591 # All local for invalid ones
@@ -103,3 +119,30 @@ def test_url_triggers_rules_and_auto_title(mockbot):
103119 labels = sorted (result [0 ].get_rule_label () for result in results )
104120 expected = ['handle_urls_https' , 'title_auto' ]
105121 assert labels == expected
122+
123+
124+ @pytest .mark .parametrize ('level, result' , (
125+ ('NOTHING' , False ),
126+ ('VOICE' , False ),
127+ ('HALFOP' , False ),
128+ ('OP' , True ),
129+ ('ADMIN' , True ),
130+ ('OWNER' , True ),
131+ ))
132+ def test_url_ban_privilege (preloadedbot , ircfactory , triggerfactory , level , result ):
133+ """Make sure the urlban command privilege check functions correctly."""
134+ irc = ircfactory (preloadedbot )
135+ irc .channel_joined ('#test' , [
136+ 'Unothing' , 'Uvoice' , 'Uhalfop' , 'Uop' , 'Uadmin' , 'Uowner' ])
137+ irc .mode_set ('#test' , '+vhoaq' , [
138+ 'Uvoice' , 'Uhalfop' , 'Uop' , 'Uadmin' , 'Uowner' ])
139+
140+ nick = f'U{ level .title ()} '
141+ user = level .lower ()
142+ line = f':{ nick } !{ user } @example.com PRIVMSG #test :.urlban *'
143+ wrapper = triggerfactory .wrapper (preloadedbot , line )
144+ match = triggerfactory (preloadedbot , line )
145+
146+ # parameter matrix assumes the default `url.exclude_required_access` config
147+ # value, which was 'OP' at the time of test creation
148+ assert url ._user_can_change_excludes (wrapper , match ) == result
0 commit comments