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

bug: return 201 for all push subscription requests. #1446

Merged
merged 2 commits into from
Dec 3, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions autopush/router/webpush.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,14 @@ def stored_response(self, notification):
notification.data_length,
tags=make_tags(destination='Stored'))
location = "%s/m/%s" % (self.conf.endpoint_url, notification.location)
return RouterResponse(status_code=202, response_body="",
# RFC https://tools.ietf.org/html/rfc8030#section-5
# all responses should be 201, unless this is a push reciept request,
# which requires a 202 and a URL that can be checked later for UA
# acknowledgement. (We don't support that yet. See autopush-rs#244)
return RouterResponse(status_code=201, response_body="",
headers={"Location": location,
"TTL": notification.ttl},
logged_status=202)
logged_status=201)

#############################################################
# Blocking Helper Functions
Expand Down
9 changes: 5 additions & 4 deletions autopush/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ def send_notification(self, channel=None, version=None, data=None,
headers["Topic"] = topic
body = data or ""
method = "POST"
status = status or (201 if self.ws and self.ws.connected else 202)
# 202 status reserved for yet to be implemented push w/ reciept.
status = status or 201

log.debug("%s body: %s", method, body)
http.request(method, url.path.encode("utf-8"), body, headers)
Expand All @@ -246,7 +247,7 @@ def send_notification(self, channel=None, version=None, data=None,
if status == 201 and ttl is not None:
ttl_header = resp.getheader("TTL")
assert ttl_header == str(ttl)
if ttl != 0 and status == 202:
if ttl != 0 and status == 201:
assert location is not None
if channel in self.messages:
self.messages[channel].append(location)
Expand Down Expand Up @@ -535,7 +536,7 @@ def test_legacy_simplepush_record(self):
'current_month': self.ep.db.current_msg_month})
safe = db.Message.all_channels
db.Message.all_channels = Mock(return_value=(True, client.channels))
yield client.send_notification(status=202)
yield client.send_notification(status=201)
db.Message.all_channels = safe
yield self.shut_down(client)

Expand Down Expand Up @@ -601,7 +602,7 @@ def test_webpush_data_save_fail(self):
return_value=False)
yield client.send_notification(channel=chan,
data=test["data"],
status=202)
status=201)
db.Message.store_message = safe
yield self.shut_down(client)

Expand Down
9 changes: 5 additions & 4 deletions autopush/tests/test_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,8 @@ def test_route_failure(self):

def verify_deliver(result):
assert isinstance(result, RouterResponse)
assert result.status_code == 202
# https://tools.ietf.org/html/rfc8030#section-5
assert result.status_code == 201
kwargs = self.message_mock.store_message.call_args[1]
assert len(self.metrics.increment.mock_calls) == 3
t_h = kwargs["notification"].headers
Expand Down Expand Up @@ -1585,7 +1586,7 @@ def throw():
d = self.router.route_notification(self.notif, router_data)

def verify_deliver(status):
assert status.status_code == 202
assert status.status_code == 201
d.addBoth(verify_deliver)

return d
Expand Down Expand Up @@ -1621,7 +1622,7 @@ def test_route_lookup_uaid_no_nodeid(self):
d = self.router.route_notification(self.notif, router_data)

def verify_deliver(status):
assert status.status_code == 202
assert status.status_code == 201
d.addBoth(verify_deliver)

return d
Expand All @@ -1648,7 +1649,7 @@ def throw():

def verify_deliver(result):
assert isinstance(result, RouterResponse)
assert result.status_code == 202
assert result.status_code == 201
kwargs = self.message_mock.store_message.call_args[1]
assert len(self.metrics.increment.mock_calls) == 3
t_h = kwargs["notification"].headers
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ configargparse==1.0
configparser==4.0.2 # via datadog
constantly==15.1.0 # via twisted
contextlib2==0.6.0.post1 # via raven
cryptography==2.8
cryptography==3.2
cyclone==1.2
datadog==0.37.1
decorator==4.4.1 # via datadog
Expand Down