Let brother's scan-folder take an absolute path: mesh-config matches a pattern against the whole value (issue 1472) #385
@@ -357,3 +357,41 @@ func TestTheBucketIsRequiredAndItsKeyIsOnlyTheDeviceAccounts(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Issue 1472: mesh-config matches a config value against its pattern whole, as mesh-sdk's catalogue compiles it
|
||||
// (`^(?:<pattern>)$`, go/catalogue/config.go). Each value the operator gives on a real node passes, and a value
|
||||
// of the wrong form does not.
|
||||
func TestEachConfigPatternAdmitsARealValueWhole(t *testing.T) {
|
||||
raw, err := os.ReadFile(filepath.Join("..", "..", "module.json"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var m struct {
|
||||
Config map[string]struct {
|
||||
Pattern string `json:"pattern"`
|
||||
} `json:"config"`
|
||||
}
|
||||
if err := json.Unmarshal(raw, &m); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cases := map[string]struct{ good, bad string }{
|
||||
"scanner": {"http://192.0.2.10/eSCL", "192.0.2.10"},
|
||||
"scan-folder": {"/home/operator/Documents/Scans", "Documents/Scans"},
|
||||
"printer": {"192.0.2.10", "http://192.0.2.10"},
|
||||
"printer-certificate": {"EA:B4:B7:0F:96:CD:A6:2B:61:53:2E:F0:A8:D6:9F:42:EA:9F:66:0A:82:5B:C2:43:0B:97:C5:9A:7A:B4:18:5B", "EAB4"},
|
||||
}
|
||||
for key, c := range cases {
|
||||
p := m.Config[key].Pattern
|
||||
if p == "" {
|
||||
t.Errorf("%s declares no pattern", key)
|
||||
continue
|
||||
}
|
||||
re := regexp.MustCompile(`^(?:` + p + `)$`)
|
||||
if !re.MatchString(c.good) {
|
||||
t.Errorf("%s's pattern %q refuses the real value %q", key, p, c.good)
|
||||
}
|
||||
if re.MatchString(c.bad) {
|
||||
t.Errorf("%s's pattern %q admits %q", key, p, c.bad)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
"scan-folder": {
|
||||
"type": "string",
|
||||
"description": "The absolute path of the folder the scans are filed in as PDF files; the module makes it when it files the first scan, and never touches a file in it that it did not write. The operator's, with no default.",
|
||||
"pattern": "^/",
|
||||
"pattern": "^/.+$",
|
||||
"trusted": true,
|
||||
"required": true
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user