//go:build linux package provisioner import ( "context" "strings" "testing" "github.com/go-json-experiment/json" ) func TestSchemaPlanV2IsLocalAndNotEnrollable(t *testing.T) { old := planFixture() p := schemaPlanV2{2, old.Installation, old.BaselineOperation, schemaTargetV2{old.Credential, "credential-current-v1", strings.Repeat("a", 64)}, schemaTargetV2{old.Directory, "directory-historical-empty-v1", strings.Repeat("b", 64)}} raw, err := json.Marshal(p) if err != nil { t.Fatal(err) } decoded, err := decodeSchemaPlanV2(raw) if err != nil || decoded != p { t.Fatal(err) } for _, change := range []func(*schemaPlanV2){ func(p *schemaPlanV2) { p.Version = 1 }, func(p *schemaPlanV2) { p.Credential.SchemaProfile = "directory-historical-empty-v1" }, func(p *schemaPlanV2) { p.Directory.SchemaManifestDigest = "" }, func(p *schemaPlanV2) { p.Directory.SchemaManifestDigest = strings.Repeat("B", 64) }, func(p *schemaPlanV2) { p.Directory.SchemaProfile = "unknown" }, func(p *schemaPlanV2) { p.Directory.Host = p.Credential.Host }, } { changed := p change(&changed) wire, _ := json.Marshal(changed) if _, err := decodeSchemaPlanV2(wire); err == nil { t.Fatal("invalid v2 plan accepted") } } wire, _ := json.Marshal(old) if _, err := decodeSchemaPlanV2(wire); err == nil { t.Fatal("v2 accepted v1 plan") } var legacy InstallationPlan if json.Unmarshal(raw, &legacy, json.RejectUnknownMembers(true)) == nil { t.Fatal("old wire decoder accepted v2 fields") } j := journalFixture(t) legacy = old legacy.Version = 2 if err := j.enroll(context.Background(), legacy); err == nil { t.Fatal("journal enrolled v2") } }