diff options
author | Tom Cherry <tomcherry@google.com> | 2017-04-05 17:55:46 -0700 |
---|---|---|
committer | Tom Cherry <tomcherry@google.com> | 2017-04-17 19:33:04 +0000 |
commit | cc054c9da830b8b33b850c633324867c68488cac (patch) | |
tree | 0c076b528cec90672783c0a10bd6fcb327c3c822 /init/devices_test.cpp | |
parent | b7826a74f246ac148c3f5c6ad73e3fc8728a0bfe (diff) | |
download | core-cc054c9da830b8b33b850c633324867c68488cac.tar.gz core-cc054c9da830b8b33b850c633324867c68488cac.tar.bz2 core-cc054c9da830b8b33b850c633324867c68488cac.zip |
ueventd: create classes for dev and sys permissions
Create classes for dev and sys permissions and store these permissions
in std::vector instead of the C list.
Test: boot bullhead
Test: init unit tests
Change-Id: I874039a3db29b4c70149506da8e407123ab7eca2
Diffstat (limited to 'init/devices_test.cpp')
-rw-r--r-- | init/devices_test.cpp | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/init/devices_test.cpp b/init/devices_test.cpp index 693fb54dd..66521db6b 100644 --- a/init/devices_test.cpp +++ b/init/devices_test.cpp @@ -316,3 +316,94 @@ TEST(devices, sanitize_onebad) { sanitize_partition_name(&string); EXPECT_EQ("_", string); } + +TEST(devices, DevPermissionsMatchNormal) { + // Basic from ueventd.rc + // /dev/null 0666 root root + Permissions permissions("/dev/null", 0666, 0, 0); + EXPECT_TRUE(permissions.Match("/dev/null")); + EXPECT_FALSE(permissions.Match("/dev/nullsuffix")); + EXPECT_FALSE(permissions.Match("/dev/nul")); + EXPECT_EQ(0666U, permissions.perm()); + EXPECT_EQ(0U, permissions.uid()); + EXPECT_EQ(0U, permissions.gid()); +} + +TEST(devices, DevPermissionsMatchPrefix) { + // Prefix from ueventd.rc + // /dev/dri/* 0666 root graphics + Permissions permissions("/dev/dri/*", 0666, 0, 1000); + EXPECT_TRUE(permissions.Match("/dev/dri/some_dri_device")); + EXPECT_TRUE(permissions.Match("/dev/dri/some_other_dri_device")); + EXPECT_TRUE(permissions.Match("/dev/dri/")); + EXPECT_FALSE(permissions.Match("/dev/dr/non_match")); + EXPECT_EQ(0666U, permissions.perm()); + EXPECT_EQ(0U, permissions.uid()); + EXPECT_EQ(1000U, permissions.gid()); +} + +TEST(devices, DevPermissionsMatchWildcard) { + // Wildcard example + // /dev/device*name 0666 root graphics + Permissions permissions("/dev/device*name", 0666, 0, 1000); + EXPECT_TRUE(permissions.Match("/dev/devicename")); + EXPECT_TRUE(permissions.Match("/dev/device123name")); + EXPECT_TRUE(permissions.Match("/dev/deviceabcname")); + EXPECT_FALSE(permissions.Match("/dev/device123name/subdevice")); + EXPECT_FALSE(permissions.Match("/dev/deviceame")); + EXPECT_EQ(0666U, permissions.perm()); + EXPECT_EQ(0U, permissions.uid()); + EXPECT_EQ(1000U, permissions.gid()); +} + +TEST(devices, DevPermissionsMatchWildcardPrefix) { + // Wildcard+Prefix example + // /dev/device*name* 0666 root graphics + Permissions permissions("/dev/device*name*", 0666, 0, 1000); + EXPECT_TRUE(permissions.Match("/dev/devicename")); + EXPECT_TRUE(permissions.Match("/dev/device123name")); + EXPECT_TRUE(permissions.Match("/dev/deviceabcname")); + EXPECT_TRUE(permissions.Match("/dev/device123namesomething")); + // FNM_PATHNAME doesn't match '/' with * + EXPECT_FALSE(permissions.Match("/dev/device123name/something")); + EXPECT_FALSE(permissions.Match("/dev/deviceame")); + EXPECT_EQ(0666U, permissions.perm()); + EXPECT_EQ(0U, permissions.uid()); + EXPECT_EQ(1000U, permissions.gid()); +} + +TEST(devices, SysfsPermissionsMatchWithSubsystemNormal) { + // /sys/devices/virtual/input/input* enable 0660 root input + SysfsPermissions permissions("/sys/devices/virtual/input/input*", "enable", 0660, 0, 1001); + EXPECT_TRUE(permissions.MatchWithSubsystem("/sys/devices/virtual/input/input0", "input")); + EXPECT_FALSE(permissions.MatchWithSubsystem("/sys/devices/virtual/input/not_input0", "input")); + EXPECT_EQ(0660U, permissions.perm()); + EXPECT_EQ(0U, permissions.uid()); + EXPECT_EQ(1001U, permissions.gid()); +} + +TEST(devices, SysfsPermissionsMatchWithSubsystemClass) { + // /sys/class/input/event* enable 0660 root input + SysfsPermissions permissions("/sys/class/input/event*", "enable", 0660, 0, 1001); + EXPECT_TRUE(permissions.MatchWithSubsystem( + "/sys/devices/soc.0/f9924000.i2c/i2c-2/2-0020/input/input0/event0", "input")); + EXPECT_FALSE(permissions.MatchWithSubsystem( + "/sys/devices/soc.0/f9924000.i2c/i2c-2/2-0020/input/input0/not_event0", "input")); + EXPECT_FALSE(permissions.MatchWithSubsystem( + "/sys/devices/soc.0/f9924000.i2c/i2c-2/2-0020/input/input0/event0", "not_input")); + EXPECT_EQ(0660U, permissions.perm()); + EXPECT_EQ(0U, permissions.uid()); + EXPECT_EQ(1001U, permissions.gid()); +} + +TEST(devices, SysfsPermissionsMatchWithSubsystemBus) { + // /sys/bus/i2c/devices/i2c-* enable 0660 root input + SysfsPermissions permissions("/sys/bus/i2c/devices/i2c-*", "enable", 0660, 0, 1001); + EXPECT_TRUE(permissions.MatchWithSubsystem("/sys/devices/soc.0/f9967000.i2c/i2c-5", "i2c")); + EXPECT_FALSE(permissions.MatchWithSubsystem("/sys/devices/soc.0/f9967000.i2c/not-i2c", "i2c")); + EXPECT_FALSE( + permissions.MatchWithSubsystem("/sys/devices/soc.0/f9967000.i2c/i2c-5", "not_i2c")); + EXPECT_EQ(0660U, permissions.perm()); + EXPECT_EQ(0U, permissions.uid()); + EXPECT_EQ(1001U, permissions.gid()); +} |