Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
fix: hasher doesn't take UUIDs
Browse files Browse the repository at this point in the history
and fix ChannelRegistrationHandler now taking a UUID chid after the
last refactor and some type sigs

Closes #984
  • Loading branch information
pjenvey committed Jul 27, 2017
1 parent 8921df7 commit 69b91de
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
10 changes: 7 additions & 3 deletions autopush/web/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
from boto.dynamodb2.exceptions import ProvisionedThroughputExceededException
from boto.exception import BotoServerError
from marshmallow.schema import UnmarshalResult # noqa
from typing import Any, Callable # noqa
from typing import ( # noqa
Any,
Callable,
Sequence
)
from twisted.internet.threads import deferToThread
from twisted.logger import Logger

Expand Down Expand Up @@ -142,8 +146,8 @@ def data_length(self):
class BaseWebHandler(BaseHandler):
"""Common overrides for Push web API's"""
cors_methods = ""
cors_request_headers = ()
cors_response_headers = ()
cors_request_headers = () # type: Sequence[str]
cors_response_headers = () # type: Sequence[str]

#############################################################
# Cyclone API Methods
Expand Down
17 changes: 8 additions & 9 deletions autopush/web/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@ class PathUUID(fields.Field):
throw a 404"""
def _deserialize(self, value, attr, data):
try:
new_uuid = uuid.UUID(value)
return uuid.UUID(value)
except ValueError:
raise InvalidRequest("Invalid Path", status_code=404)
else:
return new_uuid


#############################################################
Expand Down Expand Up @@ -317,7 +315,7 @@ def _write_endpoint(self, endpoint, uaid, chid, router_type, router_data,
self.log.info("Register",
client_info=self._client_info,
endpoint=endpoint,
uaid_hash=hasher(uaid))
uaid_hash=hasher(uaid.hex))
self.finish()

def _success(self, result):
Expand Down Expand Up @@ -355,7 +353,7 @@ def post(self, router_type, router_data):
return d

def _register_user_and_channel(self, uaid, chid, router_type, router_data):
# type: (uuid.UUID, str, str, JSONDict, Optional[str]) -> str
# type: (uuid.UUID, str, str, JSONDict) -> str
"""Register a new user/channel, return its endpoint"""
self._register_user(uaid, router_type, router_data)
return self._register_channel(uaid, chid, router_data.get("key"))
Expand Down Expand Up @@ -455,7 +453,7 @@ class ChannelRegistrationHandler(BaseRegistrationHandler):

@threaded_validate(UnregisterChidSchema)
def delete(self, uaid, chid):
# type: (uuid.UUID, str) -> Deferred
# type: (uuid.UUID, uuid.UUID) -> Deferred
self.metrics.increment("ua.command.unregister",
tags=self.base_tags())
d = deferToThread(self._delete_channel, uaid, chid)
Expand All @@ -465,12 +463,13 @@ def delete(self, uaid, chid):
return d

def _delete_channel(self, uaid, chid):
if not self.db.message.unregister_channel(uaid.hex, chid):
# type: (uuid.UUID, uuid.UUID) -> None
if not self.db.message.unregister_channel(uaid.hex, chid.hex):
raise ItemNotFound("ChannelID not found")
self.log.info("Unregister",
client_info=self._client_info,
channel_id=chid,
uaid_hash=hasher(uaid))
channel_id=chid.hex,
uaid_hash=hasher(uaid.hex))

def _chid_not_found_err(self, fail):
"""errBack for unknown chid"""
Expand Down
3 changes: 2 additions & 1 deletion autopush/web/webpush.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
InvalidTokenException,
VapidAuthException,
)
from autopush.types import JSONDict # noqa
from autopush.utils import (
base64url_encode,
extract_jwt,
Expand Down Expand Up @@ -459,7 +460,7 @@ def initialize(self):
def post(self,
subscription, # type: Dict[str, Any]
notification, # type: WebPushNotification
jwt=None, # type: Optional[Dict[str, str]]
jwt=None, # type: Optional[JSONDict]
**kwargs # type: Any
):
# type: (...) -> Deferred
Expand Down

0 comments on commit 69b91de

Please sign in to comment.