Rate limit public registration writes
This commit is contained in:
parent
cccca324c1
commit
b80de5a1f4
6 changed files with 129 additions and 1 deletions
|
|
@ -2,6 +2,7 @@ import io
|
|||
import json
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
from urllib.error import HTTPError
|
||||
|
||||
from user_engine.adapters.registration_verification import (
|
||||
HTTPRegistrationVerificationAdapter,
|
||||
|
|
@ -66,3 +67,22 @@ class RegistrationVerificationAdapterTests(unittest.TestCase):
|
|||
)
|
||||
with self.assertRaisesRegex(RuntimeError, "wrong purpose"):
|
||||
adapter.consume("x" * 32)
|
||||
|
||||
@patch("user_engine.adapters.registration_verification.urlopen")
|
||||
def test_expired_and_replayed_handles_have_the_same_redacted_failure(self, opener):
|
||||
adapter = HTTPRegistrationVerificationAdapter(
|
||||
base_url="http://verification", bearer_token="secret"
|
||||
)
|
||||
messages = []
|
||||
for status in (409, 410):
|
||||
opener.side_effect = HTTPError(
|
||||
"http://verification/consume", status, "provider detail", {},
|
||||
io.BytesIO(b'{"error":"account-specific detail"}'),
|
||||
)
|
||||
with self.assertRaises(RuntimeError) as raised:
|
||||
adapter.consume("x" * 32)
|
||||
messages.append(str(raised.exception))
|
||||
self.assertEqual(
|
||||
["registration verification was rejected"] * 2, messages
|
||||
)
|
||||
self.assertNotIn("account-specific", repr(messages))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue