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 #608 from mozilla-services/bug/issue-578
Browse files Browse the repository at this point in the history
fix: return 404 for invalid URL's for consistency
  • Loading branch information
bbangert authored Aug 19, 2016
2 parents cf3f197 + f4c47af commit 8391f8a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 22 deletions.
8 changes: 4 additions & 4 deletions autopush/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import datadog
from datadog import ThreadStats
from datadog.util.hostname import get_hostname


class IMetrics(object):
Expand Down Expand Up @@ -70,13 +69,14 @@ def timing(self, name, duration, **kwargs):

class DatadogMetrics(object):
"""DataDog Metric backend"""
def __init__(self, api_key, app_key, flush_interval=10,
def __init__(self, api_key, app_key, hostname, flush_interval=10,
namespace="autopush"):

datadog.initialize(api_key=api_key, app_key=app_key)
datadog.initialize(api_key=api_key, app_key=app_key,
host_name=hostname)
self._client = ThreadStats()
self._flush_interval = flush_interval
self._host = get_hostname()
self._host = hostname
self._namespace = namespace

def _prefix_name(self, name):
Expand Down
24 changes: 13 additions & 11 deletions autopush/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,6 @@ def __init__(self,
pool = HTTPConnectionPool(reactor)
self.agent = Agent(reactor, connectTimeout=5, pool=pool)

# Metrics setup
if datadog_api_key:
self.metrics = DatadogMetrics(
api_key=datadog_api_key,
app_key=datadog_app_key,
flush_interval=datadog_flush_interval
)
elif statsd_host:
self.metrics = TwistedMetrics(statsd_host, statsd_port)
else:
self.metrics = SinkMetrics()
if not crypto_key:
crypto_key = [Fernet.generate_key()]
if not isinstance(crypto_key, list):
Expand All @@ -133,6 +122,19 @@ def __init__(self,
if resolve_hostname:
self.hostname = resolve_ip(self.hostname)

# Metrics setup
if datadog_api_key:
self.metrics = DatadogMetrics(
hostname=self.hostname,
api_key=datadog_api_key,
app_key=datadog_app_key,
flush_interval=datadog_flush_interval,
)
elif statsd_host:
self.metrics = TwistedMetrics(statsd_host, statsd_port)
else:
self.metrics = SinkMetrics()

self.port = port
self.endpoint_hostname = endpoint_hostname or self.hostname
self.router_hostname = router_hostname or self.hostname
Expand Down
2 changes: 1 addition & 1 deletion autopush/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1318,7 +1318,7 @@ def test_with_key(self):

yield client.send_notification(
vapid=vapid,
status=400)
status=404)

yield self.shut_down(client)

Expand Down
7 changes: 3 additions & 4 deletions autopush/tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from nose.tools import ok_, eq_
from mock import Mock, patch

from datadog.util.hostname import get_hostname

from autopush.metrics import (
IMetrics,
DatadogMetrics,
Expand Down Expand Up @@ -52,9 +50,10 @@ def test_basic(self, mock_reactor):
class DatadogMetricsTestCase(unittest.TestCase):
@patch("autopush.metrics.datadog")
def test_basic(self, mock_dog):
hostname = get_hostname()
hostname = "localhost"

m = DatadogMetrics("someapikey", "someappkey", namespace="testpush")
m = DatadogMetrics("someapikey", "someappkey", namespace="testpush",
hostname="localhost")
ok_(len(mock_dog.mock_calls) > 0)
m._client = Mock()
m.start()
Expand Down
2 changes: 1 addition & 1 deletion autopush/web/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def extract_subscription(self, d):
ckey_header=d["ckey_header"],
)
except (InvalidTokenException, InvalidToken):
raise InvalidRequest("invalid token", errno=102)
raise InvalidRequest("invalid token", status_code=404, errno=102)
return result

@validates_schema(skip_on_field_errors=True)
Expand Down
5 changes: 4 additions & 1 deletion docs/http.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ Unless otherwise specified, all calls return the following error codes:
- 400 - Bad Parameters

- errno 101 - Missing neccessary crypto keys
- errno 102 - Invalid URL endpoint
- errno 108 - Router type is invalid
- errno 110 - Invalid crypto keys specified
- errno 111 - Missing Required Header
Expand All @@ -103,6 +102,10 @@ Unless otherwise specified, all calls return the following error codes:

- errno 109 - Invalid authentication

- 404 - Not Found

- errno 102 - Invalid URL endpoint

- 410 - `{UAID}` or `{CHID}` not found

- errno 103 - Expired URL endpoint
Expand Down

0 comments on commit 8391f8a

Please sign in to comment.