carlos / platform Public

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

Plain git — no account needed to clone.

Download

Download this file

1//go:build linux
2
3package release
4
5import (
6 "github.com/carlosframework/platform/internal/rootstate"
7 "testing"
8)
9
10func TestPlan14GenerationNamespaceProof(t *testing.T) {
11 path := "/opt/carlos/versions/v1/lifecycle"
12 before := rootstate.FileIdentity{Boot: "boot", Device: 66305, Inode: 131086, Filesystem: "ext4:volume", Handle: "file-handle", HandleType: 1, Mode: 0100755, MountRoot: "/opt/carlos", MountPoint: "/opt/carlos", MountNamespace: "private", Mount: 306, MountUnique: 306, NamespaceUnique: 1, MountLineage: "/opt/carlos\t/opt/carlos\n/\t/\n"}
13 after := before
14 after.MountRoot, after.MountPoint, after.MountNamespace, after.Mount = "/", "/", "host", 127
15 after.MountLineage = "/\t/\n"
16 after.MountUnique, after.NamespaceUnique = 127, 2
17 if before.Same(after) {
18 t.Fatal("fixture must cross mount layouts")
19 }
20 if !GenerationFileProof(path, before, after) {
21 t.Fatal("same file through host mount refused")
22 }
23 for _, field := range []string{"source", "point", "namespace", "device", "filesystem", "handle", "inode", "owner", "mode", "missing"} {
24 bad := after
25 switch field {
26 case "source":
27 bad.MountRoot = "/other"
28 case "point":
29 bad.MountPoint = "/opt"
30 case "namespace":
31 bad.MountNamespace = before.MountNamespace
32 bad.NamespaceUnique = before.NamespaceUnique
33 case "device":
34 bad.Device++
35 case "filesystem":
36 bad.Filesystem = "other"
37 case "handle":
38 bad.Handle = "other"
39 case "inode":
40 bad.Inode++
41 case "owner":
42 bad.UID++
43 case "mode":
44 bad.Mode++
45 case "missing":
46 bad.Handle = ""
47 }
48 if GenerationFileProof(path, before, bad) {
49 t.Fatal("substitution accepted", field)
50 }
51 }
52}
53
54func TestPlan14GenerationMountSubstitution(t *testing.T) {
55 path := "/opt/carlos/versions/v1/app"
56 before := rootstate.FileIdentity{Boot: "old", Device: 1, Inode: 2, Filesystem: "fs", Handle: "handle", Mount: 3, MountUnique: 3, NamespaceUnique: 1, MountNamespace: "mnt:[1]", MountRoot: "/", MountPoint: "/", MountLineage: "/\t/\n"}
57 for _, boot := range []string{before.Boot, "new"} {
58 for _, point := range []string{"/opt/carlos", "/opt/carlos/versions/v1", path, "/"} {
59 after := before
60 after.Boot = boot
61 after.MountRoot, after.MountPoint = point, point
62 after.MountLineage = point + "\t" + point + "\n" + before.MountLineage
63 if GenerationFileProof(path, before, after) {
64 t.Fatal("substituted mount accepted", boot, point)
65 }
66 }
67 }
68}
69