Copy the node-engine's declaration parser into mesh-sdk, from mesh-host main (issue 1353)

This commit is contained in:
2026-10-20 06:01:48 +00:00
parent 3387abf50e
commit e5e3e62f28
23 changed files with 4814 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
package declaration
import "testing"
// `trusted` is the catalogue's word on a file (novox/hq issue 339): a controller takes it out before it sends a
// declaration, and one that does not — an older one, or one rolled back to — must not cost the node its whole
// declaration. So a file accepts it and the engine does nothing with it; any other resource still refuses it.
func TestAFileAcceptsAndIgnoresTrusted(t *testing.T) {
for _, v := range []string{"true", "false"} {
d, err := Parse([]byte(`{"declaration":1,"resources":[{"id":"m.f","type":"file","path":"/etc/m.conf",` +
`"content":"x","trusted":` + v + `}]}`))
if err != nil {
t.Fatalf("trusted %s: %v", v, err)
}
if f, ok := d.Resources[0].(*File); !ok || f.Content != "x" {
t.Fatalf("trusted %s: %+v", v, d.Resources[0])
}
}
if _, err := Parse([]byte(`{"declaration":1,"resources":[{"id":"m.d","type":"directory","path":"/srv/m",` +
`"trusted":true}]}`)); err == nil {
t.Fatal("a directory took trusted")
}
}