Skip to content

Commit 5b3de7e

Browse files
committed
Add ":" as acceptable char for node ID
1 parent ad9c4eb commit 5b3de7e

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

docs/source/user_guide/configuration_options.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ Node
130130
- Default value
131131
- Type
132132
* - ``id``
133-
- Node ID can only contain a-z, A-Z, 0-9 or special characters . - _ @
133+
- Node ID can only contain a-z, A-Z, 0-9 or special characters . - _ @ :
134134
- local hostname
135135
- string
136136
* - ``datadir``

pkg/types/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ func (cfg NodeCfg) Init() error {
3636
}
3737
cfg.ID = host
3838
} else {
39-
submitIDRegex := regexp.MustCompile(`^[.\-_@a-zA-Z0-9]*$`)
39+
submitIDRegex := regexp.MustCompile(`^[.\-_@:a-zA-Z0-9]*$`)
4040
match := submitIDRegex.FindSubmatch([]byte(cfg.ID))
4141
if match == nil {
42-
return fmt.Errorf("node id can only contain a-z, A-Z, 0-9 or special characters . - _ @ but received: %s", cfg.ID)
42+
return fmt.Errorf("node id can only contain a-z, A-Z, 0-9 or special characters . - _ @ : but received: %s", cfg.ID)
4343
}
4444
}
4545
if strings.ToLower(cfg.ID) == "localhost" {

pkg/types/main_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package types
2+
3+
import "testing"
4+
5+
func TestMainInitNodeID(t *testing.T) {
6+
mainInitNodeIDTestCases := []struct {
7+
name string
8+
nodeID string
9+
expectedErr string
10+
}{
11+
{
12+
name: "successful, no error",
13+
nodeID: "t.e-s_t@1:234",
14+
expectedErr: "",
15+
},
16+
{
17+
name: "failed, charactered not allowed",
18+
nodeID: "test!#&123",
19+
expectedErr: "node id can only contain a-z, A-Z, 0-9 or special characters . - _ @ : but received: test!#&123",
20+
},
21+
}
22+
23+
for _, testCase := range mainInitNodeIDTestCases {
24+
t.Run(testCase.name, func(t *testing.T) {
25+
cfg := NodeCfg{
26+
ID: testCase.nodeID,
27+
}
28+
err := cfg.Init()
29+
if err == nil && testCase.expectedErr != "" {
30+
t.Errorf("exected error but got no error")
31+
} else if err != nil && err.Error() != testCase.expectedErr {
32+
t.Errorf("expected error to be %s, but got: %s", testCase.expectedErr, err.Error())
33+
}
34+
})
35+
}
36+
}

0 commit comments

Comments
 (0)