Improved rocketchat:// privacy + more test cases (#752)

This commit is contained in:
Chris Caron 2022-11-11 16:54:07 -05:00 committed by GitHub
parent 184ff48551
commit 640c00ae70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 8 deletions

View File

@ -48,10 +48,6 @@ RC_HTTP_ERROR_MAP = {
401: 'Authentication tokens provided is invalid or missing.',
}
# Used to break apart list of potential tags by their delimiter
# into a usable list.
LIST_DELIM = re.compile(r'[ \t\r\n,\\/]+')
class RocketChatAuthMode:
"""
@ -320,7 +316,8 @@ class NotifyRocketChat(NotifyBase):
auth = '{user}{webhook}@'.format(
user='{}:'.format(NotifyRocketChat.quote(self.user, safe=''))
if self.user else '',
webhook=self.pprint(self.webhook, privacy, safe=''),
webhook=self.pprint(self.webhook, privacy,
mode=PrivacyMode.Secret, safe=''),
)
default_port = 443 if self.secure else 80
@ -333,7 +330,7 @@ class NotifyRocketChat(NotifyBase):
port='' if self.port is None or self.port == default_port
else ':{}'.format(self.port),
targets='/'.join(
[NotifyRocketChat.quote(x, safe='') for x in chain(
[NotifyRocketChat.quote(x, safe='@#') for x in chain(
# Channels are prefixed with a pound/hashtag symbol
['#{}'.format(x) for x in self.channels],
# Rooms are as is

View File

@ -247,6 +247,7 @@ class AppriseURLTester:
if privacy_url:
# Assess that our privacy url is as expected
if not obj.url(privacy=True).startswith(privacy_url):
print('Provided %s' % url)
raise AssertionError(
"Privacy URL: '{}' != expected '{}'".format(
obj.url(privacy=True)[:len(privacy_url)],

View File

@ -75,6 +75,7 @@ apprise_url_tests = (
'userId': 'user',
},
},
'privacy_url': 'rocket://user:****@localhost',
}),
# A channel (using the to=)
('rockets://user:pass@localhost?to=#channel', {
@ -87,6 +88,7 @@ apprise_url_tests = (
'userId': 'user',
},
},
'privacy_url': 'rockets://user:****@localhost',
}),
# A channel
('rockets://user:pass@localhost/#channel', {
@ -99,6 +101,7 @@ apprise_url_tests = (
'userId': 'user',
},
},
'privacy_url': 'rockets://user:****@localhost',
}),
# Several channels
('rocket://user:pass@localhost/#channel1/#channel2/?avatar=Yes', {
@ -111,6 +114,7 @@ apprise_url_tests = (
'userId': 'user',
},
},
'privacy_url': 'rocket://user:****@localhost',
}),
# Several Rooms
('rocket://user:pass@localhost/room1/room2', {
@ -123,6 +127,7 @@ apprise_url_tests = (
'userId': 'user',
},
},
'privacy_url': 'rocket://user:****@localhost',
}),
# A room and channel
('rocket://user:pass@localhost/room/#channel?mode=basic&avatar=Yes', {
@ -151,6 +156,7 @@ apprise_url_tests = (
'userId': 'user',
},
},
'privacy_url': 'rockets://user:****@localhost',
}),
# A room and channel
('rockets://user:pass@localhost/rooma/#channela', {
@ -168,9 +174,11 @@ apprise_url_tests = (
# A web token
('rockets://web/token@localhost/@user/#channel/roomid', {
'instance': NotifyRocketChat,
'privacy_url': 'rockets://****@localhost/#channel/roomid',
}),
('rockets://user:web/token@localhost/@user/?mode=webhook', {
'instance': NotifyRocketChat,
'privacy_url': 'rockets://user:****@localhost',
}),
('rockets://user:web/token@localhost?to=@user2,#channel2', {
'instance': NotifyRocketChat,
@ -180,10 +188,11 @@ apprise_url_tests = (
'instance': NotifyRocketChat,
# Our expected url(privacy=True) startswith() response:
'privacy_url': 'rockets://w...n@localhost',
'privacy_url': 'rockets://****@localhost/',
}),
('rockets://localhost/@user/?mode=webhook&webhook=web/token', {
'instance': NotifyRocketChat,
'privacy_url': 'rockets://****@localhost/@user'
}),
('rockets://user:web/token@localhost/@user/?mode=invalid', {
# invalid mode
@ -228,7 +237,7 @@ def test_plugin_rocket_chat_urls():
@mock.patch('requests.get')
@mock.patch('requests.post')
def test_plugin_rocketchat_edge_cases(mock_post, mock_get):
def test_plugin_rocket_chat_edge_cases(mock_post, mock_get):
"""
NotifyRocketChat() Edge Cases