Skip to content

Commit 1381fe0

Browse files
committed
Merge pull request #254 from opdemand/fix-id-override
Only allow App ID's that are valid DNS hostnames
2 parents c9127c1 + 94d714d commit 1381fe0

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

api/serializers.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
from __future__ import unicode_literals
77

8+
import re
9+
810
from django.contrib.auth.models import User
911
from rest_framework import serializers
1012

@@ -165,6 +167,16 @@ class Meta:
165167
model = models.App
166168
read_only_fields = ('created', 'updated')
167169

170+
def validate_id(self, attrs, source):
171+
"""
172+
Check that the ID is all lowercase
173+
"""
174+
value = attrs[source]
175+
match = re.match(r'^[a-z0-9-]+$', value)
176+
if not match:
177+
raise serializers.ValidationError("App IDs can only contain [a-z0-9-]")
178+
return attrs
179+
168180

169181
class ContainerSerializer(serializers.ModelSerializer):
170182
"""Serialize a :class:`~api.models.Container` model."""

api/tests/app.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ def test_app_actions(self):
185185
def test_app_errors(self):
186186
formation_id, app_id = 'autotest', 'autotest-errors'
187187
url = '/api/apps'
188+
body = {'formation': formation_id, 'id': 'camelCase'}
189+
response = self.client.post(url, json.dumps(body), content_type='application/json')
190+
self.assertContains(response, 'App IDs can only contain [a-z0-9-]', status_code=400)
188191
body = {'formation': formation_id, 'id': app_id}
189192
response = self.client.post(url, json.dumps(body), content_type='application/json')
190193
self.assertEqual(response.status_code, 201)

client/deis.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,11 @@ def apps_create(self, args):
399399
progress.join()
400400
if response.status_code == requests.codes.created: # @UndefinedVariable
401401
data = response.json()
402-
formation = data['id']
403-
print("done, created {}".format(formation))
402+
app_id = data['id']
403+
print("done, created {}".format(app_id))
404404
# add a git remote
405405
hostname = urlparse.urlparse(self._settings['controller']).netloc
406-
git_remote = "git@{hostname}:{formation}.git".format(**locals())
406+
git_remote = "git@{hostname}:{app_id}.git".format(**locals())
407407
try:
408408
subprocess.check_call(
409409
['git', 'remote', 'add', '-f', 'deis', git_remote],

0 commit comments

Comments
 (0)