carlos / platform Public

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

Plain git — no account needed to clone.

Download

Download this file

1package host
2
3import (
4 "crypto/sha256"
5 "fmt"
6 "github.com/carlosframework/platform/internal/hostclaim"
7 "github.com/carlosframework/platform/internal/instancectl"
8 "github.com/carlosframework/platform/internal/release"
9 "os"
10 "path/filepath"
11 "testing"
12)
13
14func TestPlan11Fix1RootBindsHostApp(t *testing.T) {
15 for _, shape := range []string{"own", "other-account", "other-app", "root-binary", "missing-provider"} {
16 t.Run(shape, func(t *testing.T) {
17 f := newLaunchFixture(t, servingOp())
18 opt := t.TempDir()
19 path := release.VersionPath(opt, "bap", "v1", "app-a")
20 switch shape {
21 case "other-account":
22 path = release.VersionPath(opt, "cat", "v1", "app-a")
23 case "other-app":
24 path = release.VersionPath(opt, "bap", "v1", "app-b")
25 case "root-binary":
26 path = filepath.Join(opt, "bin", "helper")
27 }
28 if err := os.MkdirAll(filepath.Dir(path), 0700); err != nil {
29 t.Fatal(err)
30 }
31 data := []byte("fixture executable")
32 if err := os.WriteFile(path, data, 0700); err != nil {
33 t.Fatal(err)
34 }
35 f.req.Executable, f.req.Spec.Executable, f.kernel.path = path, path, path
36 digest := fmt.Sprintf("%x", sha256.Sum256(data))
37 f.req.Spec.Digest, f.kernel.digest = digest, digest
38 hash, err := f.req.Spec.Hash()
39 if err != nil {
40 t.Fatal(err)
41 }
42 f.req.Reservation.Inputs = hash
43 f.claims.set(func(c *hostclaim.Claim) { c.Holder.WakeRetry.Attempt.LaunchInputs = hash })
44 server := &instancectl.Server{OptDir: opt, HostApp: func(string) (string, string, error) { return "bap", "app-a", nil }}
45 f.root.ValidateExecutable = claimStagedExecutable(server)
46 if shape == "missing-provider" {
47 f.root.ValidateExecutable = nil
48 }
49 _, err = f.root.Serve(t.Context(), f.peer, f.req)
50 if shape == "own" {
51 if err != nil {
52 t.Fatal(err)
53 }
54 return
55 }
56 if err == nil {
57 t.Fatal("root accepted a build outside the host app")
58 }
59 f.noReservation(t, shape)
60 })
61 }
62}
63