oficina / home Public

Clone
git clone https://amadan.net/oficina/home

Plain git — no account needed to clone.

Download

Download this file

1//go:build linux
2
3package provisioner
4
5import (
6 "context"
7 "strings"
8 "testing"
9
10 "github.com/go-json-experiment/json"
11)
12
13func TestSchemaPlanV2IsLocalAndNotEnrollable(t *testing.T) {
14 old := planFixture()
15 p := schemaPlanV2{2, old.Installation, old.BaselineOperation,
16 schemaTargetV2{old.Credential, "credential-current-v1", strings.Repeat("a", 64)},
17 schemaTargetV2{old.Directory, "directory-historical-empty-v1", strings.Repeat("b", 64)}}
18 raw, err := json.Marshal(p)
19 if err != nil {
20 t.Fatal(err)
21 }
22 decoded, err := decodeSchemaPlanV2(raw)
23 if err != nil || decoded != p {
24 t.Fatal(err)
25 }
26 for _, change := range []func(*schemaPlanV2){
27 func(p *schemaPlanV2) { p.Version = 1 },
28 func(p *schemaPlanV2) { p.Credential.SchemaProfile = "directory-historical-empty-v1" },
29 func(p *schemaPlanV2) { p.Directory.SchemaManifestDigest = "" },
30 func(p *schemaPlanV2) { p.Directory.SchemaManifestDigest = strings.Repeat("B", 64) },
31 func(p *schemaPlanV2) { p.Directory.SchemaProfile = "unknown" },
32 func(p *schemaPlanV2) { p.Directory.Host = p.Credential.Host },
33 } {
34 changed := p
35 change(&changed)
36 wire, _ := json.Marshal(changed)
37 if _, err := decodeSchemaPlanV2(wire); err == nil {
38 t.Fatal("invalid v2 plan accepted")
39 }
40 }
41 wire, _ := json.Marshal(old)
42 if _, err := decodeSchemaPlanV2(wire); err == nil {
43 t.Fatal("v2 accepted v1 plan")
44 }
45 var legacy InstallationPlan
46 if json.Unmarshal(raw, &legacy, json.RejectUnknownMembers(true)) == nil {
47 t.Fatal("old wire decoder accepted v2 fields")
48 }
49 j := journalFixture(t)
50 legacy = old
51 legacy.Version = 2
52 if err := j.enroll(context.Background(), legacy); err == nil {
53 t.Fatal("journal enrolled v2")
54 }
55}
56