Skip to content
This repository was archived by the owner on May 6, 2020. It is now read-only.

fix(serializers.py): update PROCTYPE_MATCH to disallow uppercase characters #1261

Merged
merged 5 commits into from
Mar 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions rootfs/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@

from api import models

# proc type name is alphanumeric
# proc type name is lowercase alphanumeric
# https://docs-v2.readthedocs.io/en/latest/using-workflow/process-types-and-the-procfile/#declaring-process-types
PROCTYPE_MATCH = re.compile(r'^(?P<type>[a-zA-Z0-9]+(\-[a-zA-Z0-9]+)*)$')
PROCTYPE_MATCH = re.compile(r'^(?P<type>[a-z0-9]+(\-[a-z0-9]+)*)$')
PROCTYPE_MISMATCH_MSG = "Process types can only contain lowercase alphanumeric characters"
MEMLIMIT_MATCH = re.compile(
r'^(?P<mem>(([0-9]+(MB|KB|GB|[BKMG])|0)(/([0-9]+(MB|KB|GB|[BKMG])))?))$', re.IGNORECASE)
CPUSHARE_MATCH = re.compile(
Expand Down Expand Up @@ -197,7 +198,7 @@ def validate_procfile(self, data):
raise serializers.ValidationError("Command can't be empty for process type")

if not re.match(PROCTYPE_MATCH, key):
raise serializers.ValidationError("Process types can only contain alphanumeric")
raise serializers.ValidationError(PROCTYPE_MISMATCH_MSG)

return data

Expand Down Expand Up @@ -271,7 +272,7 @@ def validate_memory(self, data):
continue

if not re.match(PROCTYPE_MATCH, key):
raise serializers.ValidationError("Process types can only contain alphanumeric")
raise serializers.ValidationError(PROCTYPE_MISMATCH_MSG)

if not re.match(MEMLIMIT_MATCH, str(value)):
raise serializers.ValidationError(
Expand All @@ -286,7 +287,7 @@ def validate_cpu(self, data):
continue

if not re.match(PROCTYPE_MATCH, key):
raise serializers.ValidationError("Process types can only contain alphanumeric")
raise serializers.ValidationError(PROCTYPE_MISMATCH_MSG)

shares = re.match(CPUSHARE_MATCH, str(value))
if not shares:
Expand Down
14 changes: 13 additions & 1 deletion rootfs/api/tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,18 @@ def test_build_validate_procfile(self, mock_requests):
response = self.client.post(url, body)
self.assertEqual(response.status_code, 400, response.data)

url = "/v2/apps/{app_id}/builds".format(**locals())
body = {
'image': 'autotest/example',
'sha': 'a'*40,
'procfile': {
'web': 'node server.js',
'Worker-test1': 'node worker.js'
}
}
response = self.client.post(url, body)
self.assertEqual(response.status_code, 400, response.data)

url = "/v2/apps/{app_id}/builds".format(**locals())
body = {
'image': 'autotest/example',
Expand Down Expand Up @@ -767,7 +779,7 @@ def test_build_validate_procfile(self, mock_requests):
'sha': 'a'*40,
'procfile': {
'web': 'node server.js',
'Worker-test1': 'node worker.js'
'worker-test1': 'node worker.js'
}
}
response = self.client.post(url, body)
Expand Down