From 6c7fa53990817f6ca4fc8ae443f58070e68f73bc Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Fri, 5 Feb 2016 14:42:35 -0800 Subject: [PATCH 1/2] Ensure there are no periods in the service name --- nomad/structs/structs.go | 7 +++++++ nomad/structs/structs_test.go | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index f2e5e356b58..c9635c6dd81 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -1414,6 +1414,13 @@ func (s *Service) InitFields(job string, taskGroup string, task string) { // Validate checks if the Check definition is valid func (s *Service) Validate() error { var mErr multierror.Error + + // Ensure the name does not have a period in it. + // RFC-2782: https://tools.ietf.org/html/rfc2782 + if strings.Contains(s.Name, ".") { + mErr.Errors = append(mErr.Errors, fmt.Errorf("service name can't contain periods: %q", s.Name)) + } + for _, c := range s.Checks { if err := c.Validate(); err != nil { mErr.Errors = append(mErr.Errors, err) diff --git a/nomad/structs/structs_test.go b/nomad/structs/structs_test.go index 076456c0892..dfdeea82830 100644 --- a/nomad/structs/structs_test.go +++ b/nomad/structs/structs_test.go @@ -485,6 +485,14 @@ func TestInvalidServiceCheck(t *testing.T) { if err := s.Validate(); err == nil { t.Fatalf("Service should be invalid") } + + s = Service{ + Name: "service.name", + PortLabel: "bar", + } + if err := s.Validate(); err != nil { + t.Fatalf("Service should be invalid: %v", err) + } } func TestDistinctCheckID(t *testing.T) { From 7d3be2bba29139fce326417f19d6ca88bcc873c4 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Fri, 5 Feb 2016 15:15:56 -0800 Subject: [PATCH 2/2] Fix == --- nomad/structs/structs_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nomad/structs/structs_test.go b/nomad/structs/structs_test.go index dfdeea82830..dfbca2ad1cc 100644 --- a/nomad/structs/structs_test.go +++ b/nomad/structs/structs_test.go @@ -490,7 +490,7 @@ func TestInvalidServiceCheck(t *testing.T) { Name: "service.name", PortLabel: "bar", } - if err := s.Validate(); err != nil { + if err := s.Validate(); err == nil { t.Fatalf("Service should be invalid: %v", err) } }