From d4ef12e42ebfde8575caa86e8b649cf0d6fcb2e5 Mon Sep 17 00:00:00 2001 From: Chris Baker <1675087+cgbaker@users.noreply.github.com> Date: Sat, 3 Oct 2020 21:46:58 +0000 Subject: [PATCH] documenting tests around null characters in job id, task group name, and task name --- nomad/structs/structs_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/nomad/structs/structs_test.go b/nomad/structs/structs_test.go index 942710db7..0c721cd31 100644 --- a/nomad/structs/structs_test.go +++ b/nomad/structs/structs_test.go @@ -170,6 +170,25 @@ func TestJob_ValidateScaling(t *testing.T) { require.Contains(mErr.Errors[0].Error(), "task group count must not be less than minimum count in scaling policy") } +func TestJob_ValidateNullChar(t *testing.T) { + assert := assert.New(t) + + // job id should not allow null characters + job := testJob() + job.ID = "id_with\000null_character" + assert.Error(job.Validate(), "null character in job ID should not validate") + + // task group name should not allow null characters + job.ID = "happy_little_job_id" + job.TaskGroups[0].Name = "oh_no_another_\000_char" + assert.Error(job.Validate(), "null character in task group name should not validate") + + // task name should not allow null characters + job.TaskGroups[0].Name = "so_much_better" + job.TaskGroups[0].Tasks[0].Name = "what_is_with_these_\000_chars" + assert.Error(job.Validate(), "null character in task name should not validate") +} + func TestJob_Warnings(t *testing.T) { cases := []struct { Name string