-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuilder_linux_test.go
More file actions
52 lines (44 loc) · 1.46 KB
/
Copy pathbuilder_linux_test.go
File metadata and controls
52 lines (44 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//go:build linux
package bbox
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/moolen/bbox/internal/sandboxroot"
)
func TestResolveDockerBuildSupportRejectsMissingRequiredTool(t *testing.T) {
dir := t.TempDir()
opts := sandboxroot.DockerBuildOptions{
Enabled: true,
BuildkitdPath: writeExecutableFixture(t, dir, "buildkitd"),
BuildctlPath: writeExecutableFixture(t, dir, "buildctl"),
RuncPath: writeExecutableFixture(t, dir, "runc"),
PodmanPath: writeExecutableFixture(t, dir, "podman"),
NewgidmapPath: writeExecutableFixture(t, dir, "newgidmap"),
NewuidmapPath: filepath.Join(dir, "missing-newuidmap"),
}
_, err := sandboxroot.ResolveDockerBuildSupport(opts)
if err == nil {
t.Fatal("expected missing newuidmap to fail")
}
if !strings.Contains(err.Error(), "newuidmap") {
t.Fatalf("expected error to mention newuidmap, got %v", err)
}
}
func TestValidateSubordinateIDMappings(t *testing.T) {
dir := t.TempDir()
subuidPath := filepath.Join(dir, "subuid")
subgidPath := filepath.Join(dir, "subgid")
username := "sandbox-user"
entry := username + ":100000:65536\n"
if err := os.WriteFile(subuidPath, []byte(entry), 0o644); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(subgidPath, []byte(entry), 0o644); err != nil {
t.Fatal(err)
}
if err := sandboxroot.ValidateSubordinateIDMappingsForUser(username, subuidPath, subgidPath); err != nil {
t.Fatalf("validate subordinate id mappings failed: %v", err)
}
}