carlos / platform Public

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

Plain git — no account needed to clone.

Download

Download this file

1package hostfence
2
3import (
4 "crypto/ed25519"
5 "github.com/carlosframework/platform/internal/hostactors"
6 "github.com/carlosframework/platform/internal/release"
7 "strings"
8 "testing"
9)
10
11func TestPlan9OneBoxRegionCountsOtherUnretiredEnrollments(t *testing.T) {
12 key := ed25519.NewKeyFromSeed(make([]byte, 32))
13 s := release.NewDirStore(t.TempDir())
14 source := hostactors.Box{BoxID: "source", Enrollment: strings.Repeat("a", 32), Namespace: "platform", Label: "source", Region: "ie", Pool: "default", Cloud: hostactors.Cloud{Provider: "aws", Account: "123", Region: "eu-west-1", InstanceID: "i-source"}, EvidenceSHA256: strings.Repeat("c", 64), State: "active"}
15 roster := hostactors.Roster{V: 1, Revision: 1, DeploymentBucket: "bucket", Boxes: map[string]hostactors.Box{"source": source}, Consoles: map[string]hostactors.Console{}, Holds: map[string]hostactors.Reservation{}, Activations: map[string]hostactors.Reservation{}, Regions: map[string]hostactors.Region{"ie": {Namespaces: []string{"platform"}, Pools: []string{"default"}, Account: "123", AWSRegion: "eu-west-1"}}}
16 write := func() {
17 wire, err := release.SignRootEnvelope(release.RootSigner(key), roster)
18 if err != nil {
19 t.Fatal(err)
20 }
21 _, tag, _ := s.Get(t.Context(), hostactors.Key)
22 if _, err = s.Put(t.Context(), hostactors.Key, wire, tag); err != nil {
23 t.Fatal(err)
24 }
25 }
26 write()
27 authority := ClaimFenceAuthority{Directory: hostactors.Directory{Store: s, PublicKey: key.Public().(ed25519.PublicKey), Bucket: "bucket"}}
28 if err := authority.CheckOneBoxRegion(t.Context(), "source", "ie"); err != nil {
29 t.Fatal(err)
30 }
31 other := source
32 other.BoxID = "other"
33 other.Label = "other"
34 other.Enrollment = strings.Repeat("d", 32)
35 other.Cloud.InstanceID = "i-other"
36 roster.Boxes["other"] = other
37 write()
38 if err := authority.CheckOneBoxRegion(t.Context(), "source", "ie"); err == nil {
39 t.Fatal("two-box region accepted")
40 }
41 other.State = "quarantined"
42 other.QuarantineRevision = 1
43 other.LossIDs = []string{"loss"}
44 roster.Boxes["other"] = other
45 write()
46 if err := authority.CheckOneBoxRegion(t.Context(), "source", "ie"); err == nil {
47 t.Fatal("quarantine erased cardinality")
48 }
49 delete(roster.Regions, "ie")
50 write()
51 if err := authority.CheckOneBoxRegion(t.Context(), "source", "ie"); err == nil {
52 t.Fatal("missing placement accepted")
53 }
54}
55