File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55
66from __future__ import unicode_literals
77
8+ import re
9+
810from django .contrib .auth .models import User
911from 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
169181class ContainerSerializer (serializers .ModelSerializer ):
170182 """Serialize a :class:`~api.models.Container` model."""
Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments