Skip to content

Commit

Permalink
Prevent non-lowercase client names (#128)
Browse files Browse the repository at this point in the history
We're using Azure storage blob containers under the hood to map clients
to their state. Containers are created as lower-case so the client names
should also be lower-case.
  • Loading branch information
c-w authored Feb 4, 2019
1 parent bcbaae5 commit 919e233
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions opwen_email_server/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from opwen_email_server.utils.serialization import from_jsonl_bytes
from opwen_email_server.utils.serialization import to_base64
from opwen_email_server.utils.serialization import to_jsonl_bytes
from opwen_email_server.utils.string import is_lowercase

Response = Union[dict, Tuple[str, int]]

Expand Down Expand Up @@ -283,6 +284,8 @@ def __init__(self,

def _action(self, client): # type: ignore
domain = client['domain']
if not is_lowercase(domain):
return 'domain must be lowercase', 400
if self._auth.client_id_for(domain) is not None:
return 'client already exists', 409

Expand Down
2 changes: 2 additions & 0 deletions opwen_email_server/utils/string.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def is_lowercase(string: str) -> bool:
return string.lower() == string
7 changes: 7 additions & 0 deletions tests/opwen_email_server/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,13 @@ def setUp(self):
self.setup_mx_records = MagicMock()
self.client_id_source = MagicMock()

def test_400(self):
domain = 'TEST.com'

_, status = self._execute_action({'domain': domain})

self.assertEqual(status, 400)

def test_409(self):
domain = 'test.com'

Expand Down
11 changes: 11 additions & 0 deletions tests/opwen_email_server/utils/test_string.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from unittest import TestCase

from opwen_email_server.utils.string import is_lowercase


class IsLowercaseTests(TestCase):
def test_lowercase(self):
self.assertTrue(is_lowercase('foo'))

def test_uppercase(self):
self.assertFalse(is_lowercase('FoO'))

0 comments on commit 919e233

Please sign in to comment.