Skip to content

Commit d30db60

Browse files
tweksteenstephensmalley
authored andcommitted
Add tests for selabel_file backend
Add basic set of tests to validate the behaviour of the selabel_file backend. The parsing and usage of file_contexts is confirmed, in the following scenarios: - selabel_open with no options, - selabel_open with a NULL SELABEL_OPT_PATH, - selabel_open with a valid SELABEL_OPT_PATH, - selabel_open with a valid SELABEL_OPT_PATH and SELABEL_OPT_BASEONLY, - selabel_open with SELABEL_OPT_VALIDATE and known types, - selabel_open with SELABEL_OPT_VALIDATE and unknown types. Validate that substitutions and local customizations are loaded according to selabel_file(5). Signed-off-by: Thiébaud Weksteen <tweek@google.com> Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
1 parent 16ac3af commit d30db60

19 files changed

Lines changed: 393 additions & 2 deletions

policy/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ TARGETS = \
2929
test_task_getsid.te test_task_setpgid.te test_task_setsched.te \
3030
test_transition.te test_unix_socket.te \
3131
test_mmap.te test_overlayfs.te test_mqueue.te \
32-
test_ibpkey.te test_atsecure.te test_cgroupfs.te
32+
test_ibpkey.te test_atsecure.te test_cgroupfs.te \
33+
test_file_contexts.te
3334

3435
ifeq (x$(DISTRO),$(filter x$(DISTRO),xRHEL4 xRHEL5 xRHEL6))
3536
SUPPORTS_CIL = n

policy/test_file_contexts.te

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
####### Policy for testing file_contexts #########
2+
3+
type test_base_t;
4+
type test_base_wildcard_t;
5+
type test_base_sub_t;
6+
type test_file_list_t;

tests/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ SUBDIRS:= domain_trans entrypoint execshare exectrace execute_no_trans \
2828
task_getpgid task_setpgid file ioctl capable_file capable_net \
2929
capable_sys dyntrans dyntrace bounds nnp_nosuid mmap unix_socket \
3030
inet_socket/tcp inet_socket/udp overlay checkreqprot mqueue \
31-
mac_admin atsecure infiniband_endport infiniband_pkey
31+
mac_admin atsecure infiniband_endport infiniband_pkey file_contexts
3232

3333
ifeq ($(shell grep -q cap_userns $(POLDEV)/include/support/all_perms.spt && echo true),true)
3434
ifneq ($(shell ./kvercmp $$(uname -r) 4.7),-1)

tests/file_contexts/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
internal.o
2+
test_lookup
3+
test_open
4+
test_open_base
5+
test_validate

tests/file_contexts/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
TARGETS=test_open test_lookup test_open_base test_validate
2+
CFLAGS += -O2 -Werror -Wall
3+
LDLIBS += -lselinux
4+
5+
all: $(TARGETS)
6+
7+
$(TARGETS): internal.o
8+
9+
clean:
10+
rm -f $(TARGETS) *.o

tests/file_contexts/f1.fc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/ system_u:object_r:rootfs:s0

tests/file_contexts/f2.fc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/base system_u:object_r:test_base_t:s0
2+
/base(/.*)? system_u:object_r:test_base_wildcard_t:s0
3+
/base/sub system_u:object_r:test_base_sub_t:s0
4+
/base/file\.list system_u:object_r:test_file_list_t:s0

tests/file_contexts/f3.fc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/ system_u:object_r:rootfs:s0
2+
/subbed system_u:object_r:test_subbed:s0

tests/file_contexts/f3.fc.homedirs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/homedirs system_u:object_r:test_homedirs:s0

tests/file_contexts/f3.fc.local

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/local system_u:object_r:test_local:s0

0 commit comments

Comments
 (0)