From 35aac9f358cd65d36d2cc5d337db4d7df34c38eb Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 20 Oct 2026 21:49:47 +0200 Subject: [PATCH] Let brother's scan-folder take an absolute path: mesh-config matches a pattern against the whole value (issue 1472) --- modules/brother/cmd/brother/manifest_test.go | 38 ++++++++++++++++++++ modules/brother/module.json | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/modules/brother/cmd/brother/manifest_test.go b/modules/brother/cmd/brother/manifest_test.go index 425ba98d..2291186f 100644 --- a/modules/brother/cmd/brother/manifest_test.go +++ b/modules/brother/cmd/brother/manifest_test.go @@ -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 +// (`^(?:)$`, 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) + } + } +} diff --git a/modules/brother/module.json b/modules/brother/module.json index 023e2d12..e62e1843 100644 --- a/modules/brother/module.json +++ b/modules/brother/module.json @@ -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 },