mirror of
https://github.com/caronc/apprise.git
synced 2025-02-21 12:41:16 +01:00
Improved rocketchat:// privacy + more test cases (#752)
This commit is contained in:
parent
184ff48551
commit
640c00ae70
@ -48,10 +48,6 @@ RC_HTTP_ERROR_MAP = {
|
|||||||
401: 'Authentication tokens provided is invalid or missing.',
|
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:
|
class RocketChatAuthMode:
|
||||||
"""
|
"""
|
||||||
@ -320,7 +316,8 @@ class NotifyRocketChat(NotifyBase):
|
|||||||
auth = '{user}{webhook}@'.format(
|
auth = '{user}{webhook}@'.format(
|
||||||
user='{}:'.format(NotifyRocketChat.quote(self.user, safe=''))
|
user='{}:'.format(NotifyRocketChat.quote(self.user, safe=''))
|
||||||
if self.user else '',
|
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
|
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
|
port='' if self.port is None or self.port == default_port
|
||||||
else ':{}'.format(self.port),
|
else ':{}'.format(self.port),
|
||||||
targets='/'.join(
|
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
|
# Channels are prefixed with a pound/hashtag symbol
|
||||||
['#{}'.format(x) for x in self.channels],
|
['#{}'.format(x) for x in self.channels],
|
||||||
# Rooms are as is
|
# Rooms are as is
|
||||||
|
@ -247,6 +247,7 @@ class AppriseURLTester:
|
|||||||
if privacy_url:
|
if privacy_url:
|
||||||
# Assess that our privacy url is as expected
|
# Assess that our privacy url is as expected
|
||||||
if not obj.url(privacy=True).startswith(privacy_url):
|
if not obj.url(privacy=True).startswith(privacy_url):
|
||||||
|
print('Provided %s' % url)
|
||||||
raise AssertionError(
|
raise AssertionError(
|
||||||
"Privacy URL: '{}' != expected '{}'".format(
|
"Privacy URL: '{}' != expected '{}'".format(
|
||||||
obj.url(privacy=True)[:len(privacy_url)],
|
obj.url(privacy=True)[:len(privacy_url)],
|
||||||
|
@ -75,6 +75,7 @@ apprise_url_tests = (
|
|||||||
'userId': 'user',
|
'userId': 'user',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
'privacy_url': 'rocket://user:****@localhost',
|
||||||
}),
|
}),
|
||||||
# A channel (using the to=)
|
# A channel (using the to=)
|
||||||
('rockets://user:pass@localhost?to=#channel', {
|
('rockets://user:pass@localhost?to=#channel', {
|
||||||
@ -87,6 +88,7 @@ apprise_url_tests = (
|
|||||||
'userId': 'user',
|
'userId': 'user',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
'privacy_url': 'rockets://user:****@localhost',
|
||||||
}),
|
}),
|
||||||
# A channel
|
# A channel
|
||||||
('rockets://user:pass@localhost/#channel', {
|
('rockets://user:pass@localhost/#channel', {
|
||||||
@ -99,6 +101,7 @@ apprise_url_tests = (
|
|||||||
'userId': 'user',
|
'userId': 'user',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
'privacy_url': 'rockets://user:****@localhost',
|
||||||
}),
|
}),
|
||||||
# Several channels
|
# Several channels
|
||||||
('rocket://user:pass@localhost/#channel1/#channel2/?avatar=Yes', {
|
('rocket://user:pass@localhost/#channel1/#channel2/?avatar=Yes', {
|
||||||
@ -111,6 +114,7 @@ apprise_url_tests = (
|
|||||||
'userId': 'user',
|
'userId': 'user',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
'privacy_url': 'rocket://user:****@localhost',
|
||||||
}),
|
}),
|
||||||
# Several Rooms
|
# Several Rooms
|
||||||
('rocket://user:pass@localhost/room1/room2', {
|
('rocket://user:pass@localhost/room1/room2', {
|
||||||
@ -123,6 +127,7 @@ apprise_url_tests = (
|
|||||||
'userId': 'user',
|
'userId': 'user',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
'privacy_url': 'rocket://user:****@localhost',
|
||||||
}),
|
}),
|
||||||
# A room and channel
|
# A room and channel
|
||||||
('rocket://user:pass@localhost/room/#channel?mode=basic&avatar=Yes', {
|
('rocket://user:pass@localhost/room/#channel?mode=basic&avatar=Yes', {
|
||||||
@ -151,6 +156,7 @@ apprise_url_tests = (
|
|||||||
'userId': 'user',
|
'userId': 'user',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
'privacy_url': 'rockets://user:****@localhost',
|
||||||
}),
|
}),
|
||||||
# A room and channel
|
# A room and channel
|
||||||
('rockets://user:pass@localhost/rooma/#channela', {
|
('rockets://user:pass@localhost/rooma/#channela', {
|
||||||
@ -168,9 +174,11 @@ apprise_url_tests = (
|
|||||||
# A web token
|
# A web token
|
||||||
('rockets://web/token@localhost/@user/#channel/roomid', {
|
('rockets://web/token@localhost/@user/#channel/roomid', {
|
||||||
'instance': NotifyRocketChat,
|
'instance': NotifyRocketChat,
|
||||||
|
'privacy_url': 'rockets://****@localhost/#channel/roomid',
|
||||||
}),
|
}),
|
||||||
('rockets://user:web/token@localhost/@user/?mode=webhook', {
|
('rockets://user:web/token@localhost/@user/?mode=webhook', {
|
||||||
'instance': NotifyRocketChat,
|
'instance': NotifyRocketChat,
|
||||||
|
'privacy_url': 'rockets://user:****@localhost',
|
||||||
}),
|
}),
|
||||||
('rockets://user:web/token@localhost?to=@user2,#channel2', {
|
('rockets://user:web/token@localhost?to=@user2,#channel2', {
|
||||||
'instance': NotifyRocketChat,
|
'instance': NotifyRocketChat,
|
||||||
@ -180,10 +188,11 @@ apprise_url_tests = (
|
|||||||
'instance': NotifyRocketChat,
|
'instance': NotifyRocketChat,
|
||||||
|
|
||||||
# Our expected url(privacy=True) startswith() response:
|
# 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', {
|
('rockets://localhost/@user/?mode=webhook&webhook=web/token', {
|
||||||
'instance': NotifyRocketChat,
|
'instance': NotifyRocketChat,
|
||||||
|
'privacy_url': 'rockets://****@localhost/@user'
|
||||||
}),
|
}),
|
||||||
('rockets://user:web/token@localhost/@user/?mode=invalid', {
|
('rockets://user:web/token@localhost/@user/?mode=invalid', {
|
||||||
# invalid mode
|
# invalid mode
|
||||||
@ -228,7 +237,7 @@ def test_plugin_rocket_chat_urls():
|
|||||||
|
|
||||||
@mock.patch('requests.get')
|
@mock.patch('requests.get')
|
||||||
@mock.patch('requests.post')
|
@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
|
NotifyRocketChat() Edge Cases
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user