clicksend:// authentication bugfix (#1121)

This commit is contained in:
Chris Caron 2024-05-05 12:42:08 -04:00 committed by GitHub
parent fcd70ff84c
commit 5fd912f5fe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 7 deletions

View File

@ -41,7 +41,6 @@
#
import requests
from json import dumps
from base64 import b64encode
from .base import NotifyBase
from ..url import PrivacyMode
@ -89,7 +88,7 @@ class NotifyClickSend(NotifyBase):
# Define object templates
templates = (
'{schema}://{user}:{password}@{targets}',
'{schema}://{user}:{apikey}@{targets}',
)
# Define our template tokens
@ -99,11 +98,12 @@ class NotifyClickSend(NotifyBase):
'type': 'string',
'required': True,
},
'password': {
'name': _('Password'),
'apikey': {
'name': _('API Key'),
'type': 'string',
'private': True,
'required': True,
'map_to': 'password',
},
'target_phone': {
'name': _('Target Phone No'),
@ -124,6 +124,9 @@ class NotifyClickSend(NotifyBase):
'to': {
'alias_of': 'targets',
},
'key': {
'alias_of': 'apikey',
},
'batch': {
'name': _('Batch Mode'),
'type': 'bool',
@ -174,9 +177,6 @@ class NotifyClickSend(NotifyBase):
headers = {
'User-Agent': self.app_id,
'Content-Type': 'application/json; charset=utf-8',
'Authorization': 'Basic {}'.format(
b64encode('{}:{}'.format(
self.user, self.password).encode('utf-8'))),
}
# error tracking (used for function return)
@ -208,6 +208,7 @@ class NotifyClickSend(NotifyBase):
r = requests.post(
self.notify_url,
data=dumps(payload),
auth=(self.user, self.password),
headers=headers,
verify=self.verify_certificate,
timeout=self.request_timeout,
@ -322,6 +323,12 @@ class NotifyClickSend(NotifyBase):
results['batch'] = \
parse_bool(results['qsd'].get('batch', False))
# API Key
if 'key' in results['qsd'] and len(results['qsd']['key']):
# Extract the API Key from an argument
results['password'] = \
NotifyClickSend.unquote(results['qsd']['key'])
# Support the 'to' variable so that we can support rooms this way too
# The 'to' makes it easier to use yaml configuration
if 'to' in results['qsd'] and len(results['qsd']['to']):

View File

@ -62,6 +62,10 @@ apprise_url_tests = (
# valid number - no batch
'instance': NotifyClickSend,
}),
('clicksend://user@{}?batch=no&key=abc123'.format('3' * 14), {
# valid number - no batch
'instance': NotifyClickSend,
}),
('clicksend://user:pass@{}'.format('3' * 14), {
'instance': NotifyClickSend,
# throw a bizzare code forcing us to fail to look it up