carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package hostactors
2
3import (
4 "bytes"
5 "github.com/carlosframework/platform/internal/release"
6 "strings"
7 "testing"
8)
9
10func TestPlan11Fix1EnrollmentFlagBytes(t *testing.T) {
11 for _, flag := range []string{"", "1"} {
12 t.Run("flag="+flag, func(t *testing.T) {
13 t.Setenv("CARLOS_HOST_CLAIM", flag)
14 d, sg, before := fixture(t)
15 next := Clone(before.Roster)
16 b := next.Boxes["box"]
17 b.BoxID, b.Enrollment, b.Cloud.InstanceID = "second", strings.Repeat("c", 32), "i-second"
18 next.Boxes["second"] = b
19 next.Consoles["console"] = Console{Enrollment: strings.Repeat("d", 32), InstanceID: "console", Namespaces: []string{"platform"}, DeploymentBucket: d.Bucket}
20 got, err := d.Replace(t.Context(), sg, before, next)
21 if err != nil {
22 t.Fatal(err)
23 }
24 raw, _, err := d.Store.Get(t.Context(), Key)
25 if err != nil {
26 t.Fatal(err)
27 }
28 if flag == "" {
29 next.Revision = before.Roster.Revision + 1
30 want, err := release.SignRootEnvelope(sg, next)
31 if err != nil {
32 t.Fatal(err)
33 }
34 if !bytes.Equal(raw, want) || bytes.Contains(raw, []byte("enrolled_at")) {
35 t.Fatal("flag-off enrollment changed legacy signed bytes")
36 }
37 } else if got.Roster.Boxes["second"].EnrolledAt.IsZero() || got.Roster.Consoles["console"].EnrolledAt.IsZero() {
38 t.Fatal("flag-on enrollment missing timestamps")
39 }
40 })
41 }
42}
43