Add CI tests using the standard test interface
The following steps are used to execute the tests using the standard test interface: Docker sudo ANSIBLE_INVENTORY=$(test -e inventory && echo inventory || echo /usr/share/ansible/inventory) TEST_SUBJECTS=docker:docker.io/library/fedora:26 TEST_ARTIFACTS=$PWD/artifacts ansible-playbook --tags container tests.yml Classic sudo ANSIBLE_INVENTORY=$(test -e inventory && echo inventory || echo /usr/share/ansible/inventory) TEST_SUBJECTS="" TEST_ARTIFACTS=$PWD/artifacts ansible-playbook --tags classic tests.yml https://src.fedoraproject.org/rpms/libsepol/pull-request/1
This commit is contained in:
parent
640cc38286
commit
3a71508af5
63
tests/sepol_check_context/Makefile
Normal file
63
tests/sepol_check_context/Makefile
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
#
|
||||||
|
# Makefile of /CoreOS/libsepol/Sanity/sepol_check_context
|
||||||
|
# Description: Does sepol_check_context() work as expected?
|
||||||
|
# Author: Milos Malik <mmalik@redhat.com>
|
||||||
|
#
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
#
|
||||||
|
# Copyright (c) 2017 Red Hat, Inc.
|
||||||
|
#
|
||||||
|
# This copyrighted material is made available to anyone wishing
|
||||||
|
# to use, modify, copy, or redistribute it subject to the terms
|
||||||
|
# and conditions of the GNU General Public License version 2.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be
|
||||||
|
# useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||||
|
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||||
|
# PURPOSE. See the GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public
|
||||||
|
# License along with this program; if not, write to the Free
|
||||||
|
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||||
|
# Boston, MA 02110-1301, USA.
|
||||||
|
#
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
export TEST=/CoreOS/libsepol/Sanity/sepol_check_context
|
||||||
|
export TESTVERSION=1.0
|
||||||
|
|
||||||
|
BUILT_FILES=
|
||||||
|
|
||||||
|
FILES=$(METADATA) runtest.sh Makefile PURPOSE example.c testpolicy.te
|
||||||
|
|
||||||
|
.PHONY: all install download clean
|
||||||
|
|
||||||
|
run: $(FILES) build
|
||||||
|
./runtest.sh
|
||||||
|
|
||||||
|
build: $(BUILT_FILES)
|
||||||
|
test -x runtest.sh || chmod a+x runtest.sh
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *~ $(BUILT_FILES)
|
||||||
|
|
||||||
|
include /usr/share/rhts/lib/rhts-make.include
|
||||||
|
|
||||||
|
$(METADATA): Makefile
|
||||||
|
@echo "Owner: Milos Malik <mmalik@redhat.com>" > $(METADATA)
|
||||||
|
@echo "Name: $(TEST)" >> $(METADATA)
|
||||||
|
@echo "TestVersion: $(TESTVERSION)" >> $(METADATA)
|
||||||
|
@echo "Path: $(TEST_DIR)" >> $(METADATA)
|
||||||
|
@echo "Description: Does sepol_check_context() work as expected?" >> $(METADATA)
|
||||||
|
@echo "Type: Sanity" >> $(METADATA)
|
||||||
|
@echo "TestTime: 5m" >> $(METADATA)
|
||||||
|
@echo "RunFor: libsepol" >> $(METADATA)
|
||||||
|
@echo "Requires: libsepol libsepol-devel gcc policycoreutils selinux-policy-devel" >> $(METADATA)
|
||||||
|
@echo "Priority: Normal" >> $(METADATA)
|
||||||
|
@echo "License: GPLv2" >> $(METADATA)
|
||||||
|
@echo "Confidential: no" >> $(METADATA)
|
||||||
|
@echo "Destructive: no" >> $(METADATA)
|
||||||
|
|
||||||
|
rhts-lint $(METADATA)
|
||||||
|
|
5
tests/sepol_check_context/PURPOSE
Normal file
5
tests/sepol_check_context/PURPOSE
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
PURPOSE of /CoreOS/libsepol/Sanity/sepol_check_context
|
||||||
|
Author: Milos Malik <mmalik@redhat.com>
|
||||||
|
|
||||||
|
Does sepol_check_context() work as expected?
|
||||||
|
|
35
tests/sepol_check_context/example.c
Normal file
35
tests/sepol_check_context/example.c
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sepol/sepol.h>
|
||||||
|
|
||||||
|
int main (int argc, char *argv[]) {
|
||||||
|
FILE *policyfile;
|
||||||
|
|
||||||
|
if (argc < 3) {
|
||||||
|
fprintf(stderr, "%s <binary-policy-path> <context>\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
policyfile = fopen(argv[1], "r");
|
||||||
|
if (policyfile == NULL) {
|
||||||
|
perror("fopen");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sepol_set_policydb_from_file(policyfile) < 0) {
|
||||||
|
perror("sepol_set_policydb_from_file");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sepol_check_context(argv[2]) < 0) {
|
||||||
|
perror("sepol_check_context");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fclose(policyfile) != 0) {
|
||||||
|
perror("fclose");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
63
tests/sepol_check_context/runtest.sh
Normal file
63
tests/sepol_check_context/runtest.sh
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
#
|
||||||
|
# runtest.sh of /CoreOS/libsepol/Sanity/sepol_check_context
|
||||||
|
# Description: Does sepol_check_context() work as expected?
|
||||||
|
# Author: Milos Malik <mmalik@redhat.com>
|
||||||
|
#
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
#
|
||||||
|
# Copyright (c) 2017 Red Hat, Inc.
|
||||||
|
#
|
||||||
|
# This copyrighted material is made available to anyone wishing
|
||||||
|
# to use, modify, copy, or redistribute it subject to the terms
|
||||||
|
# and conditions of the GNU General Public License version 2.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be
|
||||||
|
# useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||||
|
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||||
|
# PURPOSE. See the GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public
|
||||||
|
# License along with this program; if not, write to the Free
|
||||||
|
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||||
|
# Boston, MA 02110-1301, USA.
|
||||||
|
#
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
# Include Beaker environment
|
||||||
|
. /usr/bin/rhts-environment.sh || exit 1
|
||||||
|
. /usr/share/beakerlib/beakerlib.sh || exit 1
|
||||||
|
|
||||||
|
PACKAGE="libsepol"
|
||||||
|
POLICY_PATH_PREFIX="/etc/selinux"
|
||||||
|
|
||||||
|
rlJournalStart
|
||||||
|
rlPhaseStartSetup
|
||||||
|
rlAssertRpm ${PACKAGE}
|
||||||
|
rlAssertRpm ${PACKAGE}-devel
|
||||||
|
rlRun "gcc -o example -lsepol example.c"
|
||||||
|
rlRun "make -f /usr/share/selinux/devel/Makefile"
|
||||||
|
rlRun "ls -l testpolicy.pp"
|
||||||
|
rlPhaseEnd
|
||||||
|
|
||||||
|
rlPhaseStartTest
|
||||||
|
for POLICY_KIND in minimum mls targeted ; do
|
||||||
|
if [ -d ${POLICY_PATH_PREFIX}/${POLICY_KIND}/policy ] ; then
|
||||||
|
POLICY_PATH=`find ${POLICY_PATH_PREFIX}/${POLICY_KIND}/policy/ -type f -name policy.?? | head -n 1`
|
||||||
|
rlRun "semodule -n -s ${POLICY_KIND} -r testpolicy" 0,1
|
||||||
|
rlRun "./example ${POLICY_PATH} system_u:object_r:xyz_file_t:s0" 1
|
||||||
|
rlRun "semodule -n -s ${POLICY_KIND} -i testpolicy.pp"
|
||||||
|
rlRun "./example ${POLICY_PATH} system_u:object_r:xyz_file_t:s0"
|
||||||
|
rlRun "semodule -n -s ${POLICY_KIND} -r testpolicy" 0,1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
rlPhaseEnd
|
||||||
|
|
||||||
|
rlPhaseStartCleanup
|
||||||
|
rlRun "rm -f ./example ./testpolicy.pp"
|
||||||
|
rlPhaseEnd
|
||||||
|
rlJournalPrintText
|
||||||
|
rlJournalEnd
|
||||||
|
|
4
tests/sepol_check_context/testpolicy.te
Normal file
4
tests/sepol_check_context/testpolicy.te
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
policy_module(testpolicy,1.0)
|
||||||
|
|
||||||
|
type xyz_file_t;
|
||||||
|
|
16
tests/tests.yml
Normal file
16
tests/tests.yml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
# Tests that run in all contexts
|
||||||
|
- hosts: localhost
|
||||||
|
roles:
|
||||||
|
- role: standard-test-beakerlib
|
||||||
|
tags:
|
||||||
|
- classic
|
||||||
|
- container
|
||||||
|
tests:
|
||||||
|
- sepol_check_context
|
||||||
|
required_packages:
|
||||||
|
- gcc
|
||||||
|
- libsepol-devel
|
||||||
|
- policycoreutils
|
||||||
|
- selinux-policy-devel
|
||||||
|
- findutils # beakerlib needs find command
|
Loading…
Reference in New Issue
Block a user