| 1 | package hostactors |
| 2 | |
| 3 | import ( |
| 4 | "reflect" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | func TestConsoleInvitationDoesNotAdmitOrRebind(t *testing.T) { |
| 10 | ctx := t.Context() |
| 11 | d, signer, before := fixture(t) |
| 12 | c := Console{Enrollment: strings.Repeat("c", 32), InstanceID: "console-2", Namespaces: []string{"platform"}, DeploymentBucket: d.Bucket} |
| 13 | for range 2 { |
| 14 | if err := d.InviteConsole(ctx, signer, c); err != nil { |
| 15 | t.Fatal(err) |
| 16 | } |
| 17 | } |
| 18 | got, err := d.InvitedConsole(ctx, before, c.InstanceID) |
| 19 | if err != nil || !reflect.DeepEqual(got, c) { |
| 20 | t.Fatal("invitation identity changed", got, err) |
| 21 | } |
| 22 | changed := c |
| 23 | changed.Enrollment = strings.Repeat("d", 32) |
| 24 | if err := d.InviteConsole(ctx, signer, changed); err == nil { |
| 25 | t.Fatal("rebound invitation") |
| 26 | } |
| 27 | changed = c |
| 28 | changed.InstanceID = "../other" |
| 29 | if err := d.InviteConsole(ctx, signer, changed); err == nil { |
| 30 | t.Fatal("invalid console ID invited") |
| 31 | } |
| 32 | if _, err := d.InvitedConsole(ctx, before, "../other"); err == nil { |
| 33 | t.Fatal("invalid console ID read") |
| 34 | } |
| 35 | after, err := d.Read(ctx) |
| 36 | if err != nil || after.ETag != before.ETag { |
| 37 | t.Fatal("invitation changed roster membership", err) |
| 38 | } |
| 39 | } |
| 40 | |