...

Source file src/github.com/opencontainers/runc/libcontainer/cgroups/fs/devices_test.go

Documentation: github.com/opencontainers/runc/libcontainer/cgroups/fs

     1  package fs
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/opencontainers/runc/libcontainer/cgroups/fscommon"
     7  	"github.com/opencontainers/runc/libcontainer/configs"
     8  	"github.com/opencontainers/runc/libcontainer/devices"
     9  )
    10  
    11  func TestDevicesSetAllow(t *testing.T) {
    12  	path := tempDir(t, "devices")
    13  
    14  	writeFileContents(t, path, map[string]string{
    15  		"devices.allow": "",
    16  		"devices.deny":  "",
    17  		"devices.list":  "a *:* rwm",
    18  	})
    19  
    20  	r := &configs.Resources{
    21  		Devices: []*devices.Rule{
    22  			{
    23  				Type:        devices.CharDevice,
    24  				Major:       1,
    25  				Minor:       5,
    26  				Permissions: devices.Permissions("rwm"),
    27  				Allow:       true,
    28  			},
    29  		},
    30  	}
    31  
    32  	d := &DevicesGroup{TestingSkipFinalCheck: true}
    33  	if err := d.Set(path, r); err != nil {
    34  		t.Fatal(err)
    35  	}
    36  
    37  	// The default deny rule must be written.
    38  	value, err := fscommon.GetCgroupParamString(path, "devices.deny")
    39  	if err != nil {
    40  		t.Fatal(err)
    41  	}
    42  	if value[0] != 'a' {
    43  		t.Errorf("Got the wrong value (%q), set devices.deny failed.", value)
    44  	}
    45  
    46  	// Permitted rule must be written.
    47  	if value, err := fscommon.GetCgroupParamString(path, "devices.allow"); err != nil {
    48  		t.Fatal(err)
    49  	} else if value != "c 1:5 rwm" {
    50  		t.Errorf("Got the wrong value (%q), set devices.allow failed.", value)
    51  	}
    52  }
    53  

View as plain text