Skip to content

Commit 4f5f944

Browse files
authored
fix(views): make sure domain is set it in cert attach operation (#1046)
Made it so a user can pass /v2/apps/foo/domains/thing.com or pass {domain: thing.com} as the body This works because DELETE uses the former format and POST (including SDK) use the latter but the URL format supports POST doing both... Should probably drop the body element at some point
1 parent f10d0a3 commit 4f5f944

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

rootfs/api/tests/test_certificate_use_case_1.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ def test_get_certificate_screens_data(self):
9292
)
9393
self.assertEqual(response.status_code, 201, response.data)
9494

95+
# Attach domain to cert but post no body
96+
response = self.client.post(
97+
'{}/{}/domain/'.format(self.url, self.name),
98+
{}
99+
)
100+
self.assertEqual(response.status_code, 400, response.data)
101+
self.assertEqual(response.data, {'detail': 'domain is a required field'})
102+
95103
# Assert data
96104
response = self.client.get('{}/{}'.format(self.url, self.name))
97105
self.assertEqual(response.status_code, 200, response.data)

rootfs/api/views.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,11 @@ def get_object(self, **kwargs):
361361

362362
def attach(self, request, *args, **kwargs):
363363
try:
364-
# TODO how to validate domain is set in the body?
365-
kwargs['domain'] = request.data['domain']
364+
if kwargs['domain'] is None and not request.data.get('domain'):
365+
raise DeisException("domain is a required field")
366+
elif request.data.get('domain'):
367+
kwargs['domain'] = request.data['domain']
368+
366369
self.get_object().attach(*args, **kwargs)
367370
except Http404:
368371
raise

0 commit comments

Comments
 (0)