From d58d273775be1ac9879d1938d80e8695fad41b73 Mon Sep 17 00:00:00 2001 From: Matthew Sandoval Date: Fri, 13 Dec 2024 04:22:10 -0800 Subject: [PATCH] Add ":" as acceptable char for node ID (#1242) --- .../user_guide/configuration_options.rst | 2 +- pkg/types/main.go | 4 +- pkg/types/main_test.go | 39 +++++++++++++++++++ pkg/workceptor/command_test.go | 2 - 4 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 pkg/types/main_test.go diff --git a/docs/source/user_guide/configuration_options.rst b/docs/source/user_guide/configuration_options.rst index 2d9cfce79..4e32b6867 100644 --- a/docs/source/user_guide/configuration_options.rst +++ b/docs/source/user_guide/configuration_options.rst @@ -130,7 +130,7 @@ Node - Default value - Type * - ``id`` - - Node ID can only contain a-z, A-Z, 0-9 or special characters . - _ @ + - Node ID can only contain a-z, A-Z, 0-9 or special characters . - _ @ : - local hostname - string * - ``datadir`` diff --git a/pkg/types/main.go b/pkg/types/main.go index 44a09a36b..a3956d1d6 100644 --- a/pkg/types/main.go +++ b/pkg/types/main.go @@ -36,10 +36,10 @@ func (cfg NodeCfg) Init() error { } cfg.ID = host } else { - submitIDRegex := regexp.MustCompile(`^[.\-_@a-zA-Z0-9]*$`) + submitIDRegex := regexp.MustCompile(`^[.\-_@:a-zA-Z0-9]*$`) match := submitIDRegex.FindSubmatch([]byte(cfg.ID)) if match == nil { - return fmt.Errorf("node id can only contain a-z, A-Z, 0-9 or special characters . - _ @ but received: %s", cfg.ID) + return fmt.Errorf("node id can only contain a-z, A-Z, 0-9 or special characters . - _ @ : but received: %s", cfg.ID) } } if strings.ToLower(cfg.ID) == "localhost" { diff --git a/pkg/types/main_test.go b/pkg/types/main_test.go new file mode 100644 index 000000000..1d82b1c6d --- /dev/null +++ b/pkg/types/main_test.go @@ -0,0 +1,39 @@ +package types + +import "testing" + +func TestMainInitNodeID(t *testing.T) { + mainInitNodeIDTestCases := []struct { + name string + nodeID string + expectedErr string + }{ + { + name: "successful, no error", + nodeID: "t.e-s_t@1:234", + expectedErr: "", + }, + { + name: "failed, charactered not allowed", + nodeID: "test!#&123", + expectedErr: "node id can only contain a-z, A-Z, 0-9 or special characters . - _ @ : but received: test!#&123", + }, + } + + for _, testCase := range mainInitNodeIDTestCases { + t.Run(testCase.name, func(t *testing.T) { + cfg := NodeCfg{ + ID: testCase.nodeID, + } + err := cfg.Init() + if err == nil && testCase.expectedErr != "" { + t.Errorf("exected error but got no error") + } else if err != nil && err.Error() != testCase.expectedErr { + t.Errorf("expected error to be %s, but got: %s", testCase.expectedErr, err.Error()) + } + t.Cleanup(func() { + cfg = NodeCfg{} + }) + }) + } +} diff --git a/pkg/workceptor/command_test.go b/pkg/workceptor/command_test.go index 985bbd96f..b433b3973 100644 --- a/pkg/workceptor/command_test.go +++ b/pkg/workceptor/command_test.go @@ -89,7 +89,6 @@ func TestCommandSetFromParams(t *testing.T) { } func TestUnredactedStatus(t *testing.T) { - t.Parallel() wu, mockBaseWorkUnit, _, _ := createCommandTestSetup(t) restartTestCases := []struct { name string @@ -101,7 +100,6 @@ func TestUnredactedStatus(t *testing.T) { statusLock := &sync.RWMutex{} for _, testCase := range restartTestCases { t.Run(testCase.name, func(t *testing.T) { - t.Parallel() mockBaseWorkUnit.EXPECT().GetStatusLock().Return(statusLock).Times(2) mockBaseWorkUnit.EXPECT().GetStatusWithoutExtraData().Return(&workceptor.StatusFileData{}) mockBaseWorkUnit.EXPECT().GetStatusCopy().Return(workceptor.StatusFileData{