| 1 |
# BSD 2-Clause License |
| 2 |
# |
| 3 |
# Apprise - Push Notification Library. |
| 4 |
# Copyright (c) 2026, Chris Caron <[email protected]> |
| 5 |
# |
| 6 |
# Redistribution and use in source and binary forms, with or without |
| 7 |
# modification, are permitted provided that the following conditions are met: |
| 8 |
# |
| 9 |
# 1. Redistributions of source code must retain the above copyright notice, |
| 10 |
# this list of conditions and the following disclaimer. |
| 11 |
# |
| 12 |
# 2. Redistributions in binary form must reproduce the above copyright |
| 13 |
# notice, this list of conditions and the following disclaimer in the |
| 14 |
# documentation and/or other materials provided with the distribution. |
| 15 |
# |
| 16 |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 |
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 |
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 19 |
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 20 |
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 |
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 |
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 23 |
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 24 |
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 25 |
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 26 |
# POSSIBILITY OF SUCH DAMAGE. |
| 27 |
|
| 28 |
# Disable logging for a cleaner testing output |
| 29 |
import logging |
| 30 |
from unittest import mock |
| 31 |
|
| 32 |
from helpers import AppriseURLTester |
| 33 |
import pytest |
| 34 |
import requests |
| 35 |
|
| 36 |
from apprise import Apprise, NotifyType |
| 37 |
from apprise.exception import AppriseImproperlyConfigured |
| 38 |
from apprise.plugins.zoom import ( |
| 39 |
ZOOM_MODE_DEFAULT, |
| 40 |
NotifyZoom, |
| 41 |
ZoomMode, |
| 42 |
) |
| 43 |
|
| 44 |
logging.disable(logging.CRITICAL) |
| 45 |
|
| 46 |
# Reusable test credentials |
| 47 |
WEBHOOK_ID = "abcHook123" |
| 48 |
TOKEN = "xyzVerify456" |
| 49 |
|
| 50 |
# Our Testing URLs |
| 51 |
apprise_url_tests = ( |
| 52 |
# Missing everything |
| 53 |
( |
| 54 |
"zoom://", |
| 55 |
{ |
| 56 |
"instance": AppriseImproperlyConfigured, |
| 57 |
}, |
| 58 |
), |
| 59 |
# Empty user/host segment |
| 60 |
( |
| 61 |
"zoom://:@/", |
| 62 |
{ |
| 63 |
"instance": AppriseImproperlyConfigured, |
| 64 |
}, |
| 65 |
), |
| 66 |
# Missing token (webhook_id present but no path segment) |
| 67 |
( |
| 68 |
"zoom://{}".format(WEBHOOK_ID), |
| 69 |
{ |
| 70 |
"instance": AppriseImproperlyConfigured, |
| 71 |
}, |
| 72 |
), |
| 73 |
# Valid full-mode (default) |
| 74 |
( |
| 75 |
"zoom://{}/{}".format(WEBHOOK_ID, TOKEN), |
| 76 |
{ |
| 77 |
"instance": NotifyZoom, |
| 78 |
"privacy_url": "zoom://a...3/x...6/", |
| 79 |
}, |
| 80 |
), |
| 81 |
# Explicit mode=full |
| 82 |
( |
| 83 |
"zoom://{}/{}?mode=full".format(WEBHOOK_ID, TOKEN), |
| 84 |
{ |
| 85 |
"instance": NotifyZoom, |
| 86 |
"privacy_url": "zoom://a...3/x...6/", |
| 87 |
}, |
| 88 |
), |
| 89 |
# Explicit mode=simple |
| 90 |
( |
| 91 |
"zoom://{}/{}?mode=simple".format(WEBHOOK_ID, TOKEN), |
| 92 |
{ |
| 93 |
"instance": NotifyZoom, |
| 94 |
"privacy_url": "zoom://a...3/x...6/", |
| 95 |
}, |
| 96 |
), |
| 97 |
# Invalid mode |
| 98 |
( |
| 99 |
"zoom://{}/{}?mode=invalid".format(WEBHOOK_ID, TOKEN), |
| 100 |
{ |
| 101 |
"instance": AppriseImproperlyConfigured, |
| 102 |
}, |
| 103 |
), |
| 104 |
# Native URL with ?token= query param |
| 105 |
( |
| 106 |
"https://inbots.zoom.us/incoming/hook/{}?token={}".format( |
| 107 |
WEBHOOK_ID, TOKEN |
| 108 |
), |
| 109 |
{ |
| 110 |
"instance": NotifyZoom, |
| 111 |
}, |
| 112 |
), |
| 113 |
# Full mode: HTTP 500 |
| 114 |
( |
| 115 |
"zoom://{}/{}".format(WEBHOOK_ID, TOKEN), |
| 116 |
{ |
| 117 |
"instance": NotifyZoom, |
| 118 |
"response": False, |
| 119 |
"requests_response_code": (requests.codes.internal_server_error), |
| 120 |
}, |
| 121 |
), |
| 122 |
# Full mode: unusual status code |
| 123 |
( |
| 124 |
"zoom://{}/{}".format(WEBHOOK_ID, TOKEN), |
| 125 |
{ |
| 126 |
"instance": NotifyZoom, |
| 127 |
"response": False, |
| 128 |
"requests_response_code": 999, |
| 129 |
}, |
| 130 |
), |
| 131 |
# Full mode: request exception |
| 132 |
( |
| 133 |
"zoom://{}/{}".format(WEBHOOK_ID, TOKEN), |
| 134 |
{ |
| 135 |
"instance": NotifyZoom, |
| 136 |
"test_requests_exceptions": True, |
| 137 |
}, |
| 138 |
), |
| 139 |
# Simple mode: HTTP 500 |
| 140 |
( |
| 141 |
"zoom://{}/{}?mode=simple".format(WEBHOOK_ID, TOKEN), |
| 142 |
{ |
| 143 |
"instance": NotifyZoom, |
| 144 |
"response": False, |
| 145 |
"requests_response_code": (requests.codes.internal_server_error), |
| 146 |
}, |
| 147 |
), |
| 148 |
# Simple mode: unusual status code |
| 149 |
( |
| 150 |
"zoom://{}/{}?mode=simple".format(WEBHOOK_ID, TOKEN), |
| 151 |
{ |
| 152 |
"instance": NotifyZoom, |
| 153 |
"response": False, |
| 154 |
"requests_response_code": 999, |
| 155 |
}, |
| 156 |
), |
| 157 |
# Simple mode: request exception |
| 158 |
( |
| 159 |
"zoom://{}/{}?mode=simple".format(WEBHOOK_ID, TOKEN), |
| 160 |
{ |
| 161 |
"instance": NotifyZoom, |
| 162 |
"test_requests_exceptions": True, |
| 163 |
}, |
| 164 |
), |
| 165 |
) |
| 166 |
|
| 167 |
|
| 168 |
def test_plugin_zoom_urls(): |
| 169 |
"""NotifyZoom() Apprise URLs.""" |
| 170 |
AppriseURLTester(tests=apprise_url_tests).run_all() |
| 171 |
|
| 172 |
|
| 173 |
def test_plugin_zoom_init(): |
| 174 |
"""Test NotifyZoom initialization and validation.""" |
| 175 |
|
| 176 |
# Missing webhook_id |
| 177 |
with pytest.raises(AppriseImproperlyConfigured): |
| 178 |
NotifyZoom(webhook_id=None, token=TOKEN) |
| 179 |
|
| 180 |
# Empty webhook_id |
| 181 |
with pytest.raises(AppriseImproperlyConfigured): |
| 182 |
NotifyZoom(webhook_id="", token=TOKEN) |
| 183 |
|
| 184 |
# Webhook ID with invalid characters (slash) |
| 185 |
with pytest.raises(AppriseImproperlyConfigured): |
| 186 |
NotifyZoom(webhook_id="bad/id", token=TOKEN) |
| 187 |
|
| 188 |
# Missing token |
| 189 |
with pytest.raises(AppriseImproperlyConfigured): |
| 190 |
NotifyZoom(webhook_id=WEBHOOK_ID, token=None) |
| 191 |
|
| 192 |
# Empty token |
| 193 |
with pytest.raises(AppriseImproperlyConfigured): |
| 194 |
NotifyZoom(webhook_id=WEBHOOK_ID, token="") |
| 195 |
|
| 196 |
# Invalid mode |
| 197 |
with pytest.raises(AppriseImproperlyConfigured): |
| 198 |
NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN, mode="bogus") |
| 199 |
|
| 200 |
# Empty string mode is also invalid (must not silently resolve to simple) |
| 201 |
with pytest.raises(AppriseImproperlyConfigured): |
| 202 |
NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN, mode="") |
| 203 |
|
| 204 |
# Whitespace-only mode is also invalid |
| 205 |
with pytest.raises(AppriseImproperlyConfigured): |
| 206 |
NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN, mode=" ") |
| 207 |
|
| 208 |
# Valid: default mode |
| 209 |
obj = NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN) |
| 210 |
assert obj.mode == ZOOM_MODE_DEFAULT |
| 211 |
|
| 212 |
# Valid: explicit full mode |
| 213 |
obj = NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN, mode="full") |
| 214 |
assert obj.mode == ZoomMode.FULL |
| 215 |
|
| 216 |
# Valid: explicit simple mode |
| 217 |
obj = NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN, mode="simple") |
| 218 |
assert obj.mode == ZoomMode.SIMPLE |
| 219 |
|
| 220 |
# Partial prefix matching: "sim" -> "simple" |
| 221 |
obj = NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN, mode="sim") |
| 222 |
assert obj.mode == ZoomMode.SIMPLE |
| 223 |
|
| 224 |
# Partial prefix matching: "f" -> "full" |
| 225 |
obj = NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN, mode="f") |
| 226 |
assert obj.mode == ZoomMode.FULL |
| 227 |
|
| 228 |
|
| 229 |
def test_plugin_zoom_url_round_trip(): |
| 230 |
"""Verify that url() -> parse_url() -> __init__ is lossless.""" |
| 231 |
|
| 232 |
# Full mode round-trip |
| 233 |
obj1 = NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN, mode="full") |
| 234 |
result = NotifyZoom.parse_url(obj1.url()) |
| 235 |
obj2 = NotifyZoom(**result) |
| 236 |
assert obj1.url_identifier == obj2.url_identifier |
| 237 |
assert obj1.mode == obj2.mode |
| 238 |
|
| 239 |
# Simple mode round-trip |
| 240 |
obj1 = NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN, mode="simple") |
| 241 |
result = NotifyZoom.parse_url(obj1.url()) |
| 242 |
obj2 = NotifyZoom(**result) |
| 243 |
assert obj1.url_identifier == obj2.url_identifier |
| 244 |
assert obj1.mode == obj2.mode |
| 245 |
|
| 246 |
|
| 247 |
def test_plugin_zoom_url_privacy(): |
| 248 |
"""Verify url(privacy=True) masks webhook_id and token.""" |
| 249 |
obj = NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN) |
| 250 |
priv = obj.url(privacy=True) |
| 251 |
assert WEBHOOK_ID not in priv |
| 252 |
assert TOKEN not in priv |
| 253 |
# Schema is still present |
| 254 |
assert priv.startswith("zoom://") |
| 255 |
|
| 256 |
|
| 257 |
def test_plugin_zoom_url_identifier(): |
| 258 |
"""Verify url_identifier contains webhook_id, token, and mode.""" |
| 259 |
obj = NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN) |
| 260 |
uid = obj.url_identifier |
| 261 |
assert "zoom" in uid |
| 262 |
assert WEBHOOK_ID in uid |
| 263 |
assert TOKEN in uid |
| 264 |
|
| 265 |
# Two instances with different tokens are distinct |
| 266 |
obj2 = NotifyZoom(webhook_id=WEBHOOK_ID, token="other") |
| 267 |
assert obj.url_identifier != obj2.url_identifier |
| 268 |
|
| 269 |
# Same credentials but different modes produce different identifiers |
| 270 |
obj_full = NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN, mode="full") |
| 271 |
obj_simple = NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN, mode="simple") |
| 272 |
assert obj_full.url_identifier != obj_simple.url_identifier |
| 273 |
# mode is the 4th element (index 3) of the identifier tuple |
| 274 |
assert obj_full.url_identifier[3] == ZoomMode.FULL |
| 275 |
assert obj_simple.url_identifier[3] == ZoomMode.SIMPLE |
| 276 |
|
| 277 |
|
| 278 |
@mock.patch("requests.post") |
| 279 |
def test_plugin_zoom_full_send(mock_post): |
| 280 |
"""Test _send_full() success and failure paths.""" |
| 281 |
|
| 282 |
def _mk_resp(code=requests.codes.ok): |
| 283 |
r = mock.Mock() |
| 284 |
r.status_code = code |
| 285 |
r.content = b"" |
| 286 |
return r |
| 287 |
|
| 288 |
mock_post.return_value = _mk_resp() |
| 289 |
|
| 290 |
# Success: with title |
| 291 |
obj = NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN) |
| 292 |
assert obj.notify( |
| 293 |
body="body text", |
| 294 |
title="My Title", |
| 295 |
notify_type=NotifyType.INFO, |
| 296 |
) |
| 297 |
assert mock_post.call_count == 1 |
| 298 |
# Verify ?format=full in URL |
| 299 |
call_url = mock_post.call_args[0][0] |
| 300 |
assert "format=full" in call_url |
| 301 |
|
| 302 |
mock_post.reset_mock() |
| 303 |
|
| 304 |
# Success: without title (no head section) |
| 305 |
assert obj.notify( |
| 306 |
body="body only", |
| 307 |
title="", |
| 308 |
notify_type=NotifyType.INFO, |
| 309 |
) |
| 310 |
assert mock_post.call_count == 1 |
| 311 |
|
| 312 |
mock_post.reset_mock() |
| 313 |
|
| 314 |
# HTTP 204 is also a success |
| 315 |
mock_post.return_value = _mk_resp(requests.codes.no_content) |
| 316 |
assert obj.notify(body="test", notify_type=NotifyType.INFO) |
| 317 |
|
| 318 |
mock_post.reset_mock() |
| 319 |
|
| 320 |
# HTTP 500 -> failure |
| 321 |
mock_post.return_value = _mk_resp(requests.codes.internal_server_error) |
| 322 |
assert not obj.notify(body="test", notify_type=NotifyType.INFO) |
| 323 |
|
| 324 |
mock_post.reset_mock() |
| 325 |
|
| 326 |
# Unknown status code -> failure |
| 327 |
mock_post.return_value = _mk_resp(999) |
| 328 |
assert not obj.notify(body="test", notify_type=NotifyType.INFO) |
| 329 |
|
| 330 |
mock_post.reset_mock() |
| 331 |
|
| 332 |
# RequestException -> failure |
| 333 |
mock_post.side_effect = requests.RequestException("boom") |
| 334 |
assert not obj.notify(body="test", notify_type=NotifyType.INFO) |
| 335 |
|
| 336 |
|
| 337 |
@mock.patch("requests.post") |
| 338 |
def test_plugin_zoom_simple_send(mock_post): |
| 339 |
"""Test _send_simple() success and failure paths.""" |
| 340 |
|
| 341 |
def _mk_resp(code=requests.codes.ok): |
| 342 |
r = mock.Mock() |
| 343 |
r.status_code = code |
| 344 |
r.content = b"" |
| 345 |
return r |
| 346 |
|
| 347 |
mock_post.return_value = _mk_resp() |
| 348 |
|
| 349 |
# Create a simple-mode instance |
| 350 |
obj = NotifyZoom(webhook_id=WEBHOOK_ID, token=TOKEN, mode="simple") |
| 351 |
|
| 352 |
# Success: with title (title prepended to body) |
| 353 |
assert obj.notify( |
| 354 |
body="msg body", |
| 355 |
title="Alert", |
| 356 |
notify_type=NotifyType.INFO, |
| 357 |
) |
| 358 |
assert mock_post.call_count == 1 |
| 359 |
# Verify no ?format= in simple mode URL |
| 360 |
call_url = mock_post.call_args[0][0] |
| 361 |
assert "format" not in call_url |
| 362 |
|
| 363 |
mock_post.reset_mock() |
| 364 |
|
| 365 |
# Success: without title |
| 366 |
assert obj.notify( |
| 367 |
body="no title", |
| 368 |
title="", |
| 369 |
notify_type=NotifyType.INFO, |
| 370 |
) |
| 371 |
|
| 372 |
mock_post.reset_mock() |
| 373 |
|
| 374 |
# HTTP 204 is also a success |
| 375 |
mock_post.return_value = _mk_resp(requests.codes.no_content) |
| 376 |
assert obj.notify(body="test", notify_type=NotifyType.INFO) |
| 377 |
|
| 378 |
mock_post.reset_mock() |
| 379 |
|
| 380 |
# HTTP 500 -> failure |
| 381 |
mock_post.return_value = _mk_resp(requests.codes.internal_server_error) |
| 382 |
assert not obj.notify(body="test", notify_type=NotifyType.INFO) |
| 383 |
|
| 384 |
mock_post.reset_mock() |
| 385 |
|
| 386 |
# Unknown status code -> failure |
| 387 |
mock_post.return_value = _mk_resp(999) |
| 388 |
assert not obj.notify(body="test", notify_type=NotifyType.INFO) |
| 389 |
|
| 390 |
mock_post.reset_mock() |
| 391 |
|
| 392 |
# RequestException -> failure |
| 393 |
mock_post.side_effect = requests.RequestException("err") |
| 394 |
assert not obj.notify(body="test", notify_type=NotifyType.INFO) |
| 395 |
|
| 396 |
|
| 397 |
def test_plugin_zoom_parse_url(): |
| 398 |
"""Exercise parse_url() edge cases.""" |
| 399 |
|
| 400 |
# Basic: webhook_id in host, token in path |
| 401 |
result = NotifyZoom.parse_url("zoom://myhookid/mytoken/") |
| 402 |
assert result["webhook_id"] == "myhookid" |
| 403 |
assert result["token"] == "mytoken" |
| 404 |
|
| 405 |
# ?token= override |
| 406 |
result = NotifyZoom.parse_url("zoom://myhookid/?token=override123") |
| 407 |
assert result["webhook_id"] == "myhookid" |
| 408 |
assert result["token"] == "override123" |
| 409 |
|
| 410 |
# ?mode= parameter |
| 411 |
result = NotifyZoom.parse_url("zoom://myhookid/mytoken/?mode=simple") |
| 412 |
assert result["mode"] == "simple" |
| 413 |
|
| 414 |
# A URL that fails base parsing returns None |
| 415 |
result = NotifyZoom.parse_url(None) |
| 416 |
assert result is None |
| 417 |
|
| 418 |
|
| 419 |
def test_plugin_zoom_parse_native_url(): |
| 420 |
"""Exercise parse_native_url().""" |
| 421 |
|
| 422 |
# Native URL with ?token= appended |
| 423 |
result = NotifyZoom.parse_native_url( |
| 424 |
"https://inbots.zoom.us/incoming/hook/{}?token={}".format( |
| 425 |
WEBHOOK_ID, TOKEN |
| 426 |
) |
| 427 |
) |
| 428 |
assert result is not None |
| 429 |
assert result["webhook_id"] == WEBHOOK_ID |
| 430 |
assert result["token"] == TOKEN |
| 431 |
|
| 432 |
# Native URL without token -> parse succeeds but |
| 433 |
# token will be None/missing (instantiation would fail) |
| 434 |
result = NotifyZoom.parse_native_url( |
| 435 |
"https://inbots.zoom.us/incoming/hook/{}".format(WEBHOOK_ID) |
| 436 |
) |
| 437 |
assert result is not None |
| 438 |
assert result["webhook_id"] == WEBHOOK_ID |
| 439 |
|
| 440 |
# Non-matching URL -> None |
| 441 |
assert ( |
| 442 |
NotifyZoom.parse_native_url("https://example.com/not/a/zoom/url") |
| 443 |
is None |
| 444 |
) |
| 445 |
|
| 446 |
|
| 447 |
@mock.patch("requests.post") |
| 448 |
def test_plugin_zoom_apprise_integration(mock_post): |
| 449 |
"""Test end-to-end via Apprise.add() and Apprise.notify().""" |
| 450 |
r = mock.Mock() |
| 451 |
r.status_code = requests.codes.ok |
| 452 |
r.content = b"" |
| 453 |
mock_post.return_value = r |
| 454 |
|
| 455 |
app = Apprise() |
| 456 |
assert app.add("zoom://{}/{}".format(WEBHOOK_ID, TOKEN)) |
| 457 |
assert app.notify(title="Hello", body="World") |
| 458 |
assert mock_post.call_count == 1 |