Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ":" as acceptable char for node ID #1242

Merged
merged 4 commits into from
Dec 13, 2024
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
2 changes: 1 addition & 1 deletion docs/source/user_guide/configuration_options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``
Expand Down
4 changes: 2 additions & 2 deletions pkg/types/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
39 changes: 39 additions & 0 deletions pkg/types/main_test.go
Original file line number Diff line number Diff line change
@@ -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{}
})
})
}
}
2 changes: 0 additions & 2 deletions pkg/workceptor/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ func TestCommandSetFromParams(t *testing.T) {
}

func TestUnredactedStatus(t *testing.T) {
t.Parallel()
wu, mockBaseWorkUnit, _, _ := createCommandTestSetup(t)
restartTestCases := []struct {
name string
Expand All @@ -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{
Expand Down
Loading