Skip to content

Commit

Permalink
Added validation of channel id
Browse files Browse the repository at this point in the history
  • Loading branch information
dsbilling committed Sep 15, 2023
1 parent 50bb1ec commit 3e82961
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion oppe/oppe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import requests

from oppe.config import Config
from oppe.utils import request_header
from oppe.utils import request_header, validate_uuid


class Oppe:
Expand Down Expand Up @@ -47,6 +47,8 @@ def event(self, channel_id, title, description=None, emoji=None, data=None):
:return: True if the event was triggered successfully, False otherwise.
:rtype: bool
"""
if not validate_uuid(uuid_input=channel_id):
raise ValueError('Channel ID must be a valid UUID')
data = {
'channel_id': channel_id,
'title': title,
Expand Down
6 changes: 4 additions & 2 deletions tests/test_oppe.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,7 @@ def test_publish_event_with_no_description():
def test_publish_event_with_wrong_channel_id():
""" Test publish event with wrong channel id """
oppe = init_oppe()
response = oppe.event(channel_id=fake.sha256(), title=fake.domain_word(), description=fake.sentence())
assert response is False
try:
oppe.event(channel_id=fake.sha256(), title=fake.domain_word())
except ValueError as e:
assert str(e) == 'Channel ID must be a valid UUID'

0 comments on commit 3e82961

Please sign in to comment.