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

Commit

Permalink
Merge pull request #858 from mozilla-services/bug/857
Browse files Browse the repository at this point in the history
bug: Fixes for missing UAID and header values
  • Loading branch information
jrconlin authored Apr 3, 2017
2 parents 987f31d + defb331 commit 76f772e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion autopush/router/apnsrouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def register(self, uaid, router_data, app_id, *args, **kwargs):
status_code=400,
response_body="Unknown release channel")
if not router_data.get("token"):
raise RouterException("No token registered", status_code=500,
raise RouterException("No token registered", status_code=400,
response_body="No token registered")
router_data["rel_channel"] = app_id
return router_data
Expand Down
12 changes: 12 additions & 0 deletions autopush/tests/test_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,3 +879,15 @@ def handle_finish(value):
router_token="test",
uaid=dummy_uaid.hex))
return self.finish_deferred

def test_get_no_uaid(self):
self.reg.request.headers['Authorization'] = self.auth

def handle_finish(value):
self.status_mock.assert_called_with(410, reason=None)

self.finish_deferred.addCallback(handle_finish)
self.reg.get(self._make_req(
router_type="test",
router_token="test"))
return self.finish_deferred
3 changes: 2 additions & 1 deletion autopush/web/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ def _boto_err(self, fail):

def _router_response(self, response):
for name, val in response.headers.items():
self.set_header(name, val)
if val is not None:
self.set_header(name, val)

if 200 <= response.status_code < 300:
self.set_status(response.status_code, reason=None)
Expand Down
11 changes: 8 additions & 3 deletions autopush/web/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ def _register_channel(self, router_data=None):
self.app_server_key)
return endpoint, router_data

def _check_uaid(self, uaid):
if not uaid or uaid == 'None':
raise ItemNotFound("UAID not found")
return uaid

@threaded_validate(RegistrationSchema)
def get(self, *args, **kwargs):
"""HTTP GET
Expand All @@ -235,11 +240,11 @@ def get(self, *args, **kwargs):
"""
self.uaid = self.valid_input['uaid']
self.add_header("Content-Type", "application/json")
d = deferToThread(self.ap_settings.message.all_channels,
str(self.uaid))
d = deferToThread(self._check_uaid, str(self.uaid))
d.addCallback(self.ap_settings.message.all_channels)
d.addCallback(self._write_channels)
d.addErrback(self._response_err)
d.addErrback(self._uaid_not_found_err)
d.addErrback(self._response_err)
return d

@threaded_validate(RegistrationSchema)
Expand Down

0 comments on commit 76f772e

Please sign in to comment.