Fix Zulip 401 when botname contains a dash (#581)

pull/584/head
Clemens Wolff 3 years ago committed by GitHub
parent fd0cb3ffcc
commit af2919fbb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -63,10 +63,11 @@ from ..common import NotifyType
from ..utils import parse_list from ..utils import parse_list
from ..utils import validate_regex from ..utils import validate_regex
from ..utils import is_email from ..utils import is_email
from ..utils import remove_suffix
from ..AppriseLocale import gettext_lazy as _ from ..AppriseLocale import gettext_lazy as _
# A Valid Bot Name # A Valid Bot Name
VALIDATE_BOTNAME = re.compile(r'(?P<name>[A-Z0-9_]{1,32})(-bot)?', re.I) VALIDATE_BOTNAME = re.compile(r'(?P<name>[A-Z0-9_-]{1,32})', re.I)
# Organization required as part of the API request # Organization required as part of the API request
VALIDATE_ORG = re.compile( VALIDATE_ORG = re.compile(
@ -122,7 +123,7 @@ class NotifyZulip(NotifyBase):
'botname': { 'botname': {
'name': _('Bot Name'), 'name': _('Bot Name'),
'type': 'string', 'type': 'string',
'regex': (r'^[A-Z0-9_]{1,32}(-bot)?$', 'i'), 'regex': (r'^[A-Z0-9_-]{1,32}$', 'i'),
}, },
'organization': { 'organization': {
'name': _('Organization'), 'name': _('Organization'),
@ -183,7 +184,9 @@ class NotifyZulip(NotifyBase):
raise TypeError raise TypeError
# The botname # The botname
self.botname = match.group('name') botname = match.group('name')
botname = remove_suffix(botname, '-bot')
self.botname = botname
except (TypeError, AttributeError): except (TypeError, AttributeError):
msg = 'The Zulip botname specified ({}) is invalid.'\ msg = 'The Zulip botname specified ({}) is invalid.'\

@ -1379,3 +1379,10 @@ def apply_template(template, app_mode=TemplateType.RAW, **kwargs):
# to drop the '{{' and '}}' surrounding our match so that we can # to drop the '{{' and '}}' surrounding our match so that we can
# re-index it back into our list # re-index it back into our list
return mask_r.sub(lambda x: fn(kwargs[x.group()[2:-2].strip()]), template) return mask_r.sub(lambda x: fn(kwargs[x.group()[2:-2].strip()]), template)
def remove_suffix(value, suffix):
"""
Removes a suffix from the end of a string.
"""
return value[:-len(suffix)] if value.endswith(suffix) else value

@ -55,6 +55,11 @@ apprise_url_tests = (
('zulip://....@apprise/{}'.format('a' * 32), { ('zulip://....@apprise/{}'.format('a' * 32), {
'instance': TypeError, 'instance': TypeError,
}), }),
# Valid everything - botname with a dash
('zulip://bot-name@apprise/{}'.format('a' * 32), {
'instance': plugins.NotifyZulip,
'privacy_url': 'zulip://bot-name@apprise/a...a/',
}),
# Valid everything - no target so default is used # Valid everything - no target so default is used
('zulip://botname@apprise/{}'.format('a' * 32), { ('zulip://botname@apprise/{}'.format('a' * 32), {
'instance': plugins.NotifyZulip, 'instance': plugins.NotifyZulip,

Loading…
Cancel
Save