Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1218 from Random-Liu/more-proc-mount-test
Browse files Browse the repository at this point in the history
Add test for disable_proc_mount.
  • Loading branch information
Random-Liu committed Aug 2, 2019
2 parents fb5210e + 986d04a commit a997666
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions pkg/server/container_create_test.go
Expand Up @@ -23,10 +23,12 @@ import (
"strings"
"testing"

"github.com/containerd/containerd/containers"
"github.com/containerd/containerd/contrib/apparmor"
"github.com/containerd/containerd/contrib/seccomp"
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/oci"
ctrdutil "github.com/containerd/cri/pkg/containerd/util"
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
runtimespec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
Expand Down Expand Up @@ -1093,21 +1095,33 @@ func TestMaskedAndReadonlyPaths(t *testing.T) {
config, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData()
c := newTestCRIService()

defaultSpec, err := c.generateContainerSpec(testID, testSandboxID, testPid, config, sandboxConfig, imageConfig, nil, nil)
defaultSpec, err := oci.GenerateSpec(ctrdutil.NamespacedContext(), nil, &containers.Container{ID: testID})
require.NoError(t, err)

for desc, test := range map[string]struct {
disableProcMount bool
masked []string
readonly []string
expectedMasked []string
expectedReadonly []string
privileged bool
}{
"should apply default if not specified": {
"should apply default if not specified when disable_proc_mount = true": {
disableProcMount: true,
masked: nil,
readonly: nil,
expectedMasked: defaultSpec.Linux.MaskedPaths,
expectedReadonly: defaultSpec.Linux.ReadonlyPaths,
privileged: false,
},
"should always apply CRI specified paths when disable_proc_mount = false": {
disableProcMount: false,
masked: nil,
readonly: nil,
expectedMasked: nil,
expectedReadonly: nil,
privileged: false,
},
"should be able to specify empty paths": {
masked: []string{},
readonly: []string{},
Expand Down Expand Up @@ -1143,6 +1157,7 @@ func TestMaskedAndReadonlyPaths(t *testing.T) {
},
} {
t.Logf("TestCase %q", desc)
c.config.DisableProcMount = test.disableProcMount
config.Linux.SecurityContext.MaskedPaths = test.masked
config.Linux.SecurityContext.ReadonlyPaths = test.readonly
config.Linux.SecurityContext.Privileged = test.privileged
Expand Down

0 comments on commit a997666

Please sign in to comment.