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

feat: Support app server keys via the HTTP interface #443

Merged
merged 1 commit into from Apr 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion autopush/endpoint.py
Expand Up @@ -616,6 +616,7 @@ def post(self, router_type="", router_token="", uaid="", chid=""):
# Should this be different than websocket?
self.uaid = uaid
self.chid = params["channelID"]
self.app_server_key = params.get("key")
if new_uaid:
d = Deferred()
d.addCallback(router.register, params, router_token)
Expand Down Expand Up @@ -681,7 +682,8 @@ def _delete_uaid(self, uaid, router):

def _register_channel(self, router_data=None):
self.ap_settings.message.register_channel(self.uaid, self.chid)
endpoint = self.ap_settings.make_endpoint(self.uaid, self.chid)
endpoint = self.ap_settings.make_endpoint(self.uaid, self.chid,
self.app_server_key)
return endpoint, router_data

@cyclone.web.asynchronous
Expand Down
40 changes: 40 additions & 0 deletions autopush/tests/test_endpoint.py
Expand Up @@ -1615,6 +1615,46 @@ def handle_finish(value):
self.reg.post(router_type="simplepush", uaid=dummy_uaid)
return self.finish_deferred

@patch('uuid.uuid4', return_value=uuid.UUID(dummy_chid))
def test_post_with_app_server_key(self, *args):
dummy_key = "RandomKeyString"
self.reg.request.body = json.dumps(dict(
type="simplepush",
key=utils.base64url_encode(dummy_key),
data={},
))

def mock_encrypt(cleartext):
eq_(len(cleartext), 64)
# dummy_uaid
eq_(cleartext[0:16],
'abad1dea00000000aabbccdd00000000'.decode('hex'))
# dummy_chid
eq_(cleartext[16:32],
'deadbeef00000000decafbad00000000'.decode('hex'))
# sha256(dummy_key).digest()
eq_(cleartext[32:],
('47aedd050b9e19171f0fa7b8b65ca670'
'28f0bc92cd3f2cd3682b1200ec759007').decode('hex'))
return 'abcd123'
self.fernet_mock.configure_mock(**{
'encrypt.side_effect': mock_encrypt,
})
self.reg.request.headers["Authorization"] = self.auth

def handle_finish(value):
call_args = self.reg.write.call_args
ok_(call_args is not None)
args = call_args[0]
call_arg = json.loads(args[0])
eq_(call_arg["channelID"], dummy_chid)
eq_(call_arg["endpoint"], "http://localhost/push/v2/abcd123")

self.finish_deferred.addCallback(handle_finish)
self.reg.request.headers["Authorization"] = self.auth
self.reg.post(router_type="simplepush", uaid=dummy_uaid)
return self.finish_deferred

@patch('uuid.uuid4', return_value=uuid.UUID(dummy_chid))
def test_put(self, *args):
data = dict(token="some_token")
Expand Down