Add tests for selabel_file backend
PATCH v2 1/1 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).
---
Changes since v1:
- Redirect stderr to stdout in test
policy/Makefile | 3 +- policy/test_file_contexts.te | 6 ++ tests/Makefile | 2 +- tests/file_contexts/Makefile | 10 +++ tests/file_contexts/f1.fc | 1 + tests/file_contexts/f2.fc | 4 ++ tests/file_contexts/f3.fc | 2 + tests/file_contexts/f3.fc.homedirs | 1 + tests/file_contexts/f3.fc.local | 1 + tests/file_contexts/f3.fc.subs | 1 + tests/file_contexts/f3.fc.subs_dist | 1 + tests/file_contexts/internal.c | 41 +++++++++++++ tests/file_contexts/internal.h | 16 +++++ tests/file_contexts/test | 25 ++++++++ tests/file_contexts/test_lookup.c | 46 ++++++++++++++ tests/file_contexts/test_open.c | 82 +++++++++++++++++++++++++ tests/file_contexts/test_open_base.c | 92 ++++++++++++++++++++++++++++ tests/file_contexts/test_validate.c | 56 +++++++++++++++++ 18 files changed, 388 insertions(+), 2 deletions(-) create mode 100644 policy/test_file_contexts.te create mode 100644 tests/file_contexts/Makefile create mode 100644 tests/file_contexts/f1.fc create mode 100644 tests/file_contexts/f2.fc create mode 100644 tests/file_contexts/f3.fc create mode 100644 tests/file_contexts/f3.fc.homedirs create mode 100644 tests/file_contexts/f3.fc.local create mode 100644 tests/file_contexts/f3.fc.subs create mode 100644 tests/file_contexts/f3.fc.subs_dist create mode 100644 tests/file_contexts/internal.c create mode 100644 tests/file_contexts/internal.h create mode 100755 tests/file_contexts/test create mode 100644 tests/file_contexts/test_lookup.c create mode 100644 tests/file_contexts/test_open.c create mode 100644 tests/file_contexts/test_open_base.c create mode 100644 tests/file_contexts/test_validate.c
policy/Makefile +2 -1
@@ -29,7 +29,8 @@ TARGETS = \ test_task_getsid.te test_task_setpgid.te test_task_setsched.te \ test_transition.te test_unix_socket.te \ test_mmap.te test_overlayfs.te test_mqueue.te \ - test_ibpkey.te test_atsecure.te test_cgroupfs.te + test_ibpkey.te test_atsecure.te test_cgroupfs.te \ + test_file_contexts.te ifeq (x$(DISTRO),$(filter x$(DISTRO),xRHEL4 xRHEL5 xRHEL6)) SUPPORTS_CIL = n
policy/test_file_contexts.te new file +6 -0
@@ -0,0 +1,6 @@ +####### Policy for testing file_contexts ######### + +type test_base_t; +type test_base_wildcard_t; +type test_base_sub_t; +type test_file_list_t;
tests/Makefile +1 -1
@@ -28,7 +28,7 @@ SUBDIRS:= domain_trans entrypoint execshare exectrace execute_no_trans \ task_getpgid task_setpgid file ioctl capable_file capable_net \ capable_sys dyntrans dyntrace bounds nnp_nosuid mmap unix_socket \ inet_socket/tcp inet_socket/udp overlay checkreqprot mqueue \ - mac_admin atsecure infiniband_endport infiniband_pkey + mac_admin atsecure infiniband_endport infiniband_pkey file_contexts ifeq ($(shell grep -q cap_userns $(POLDEV)/include/support/all_perms.spt && echo true),true) ifneq ($(shell ./kvercmp $$(uname -r) 4.7),-1)
tests/file_contexts/Makefile new file +10 -0
@@ -0,0 +1,10 @@ +TARGETS=test_open test_lookup test_open_base test_validate +CFLAGS += -O2 -Werror -Wall +LDLIBS += -lselinux + +all: $(TARGETS) + +$(TARGETS): internal.o + +clean: + rm -f $(TARGETS) *.o
tests/file_contexts/f1.fc new file +1 -0
@@ -0,0 +1 @@ +/ system_u:object_r:rootfs:s0
tests/file_contexts/f2.fc new file +4 -0
@@ -0,0 +1,4 @@ +/base system_u:object_r:test_base_t:s0 +/base(/.*)? system_u:object_r:test_base_wildcard_t:s0 +/base/sub system_u:object_r:test_base_sub_t:s0 +/base/file\.list system_u:object_r:test_file_list_t:s0
tests/file_contexts/f3.fc new file +2 -0
@@ -0,0 +1,2 @@ +/ system_u:object_r:rootfs:s0 +/subbed system_u:object_r:test_subbed:s0
tests/file_contexts/f3.fc.homedirs new file +1 -0
@@ -0,0 +1 @@ +/homedirs system_u:object_r:test_homedirs:s0
tests/file_contexts/f3.fc.local new file +1 -0
@@ -0,0 +1 @@ +/local system_u:object_r:test_local:s0
tests/file_contexts/f3.fc.subs new file +1 -0
@@ -0,0 +1 @@ +/sub /subbed
tests/file_contexts/f3.fc.subs_dist new file +1 -0
@@ -0,0 +1 @@ +/sub_dist /subbed
tests/file_contexts/internal.c new file +41 -0
41 lines not on this page · raw message
tests/file_contexts/internal.h new file +16 -0
@@ -0,0 +1,16 @@ +#include <selinux/label.h> +#include <selinux/selinux.h> + +#define ARRAY_SIZE (a) (sizeof(a) / sizeof((a)[0])) + +/* Structure to capture a test. The |path| will be resolved and expected to +* match the |context|. If |context| is NULL, the lookup is expected to fail. */ +struct test_t { +const char *path; +const char *context; +}; + +/* Assert that all paths described in |tests| resolve appropriately. |hnd| must +* be opened. |n| is the number of tests in |tests|. */ +void assertContextsMatch (struct selabel_handle *hnd,struct test_t *tests, +size_t n);
tests/file_contexts/test new file +25 -0
@@ -0,0 +1,25 @@ +#!/usr/bin/perl +# +# This test validates the parsing of file_contexts. +# + +use Test; + +BEGIN { plan tests => 4; } + +$basedir = $0; +$basedir =~ s|(.*)/[^/]*|$1|; + +$result = system "$basedir/test_open $basedir 2>&1"; +ok( $result, 0 ); + +$result = system "$basedir/test_lookup $basedir 2>&1"; +ok( $result, 0 ); + +$result = system "$basedir/test_open_base $basedir 2>&1"; +ok( $result, 0 ); + +$result = system "$basedir/test_validate $basedir 2>&1"; +ok( $result, 0 ); + +exit;
tests/file_contexts/test_lookup.c new file +46 -0
46 lines not on this page · raw message
tests/file_contexts/test_open.c new file +82 -0
82 lines not on this page · raw message
tests/file_contexts/test_open_base.c new file +92 -0
92 lines not on this page · raw message
tests/file_contexts/test_validate.c new file +56 -0
56 lines not on this page · raw message
Signature · 1 line
2.53.0.473.g4a7958ca14-goog
Quoted 12 lines · Thiébaud Weksteen
Add basic set of tests to validate the behaviour of the
selabel_filebackend. The parsing and usage offile_contextsis confirmed, in the following scenarios:-
selabel_openwith no options,
-selabel_openwith a NULLSELABEL_OPT_PATH,
-selabel_openwith a validSELABEL_OPT_PATH,
-selabel_openwith a validSELABEL_OPT_PATHandSELABEL_OPT_BASEONLY,
-selabel_openwithSELABEL_OPT_VALIDATEand known types,
-selabel_openwithSELABEL_OPT_VALIDATEand unknown types.
Quoted 4 lines
Validate that substitutions and local customizations are loaded according to
selabel_file(5).Signed-off-by Thiébaud Weksteen <[email protected]>
Thanks, applied.
Quoted 14 lines · Stephen Smalley
Quoted 12 lines · Thiébaud Weksteen
Add basic set of tests to validate the behaviour of the
selabel_filebackend. The parsing and usage offile_contextsis confirmed, in the following scenarios:-
selabel_openwith no options,
-selabel_openwith a NULLSELABEL_OPT_PATH,
-selabel_openwith a validSELABEL_OPT_PATH,
-selabel_openwith a validSELABEL_OPT_PATHandSELABEL_OPT_BASEONLY,
-selabel_openwithSELABEL_OPT_VALIDATEand known types,
-selabel_openwithSELABEL_OPT_VALIDATEand unknown types.
Quoted 6 lines
Quoted 4 lines
Validate that substitutions and local customizations are loaded according to
selabel_file(5).Signed-off-by Thiébaud Weksteen <[email protected]>Thanks, applied.
Great. Thanks for the review Stephen.