package host import ( "testing" "github.com/carlosframework/platform/internal/hostbox" "github.com/carlosframework/platform/internal/hostwrite" ) // rootLaunchSpec is the preimage root hashes for a launch, built exactly as // ClaimRoleAssembly.Launch builds it (claimroleassembly_linux.go): the // verifier (claimlaunch_authority.go) refuses a launch whose spec's hash is // not the attempt's reserved LaunchInputs. func rootLaunchSpec(in ClaimLaunchInputs) hostbox.LaunchSpec { return hostbox.LaunchSpec{Identity: in.Identity, Executable: in.Executable, Digest: in.ExecutableSHA256, Args: append([]string(nil), in.Args...), Env: append([]string(nil), in.Env...)} } // TestClaimLaunchDigestIsMainsAndRoots (home part 2, Task 2b fix round 4): // ClaimLaunchDigest is main's, byte for byte, for an empty launch and for // one whose instance sets app variables, and it is root's LaunchSpec hash // of the same launch, so a reserved attempt passes root's launch check. func TestClaimLaunchDigestIsMainsAndRoots(t *testing.T) { for name, c := range map[string]struct { in ClaimLaunchInputs main string }{ "empty": {ClaimLaunchInputs{}, "0ed115c96598a2877d539d837d785f574bd5c4c8630fe1803ca216a0cb76396b"}, "app variables": {ClaimLaunchInputs{Identity: hostwrite.Identity{Config: "launch-env:sha256:c", Release: "v7"}, Executable: "/opt/carlos/live/a.example.com", ExecutableSHA256: "aaaa", Args: []string{"--socket", "/run/a.sock"}, Env: []string{"A=1", "HOSTNAME=x"}}, "47246370546f9bec4ae2541bace116bd102be9655ab1b376de990d5374f26bbe"}, } { d, err := ClaimLaunchDigest(c.in) if err != nil || d != c.main { t.Fatalf("%s: %s %v, want main's %s", name, d, err, c.main) } root, err := rootLaunchSpec(c.in).Hash() if err != nil || root != d { t.Fatalf("%s: root's spec hash %s %v, the reserved digest %s", name, root, err, d) } } }