diff --git a/tests/Can-t-remove-crontab-from-expired-accounts/Makefile b/tests/Can-t-remove-crontab-from-expired-accounts/Makefile new file mode 100644 index 0000000..eea8ff8 --- /dev/null +++ b/tests/Can-t-remove-crontab-from-expired-accounts/Makefile @@ -0,0 +1,62 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /CoreOS/cronie/Regression/Can-t-remove-crontab-from-expired-accounts +# Description: Test for Can't remove crontab from expired accounts +# Author: Karel Volny +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2017 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# 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, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +export TEST=/CoreOS/cronie/Regression/Can-t-remove-crontab-from-expired-accounts +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE + +.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: Karel Volny " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: Test for Can't remove crontab from expired accounts" >> $(METADATA) + @echo "Type: Regression" >> $(METADATA) + @echo "TestTime: 5m" >> $(METADATA) + @echo "RunFor: cronie" >> $(METADATA) + @echo "Requires: cronie" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2+" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/tests/Can-t-remove-crontab-from-expired-accounts/PURPOSE b/tests/Can-t-remove-crontab-from-expired-accounts/PURPOSE new file mode 100644 index 0000000..addedc0 --- /dev/null +++ b/tests/Can-t-remove-crontab-from-expired-accounts/PURPOSE @@ -0,0 +1,3 @@ +PURPOSE of /CoreOS/cronie/Regression/Can-t-remove-crontab-from-expired-accounts +Description: Test for Can't remove crontab from expired accounts +Author: Karel Volny diff --git a/tests/Can-t-remove-crontab-from-expired-accounts/runtest.sh b/tests/Can-t-remove-crontab-from-expired-accounts/runtest.sh new file mode 100644 index 0000000..73d8914 --- /dev/null +++ b/tests/Can-t-remove-crontab-from-expired-accounts/runtest.sh @@ -0,0 +1,63 @@ +#!/bin/bash +# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /CoreOS/cronie/Regression/Can-t-remove-crontab-from-expired-accounts +# Description: Test for Can't remove crontab from expired accounts +# Author: Karel Volny +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2017 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# 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, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Include Beaker environment +. /usr/bin/rhts-environment.sh || exit 1 +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="cronie" +TestUser="usertest" +ct_file="/var/spool/cron/$TestUser" + +rlJournalStart + rlPhaseStartSetup + rlAssertRpm $PACKAGE + rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory" + rlRun "pushd $TmpDir" + rlRun "useradd $TestUser" 0 "Adding the testing user" + rlPhaseEnd + + rlPhaseStartTest + rlRun "echo '1 1 1 1 1 nonsense' | crontab -u $TestUser -" 0 "Setting up crontab for the testing user" + rlRun -s "crontab -u $TestUser -l" 0 "Checking the testing crontab" + rlAssertGrep "nonsense" $rlRun_LOG + rlRun "chage -E 1 $TestUser" 0 "Expiring the testing user account" + rlRun "crontab -u $TestUser -r" 0 "Removing the testing crontab" + rlAssertNotGrep "not allowed" $rlRun_LOG + rlRun -s "crontab -u $TestUser -l" 1 "Checking the testing crontab (should not exist)" + rlAssertGrep "no crontab for $TestUser" $rlRun_LOG + rlAssertNotGrep "not allowed" $rlRun_LOG + rlAssertNotExists "$ct_file" + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "userdel $TestUser" 0 "Deleting the testing user" + rlRun "popd" + rlRun "rm -rf $TmpDir $ct_file" 0 "Removing tmp directory and possible cruft" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/tests/Cron-does-uid-lookups-for-non-existent-users/Makefile b/tests/Cron-does-uid-lookups-for-non-existent-users/Makefile new file mode 100644 index 0000000..230390a --- /dev/null +++ b/tests/Cron-does-uid-lookups-for-non-existent-users/Makefile @@ -0,0 +1,62 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /CoreOS/cronie/Regression/Cron-does-uid-lookups-for-non-existent-users +# Description: Test for Cron does uid lookups for non-existent users +# Author: Vaclav Danek +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2015 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# 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, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +export TEST=/CoreOS/cronie/Regression/Cron-does-uid-lookups-for-non-existent-users +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE + +.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: Vaclav Danek " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: Test for Cron does uid lookups for non-existent users" >> $(METADATA) + @echo "Type: Regression" >> $(METADATA) + @echo "TestTime: 5m" >> $(METADATA) + @echo "RunFor: cronie" >> $(METADATA) + @echo "Requires: cronie" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2+" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/tests/Cron-does-uid-lookups-for-non-existent-users/PURPOSE b/tests/Cron-does-uid-lookups-for-non-existent-users/PURPOSE new file mode 100644 index 0000000..9d7cf13 --- /dev/null +++ b/tests/Cron-does-uid-lookups-for-non-existent-users/PURPOSE @@ -0,0 +1,4 @@ +PURPOSE of /CoreOS/cronie/Regression/Cron-does-uid-lookups-for-non-existent-users +Description: Test for Cron does uid lookups for non-existent users +Author: Vaclav Danek +Bug summary: Cron does uid lookups for non-existent users diff --git a/tests/Cron-does-uid-lookups-for-non-existent-users/runtest.sh b/tests/Cron-does-uid-lookups-for-non-existent-users/runtest.sh new file mode 100644 index 0000000..72329da --- /dev/null +++ b/tests/Cron-does-uid-lookups-for-non-existent-users/runtest.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /CoreOS/cronie/Regression/Cron-does-uid-lookups-for-non-existent-users +# Description: Test for Cron does uid lookups for non-existent users +# Author: Vaclav Danek +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2015 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# 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, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Include Beaker environment +. /usr/bin/rhts-environment.sh || exit 1 +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="cronie" + +rlJournalStart + rlPhaseStartSetup + rlAssertRpm $PACKAGE + rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory" + rlRun "pushd $TmpDir" + rlPhaseEnd + + rlPhaseStartTest + rlRun "sleep 61 | crontab -" 0 + rlRun -s "tail /var/log/cron" 0 + rlAssertNotGrep "ORPHAN (no passwd entry)" $rlRun_LOG + rm -f $rlRun_LOG + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "popd" + rlRun "rm -r $TmpDir" 0 "Removing tmp directory" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/tests/MAILTO-problem-with-anacron/Makefile b/tests/MAILTO-problem-with-anacron/Makefile new file mode 100644 index 0000000..cc54f39 --- /dev/null +++ b/tests/MAILTO-problem-with-anacron/Makefile @@ -0,0 +1,62 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /CoreOS/cronie/Regression/MAILTO-problem-with-anacron +# Description: Test for MAILTO problem with anacron +# Author: Karel Volny +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2017 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# 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, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +export TEST=/CoreOS/cronie/Regression/MAILTO-problem-with-anacron +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE anacrontab + +.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: Karel Volny " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: Test for MAILTO problem with anacron" >> $(METADATA) + @echo "Type: Regression" >> $(METADATA) + @echo "TestTime: 15m" >> $(METADATA) + @echo "RunFor: cronie" >> $(METADATA) + @echo "Requires: cronie" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2+" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/tests/MAILTO-problem-with-anacron/PURPOSE b/tests/MAILTO-problem-with-anacron/PURPOSE new file mode 100644 index 0000000..0eb365c --- /dev/null +++ b/tests/MAILTO-problem-with-anacron/PURPOSE @@ -0,0 +1,4 @@ +PURPOSE of /CoreOS/cronie/Regression/MAILTO-problem-with-anacron +Description: Test for MAILTO problem with anacron +Author: Karel Volny +Bug summary: MAILTO problem with anacron diff --git a/tests/MAILTO-problem-with-anacron/anacrontab b/tests/MAILTO-problem-with-anacron/anacrontab new file mode 100644 index 0000000..c672b71 --- /dev/null +++ b/tests/MAILTO-problem-with-anacron/anacrontab @@ -0,0 +1,5 @@ +SHELL=/bin/sh +PATH=/sbin:/bin:/usr/sbin:/usr/bin +MAILTO=testuser1 + +1 0 test echo "Hello anacron!" diff --git a/tests/MAILTO-problem-with-anacron/runtest.sh b/tests/MAILTO-problem-with-anacron/runtest.sh new file mode 100644 index 0000000..9504398 --- /dev/null +++ b/tests/MAILTO-problem-with-anacron/runtest.sh @@ -0,0 +1,155 @@ +#!/bin/bash +# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /CoreOS/cronie/Regression/MAILTO-problem-with-anacron +# Description: Test for MAILTO problem with anacron +# Author: Karel Volny +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2017 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# 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, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Include Beaker environment +. /usr/bin/rhts-environment.sh || exit 1 +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="cronie" +TestDir=$PWD + +rlJournalStart + rlPhaseStartSetup + rlAssertRpm $PACKAGE + rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory" + rlRun "pushd $TmpDir" + rlRun "useradd testuser1" 0 "Adding the testing user" + rlFileBackup --clean /var/spool/mail/root /var/log/cron + # stop cron not to interfere with our logs + rlServiceStop crond + rlPhaseEnd + + # email should be sent to user specified via MAILTO (testuser1) + rlPhaseStartTest anacronmail + rlRun "truncate --size 0 /var/spool/mail/testuser1" 0 "Truncating mail queue for the user 'testuser1'" + rlRun "truncate --size 0 /var/log/cron" 0 "Truncating cron log" + # DEBUG + echo "anacrontab:" + echo "***********" + cat ${TestDir}/anacrontab + rlRun "anacron -f -n -d -t ${TestDir}/anacrontab" 0 "Forcing anacron to run job" + sleep 5 + # DEBUG + echo "/var/spool/mail/testuser1:" + echo "**************************" + cat /var/spool/mail/testuser1 + rlAssertGrep "anacron" "/var/spool/mail/testuser1" + rlAssertGrep "To: testuser1" "/var/spool/mail/testuser1" + # DEBUG + echo "/var/log/cron:" + echo "**************" + cat /var/log/cron + rlAssertGrep "\(produced output\)" /var/log/cron + rlAssertNotGrep "not mailing" /var/log/cron -i + rlPhaseEnd + + # email should NOT be sent with empty MAILTO + rlPhaseStartTest noanacronmail-empty + rlRun "truncate --size 0 /var/spool/mail/root" 0 "Truncating mail queue for root" + rlRun "truncate --size 0 /var/log/cron" 0 "Truncating cron log" + rlRun "sed -i -e 's/MAILTO=testuser1/MAILTO=/' ${TestDir}/anacrontab" 0 "Removing mailto user from anacrontab" + # DEBUG + echo "anacrontab:" + echo "***********" + cat ${TestDir}/anacrontab + rlRun "anacron -f -n -d -t ${TestDir}/anacrontab" 0 "Forcing anacron to run job" + sleep 5 + # DEBUG + echo "/var/spool/mail/root:" + echo "*********************" + cat /var/spool/mail/root + rlAssertNotGrep "anacron" "/var/spool/mail/root" + # DEBUG + echo "/var/log/cron:" + echo "**************" + cat /var/log/cron + rlAssertGrep "\(produced output\)" /var/log/cron + rlAssertGrep "not mailing" /var/log/cron -i + rlPhaseEnd + + # email should be sent to nonexisting user double-doublequotes, as the string after '=' is treated literally + rlPhaseStartTest anacronmail-quotes + rlRun "truncate --size 0 /var/spool/mail/root" 0 "Truncating mail queue for root" + rlRun "truncate --size 0 /var/log/cron" 0 "Truncating cron log" + rlRun "sed -i -e 's/MAILTO=/MAILTO=\"\"/' ${TestDir}/anacrontab" 0 "Setting mailto to double quotes in anacrontab" + # DEBUG + echo "anacrontab:" + echo "***********" + cat ${TestDir}/anacrontab + rlRun "anacron -f -n -d -t ${TestDir}/anacrontab" 0 "Forcing anacron to run job" + sleep 5 + # DEBUG + echo "/var/spool/mail/root:" + echo "*********************" + cat /var/spool/mail/root + rlAssertGrep "anacron" "/var/spool/mail/root" + #rlAssertGrep "To: \"\"" "/var/spool/mail/root" + # ^ this doesn't work in Beaker for some reason, check the quotes in 'Received: ... for "";' + rlAssertGrep "for \"\"" "/var/spool/mail/root" + # DEBUG + echo "/var/log/cron:" + echo "**************" + cat /var/log/cron + rlAssertGrep "\(produced output\)" /var/log/cron + rlAssertNotGrep "not mailing" /var/log/cron -i + rlPhaseEnd + + # email should be sent to the user running anacron, when MAILTO is missing + rlPhaseStartTest anacronmail-missing + rlRun "truncate --size 0 /var/spool/mail/root" 0 "Truncating mail queue for root" + rlRun "truncate --size 0 /var/log/cron" 0 "Truncating cron log" + rlRun "sed -i -e '/MAILTO/d' ${TestDir}/anacrontab" 0 "Removing mailto from anacrontab" + # DEBUG + echo "anacrontab:" + echo "***********" + cat ${TestDir}/anacrontab + rlRun "anacron -f -n -d -t ${TestDir}/anacrontab" 0 "Forcing anacron to run job" + sleep 5 + # DEBUG + echo "/var/spool/mail/root:" + echo "*********************" + cat /var/spool/mail/root + rlAssertGrep "anacron" "/var/spool/mail/root" + # DEBUG + echo "/var/log/cron:" + echo "**************" + cat /var/log/cron + rlAssertGrep "\(produced output\)" /var/log/cron + rlAssertNotGrep "not mailing" /var/log/cron -i + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "userdel testuser1" + rlServiceRestore crond + rlFileRestore + rlRun "popd" + rlRun "rm -r $TmpDir" 0 "Removing tmp directory" + #avoid systemd failing to start crond due start-limit + sleep 10 + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/tests/Make-crontab-a-PIE/Makefile b/tests/Make-crontab-a-PIE/Makefile new file mode 100644 index 0000000..43e6a94 --- /dev/null +++ b/tests/Make-crontab-a-PIE/Makefile @@ -0,0 +1,63 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /CoreOS/Regression/Regression/Make-crontab-a-PIE +# Description: What the test does +# Author: Jakub Prokes +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2013 Red Hat, Inc. All rights reserved. +# +# 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/Regression/Make-crontab-a-PIE +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE + +.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: Jakub Prokes " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: What the test does" >> $(METADATA) + @echo "Type: Regression" >> $(METADATA) + @echo "TestTime: 5m" >> $(METADATA) + @echo "RunFor: cronie" >> $(METADATA) + @echo "Requires: cronie elfutils" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/tests/Make-crontab-a-PIE/PURPOSE b/tests/Make-crontab-a-PIE/PURPOSE new file mode 100644 index 0000000..2d2bf11 --- /dev/null +++ b/tests/Make-crontab-a-PIE/PURPOSE @@ -0,0 +1,3 @@ +PURPOSE of /CoreOS/Regression/Regression/Make-crontab-a-PIE +Description: What the test does +Author: Jakub Prokes diff --git a/tests/Make-crontab-a-PIE/runtest.sh b/tests/Make-crontab-a-PIE/runtest.sh new file mode 100644 index 0000000..b0341a1 --- /dev/null +++ b/tests/Make-crontab-a-PIE/runtest.sh @@ -0,0 +1,56 @@ +#!/bin/bash +# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /CoreOS/Regression/Regression/Make-crontab-a-PIE +# Description: What the test does +# Author: Jakub Prokes +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2013 Red Hat, Inc. All rights reserved. +# +# 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 + +PACKAGES="cronie vixie-cron" + +function myAssertRpms() { + rlRun "rpm -q $*" $((${#@}-1)) "One of required packages was found"; +} + + +rlJournalStart + rlPhaseStartSetup + myAssertRpms $PACKAGES + rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory" + rlRun "pushd $TmpDir" + rlPhaseEnd + + rlPhaseStartTest + rlRun "eu-readelf -h /usr/bin/crontab | grep -E 'Type:[[:space:]]+DYN[[:space:]]+\(Shared object file\)'" + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "popd" + rlRun "rm -r $TmpDir" 0 "Removing tmp directory" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/tests/anacron-segfaults-with-certain-config-data-2/Makefile b/tests/anacron-segfaults-with-certain-config-data-2/Makefile new file mode 100644 index 0000000..4323b82 --- /dev/null +++ b/tests/anacron-segfaults-with-certain-config-data-2/Makefile @@ -0,0 +1,62 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /CoreOS/cronie/Regression/anacron-segfaults-with-certain-config-data +# Description: try some invalid configs for anacron to check config parser +# Author: Jakub Prokes +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2014 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# 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, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +export TEST=/CoreOS/cronie/Regression/anacron-segfaults-with-certain-config-data-2 +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE configs + +.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: Jakub Prokes " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: try some invalid configs for anacron to check config parser" >> $(METADATA) + @echo "Type: Regression" >> $(METADATA) + @echo "TestTime: 5m" >> $(METADATA) + @echo "RunFor: cronie" >> $(METADATA) + @echo "Requires: cronie" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2+" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/tests/anacron-segfaults-with-certain-config-data-2/PURPOSE b/tests/anacron-segfaults-with-certain-config-data-2/PURPOSE new file mode 100644 index 0000000..6c8e9e2 --- /dev/null +++ b/tests/anacron-segfaults-with-certain-config-data-2/PURPOSE @@ -0,0 +1,3 @@ +PURPOSE of /CoreOS/cronie/Regression/anacron-segfaults-with-certain-config-data-2 +Description: try some invalid configs for anacron to check config parser +Author: Jakub Prokes diff --git a/tests/anacron-segfaults-with-certain-config-data-2/configs/scenario-01_1 b/tests/anacron-segfaults-with-certain-config-data-2/configs/scenario-01_1 new file mode 100644 index 0000000..3f10d0b --- /dev/null +++ b/tests/anacron-segfaults-with-certain-config-data-2/configs/scenario-01_1 @@ -0,0 +1,16 @@ +# /etc/anacrontab: configuration file for anacron + +# See anacron(8) and anacrontab(5) for details. + +SHELL=/bin/sh +PATH=/sbin:/bin:/usr/sbin:/usr/bin +MAILTO=root +# the maximal random delay added to the base delay of the jobs +RANDOM_DELAY=45 +# the jobs will be started during the following hours only +START_HOURS_RANGE=0 + +#period in days delay in minutes job-identifier command +1 5 cron.daily nice run-parts /etc/cron.daily +7 25 cron.weekly nice run-parts /etc/cron.weekly +@monthly 45 cron.monthly nice run-parts /etc/cron.monthly diff --git a/tests/anacron-segfaults-with-certain-config-data-2/configs/scenario-02_0 b/tests/anacron-segfaults-with-certain-config-data-2/configs/scenario-02_0 new file mode 100644 index 0000000..fee29eb --- /dev/null +++ b/tests/anacron-segfaults-with-certain-config-data-2/configs/scenario-02_0 @@ -0,0 +1,16 @@ +# /etc/anacrontab: configuration file for anacron + +# See anacron(8) and anacrontab(5) for details. + +SHELL=/bin/sh +PATH=/sbin:/bin:/usr/sbin:/usr/bin +MAILTO=root +# the maximal random delay added to the base delay of the jobs +RANDOM_DELAY=45 +# the jobs will be started during the following hours only +START_HOURS_RANGE=3-8 + +#period in days delay in minutes job-identifier command +1 5 cron.daily nice run-parts /etc/cron.daily +7 25 cron.weekly nice run-parts /etc/cron.weekly +@monthly 45 cron.monthly nice run-parts /etc/cron.monthly diff --git a/tests/anacron-segfaults-with-certain-config-data-2/configs/scenario-03_1 b/tests/anacron-segfaults-with-certain-config-data-2/configs/scenario-03_1 new file mode 100644 index 0000000..1767210 --- /dev/null +++ b/tests/anacron-segfaults-with-certain-config-data-2/configs/scenario-03_1 @@ -0,0 +1,18 @@ +# /etc/anacrontab: configuration file for anacron + +# See anacron(8) and anacrontab(5) for details. + +SHELL=/bin/sh +PATH=/sbin:/bin:/usr/sbin:/usr/bin +MAILTO=root +# the maximal random delay added to the base delay of the jobs +RANDOM_DELAY=45 +VAR=8 +# the jobs will be started during the following hours only +START_HOURS_RANGE=3-$VAR +#START_HOURS_RANGE=0 + +#period in days delay in minutes job-identifier command +1 5 cron.daily nice run-parts /etc/cron.daily +7 25 cron.weekly nice run-parts /etc/cron.weekly +@monthly 45 cron.monthly nice run-parts /etc/cron.monthly diff --git a/tests/anacron-segfaults-with-certain-config-data-2/configs/scenario-04_1 b/tests/anacron-segfaults-with-certain-config-data-2/configs/scenario-04_1 new file mode 100644 index 0000000..504a7cb --- /dev/null +++ b/tests/anacron-segfaults-with-certain-config-data-2/configs/scenario-04_1 @@ -0,0 +1,17 @@ +# /etc/anacrontab: configuration file for anacron + +# See anacron(8) and anacrontab(5) for details. + +SHELL=/bin/sh +PATH=/sbin:/bin:/usr/sbin:/usr/bin +MAILTO=root +# the maximal random delay added to the base delay of the jobs +RANDOM_DELAY=45 +%@$&=^^^^ +# the jobs will be started during the following hours only +START_HOURS_RANGE=%@$&=^^^^ + +#period in days delay in minutes job-identifier command +1 5 cron.daily nice run-parts /etc/cron.daily +7 25 cron.weekly nice run-parts /etc/cron.weekly +@monthly 45 cron.monthly nice run-parts /etc/cron.monthly diff --git a/tests/anacron-segfaults-with-certain-config-data-2/configs/scenario-05_1 b/tests/anacron-segfaults-with-certain-config-data-2/configs/scenario-05_1 new file mode 100644 index 0000000..c2d2b58 --- /dev/null +++ b/tests/anacron-segfaults-with-certain-config-data-2/configs/scenario-05_1 @@ -0,0 +1,14 @@ +# /etc/anacrontab: configuration file for anacron + +# See anacron(8) and anacrontab(5) for details. + +SHELL=/bin/sh +PATH=/sbin:/bin:/usr/sbin:/usr/bin +MAILTO=root +# the maximal random delay added to the base delay of the jobs +RANDOM_DELAY=%@$&=^^^^ + +#period in days delay in minutes job-identifier command +1 5 cron.daily nice run-parts /etc/cron.daily +7 25 cron.weekly nice run-parts /etc/cron.weekly +@monthly 45 cron.monthly nice run-parts /etc/cron.monthly diff --git a/tests/anacron-segfaults-with-certain-config-data-2/runtest.sh b/tests/anacron-segfaults-with-certain-config-data-2/runtest.sh new file mode 100644 index 0000000..bf78c58 --- /dev/null +++ b/tests/anacron-segfaults-with-certain-config-data-2/runtest.sh @@ -0,0 +1,66 @@ +#!/bin/bash +# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /CoreOS/cronie/Regression/anacron-segfaults-with-certain-config-data-2 +# Description: try some invalid configs for anacron to check config parser +# Author: Jakub Prokes +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2014 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# 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, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Include Beaker environment +. /usr/bin/rhts-environment.sh || exit 1 +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +assertRpms() { + rlRun "rpm -q $*" 0-$((${#@}-1)) "One of required packages was found"; + RC=$?; + [[ $RC -lt ${#@} ]] && return 0; + return $RC; +} + +PACKAGES="${PACKAGES:-cronie vixie-cron}" + +rlJournalStart + rlPhaseStartSetup + assertRpms $PACKAGES + rlPhaseEnd + + rlPhaseStartTest + for scenario in ./configs/*; do + [[ ! -f $scenario ]] && rlFail "$scenario isn't regular file"; + ## File name has 'special' format: scenario-X_Y where X is scenario number and Y is expected + ## exit code. And of course there must be some issues related to RHEL 5 :-) + if rlIsRHEL 5; then + rlRun "anacron -f -u -d -t $(readlink -f $scenario)" 0 "Testing $(basename ${scenario%_[0-9]})"; + else + if rlRun "anacron -T -t $scenario;" ${scenario##*_} "Verifying $(basename ${scenario%_[0-9]})"; then + rlRun "anacron -f -u -d -t $scenario" 0 "Testing $(basename ${scenario%_[0-9]})"; + else + [[ $? -eq 139 ]] && cat $scenario; + fi + fi + done + rlPhaseEnd + + rlPhaseStartCleanup + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/tests/anacron-segfaults-with-certain-config-data/Makefile b/tests/anacron-segfaults-with-certain-config-data/Makefile new file mode 100644 index 0000000..e4475ae --- /dev/null +++ b/tests/anacron-segfaults-with-certain-config-data/Makefile @@ -0,0 +1,62 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /CoreOS/cronie/Regression/anacron-segfaults-with-certain-config-data +# Description: Test for anacron segfaults with certain config data +# Author: Robin Hack +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2015 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# 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, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +export TEST=/CoreOS/cronie/Regression/anacron-segfaults-with-certain-config-data +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE core.sh + +.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: Robin Hack " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: Test for anacron segfaults with certain config data" >> $(METADATA) + @echo "Type: Regression" >> $(METADATA) + @echo "TestTime: 20m" >> $(METADATA) + @echo "RunFor: cronie" >> $(METADATA) + @echo "Requires: cronie" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2+" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/tests/anacron-segfaults-with-certain-config-data/PURPOSE b/tests/anacron-segfaults-with-certain-config-data/PURPOSE new file mode 100644 index 0000000..28d8f4b --- /dev/null +++ b/tests/anacron-segfaults-with-certain-config-data/PURPOSE @@ -0,0 +1,3 @@ +PURPOSE of /CoreOS/cronie/Regression/anacron-segfaults-with-certain-config-data +Description: anacron segfaults with certain config data +Author: Robin Hack diff --git a/tests/anacron-segfaults-with-certain-config-data/core.sh b/tests/anacron-segfaults-with-certain-config-data/core.sh new file mode 100644 index 0000000..21c0cc9 --- /dev/null +++ b/tests/anacron-segfaults-with-certain-config-data/core.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "$1" > /tmp/core.lock diff --git a/tests/anacron-segfaults-with-certain-config-data/runtest.sh b/tests/anacron-segfaults-with-certain-config-data/runtest.sh new file mode 100644 index 0000000..a2d784d --- /dev/null +++ b/tests/anacron-segfaults-with-certain-config-data/runtest.sh @@ -0,0 +1,76 @@ +#!/bin/bash +# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /CoreOS/cronie/Regression/anacron-segfaults-with-certain-config-data +# Description: Test for anacron segfaults with certain config data +# Author: Robin Hack +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2015 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# 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, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Include Beaker environment +. /usr/bin/rhts-environment.sh || exit 1 +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="cronie" + +rlJournalStart + rlPhaseStartSetup "Set anacron" + rlAssertRpm $PACKAGE + TESTDIR="${PWD}" + + rlFileBackup "/etc/anacrontab" + + rlRun "echo 'START_HOURS_RANGE=0' > /etc/anacrontab" + + # Prepare coredump handler + rlServiceStop crond + rlRun "chmod +x ${TESTDIR}/core.sh" + + rlRun "cat /proc/sys/kernel/core_pattern > /tmp/core_pattern" + rlRun "echo \"|${TESTDIR}/core.sh %e\" > /proc/sys/kernel/core_pattern" + rlPhaseEnd + + rlPhaseStartTest + rlRun "anacron" + + rlRun "sleep 2" 0 "Wait for kernel" + + # Anacron segfaults + rlAssertNotExists "/tmp/core.lock" + if [ -s "/tmp/core.lock" ]; then + rlAssertNotGrep "anacron" "/tmp/core.lock" + fi + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "cat /tmp/core_pattern > /proc/sys/kernel/core_pattern" + + rm -f /tmp/core.lock + rm -f /tmp/core_pattern + killall anacron + + rlFileRestore + rlServiceRestore crond + #avoid systemd failing to start crond due start-limit + sleep 10 + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/tests/config-parsing-issue/Makefile b/tests/config-parsing-issue/Makefile new file mode 100644 index 0000000..894a5c3 --- /dev/null +++ b/tests/config-parsing-issue/Makefile @@ -0,0 +1,62 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /CoreOS/cronie/Regression/config-parsing-issue +# Description: Test for cronie-anacron-1.4.4-14.el6.x86_64 doesn't like +# Author: Jakub Prokes +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2015 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# 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, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +export TEST=/CoreOS/cronie/Regression/config-parsing-issue +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE + +.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: Jakub Prokes " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: Test for cronie-anacron-1.4.4-14.el6.x86_64 doesn't like" >> $(METADATA) + @echo "Type: Regression" >> $(METADATA) + @echo "TestTime: 5m" >> $(METADATA) + @echo "RunFor: cronie" >> $(METADATA) + @echo "Requires: cronie-anacron" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2+" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/tests/config-parsing-issue/PURPOSE b/tests/config-parsing-issue/PURPOSE new file mode 100644 index 0000000..fe80c7e --- /dev/null +++ b/tests/config-parsing-issue/PURPOSE @@ -0,0 +1,4 @@ +PURPOSE of /CoreOS/cronie/Regression/config-parsing-issue +Description: Test for cronie-anacron-1.4.4-14.el6.x86_64 doesn't like +Author: Jakub Prokes +Bug summary: cronie-anacron-1.4.4-14.el6.x86_64 doesn't like its own /etc/anacrontab syntax diff --git a/tests/config-parsing-issue/runtest.sh b/tests/config-parsing-issue/runtest.sh new file mode 100644 index 0000000..d95adab --- /dev/null +++ b/tests/config-parsing-issue/runtest.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /CoreOS/cronie/Regression/config-parsing-issue +# Description: Test for cronie-anacron-1.4.4-14.el6.x86_64 doesn't like +# Author: Jakub Prokes +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2015 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# 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, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Include Beaker environment +. /usr/bin/rhts-environment.sh || exit 1 +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="cronie-anacron" + +rlJournalStart + rlPhaseStartSetup + rlAssertRpm $PACKAGE + rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory" + rlRun "pushd $TmpDir" + rlRun "grep '^SHELL' /etc/anacrontab"; + rlRun "grep '^PATH' /etc/anacrontab"; + rlRun "grep '^MAILTO' /etc/anacrontab"; + rlPhaseEnd + + rlPhaseStartTest + rlRun "anacron -T" + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "popd" + rlRun "rm -r $TmpDir" 0 "Removing tmp directory" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/tests/cron-daemon-fails-to-log-that-it-is-shutting-down/Makefile b/tests/cron-daemon-fails-to-log-that-it-is-shutting-down/Makefile new file mode 100644 index 0000000..c4d85ea --- /dev/null +++ b/tests/cron-daemon-fails-to-log-that-it-is-shutting-down/Makefile @@ -0,0 +1,62 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /CoreOS/cronie/Regression/cron-daemon-fails-to-log-that-it-is-shutting-down +# Description: Test for cron daemon fails to log that it is shutting down. +# Author: Robin Hack +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2015 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# 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, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +export TEST=/CoreOS/cronie/Regression/cron-daemon-fails-to-log-that-it-is-shutting-down +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE + +.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: Robin Hack " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: Test for cron daemon fails to log that it is shutting down." >> $(METADATA) + @echo "Type: Regression" >> $(METADATA) + @echo "TestTime: 20m" >> $(METADATA) + @echo "RunFor: cronie" >> $(METADATA) + @echo "Requires: cronie" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2+" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/tests/cron-daemon-fails-to-log-that-it-is-shutting-down/PURPOSE b/tests/cron-daemon-fails-to-log-that-it-is-shutting-down/PURPOSE new file mode 100644 index 0000000..4b459e8 --- /dev/null +++ b/tests/cron-daemon-fails-to-log-that-it-is-shutting-down/PURPOSE @@ -0,0 +1,4 @@ +PURPOSE of /CoreOS/cronie/Regression/cron-daemon-fails-to-log-that-it-is-shutting-down +Description: Test for cron daemon fails to log that it is shutting down. +Author: Robin Hack +Bug summary: cron daemon fails to log that it is shutting down. diff --git a/tests/cron-daemon-fails-to-log-that-it-is-shutting-down/runtest.sh b/tests/cron-daemon-fails-to-log-that-it-is-shutting-down/runtest.sh new file mode 100644 index 0000000..0aa147d --- /dev/null +++ b/tests/cron-daemon-fails-to-log-that-it-is-shutting-down/runtest.sh @@ -0,0 +1,59 @@ +#!/bin/bash +# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /CoreOS/cronie/Regression/cron-daemon-fails-to-log-that-it-is-shutting-down +# Description: Test for cron daemon fails to log that it is shutting down. +# Author: Robin Hack +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2015 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# 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, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Include Beaker environment +. /usr/bin/rhts-environment.sh || exit 1 +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="cronie" + +rlJournalStart + rlPhaseStartSetup + rlAssertRpm $PACKAGE + rlServiceStop crond + rlPhaseEnd + + rlPhaseStartTest + start_time=$(timedatectl | grep "Local time" | awk '{print$4" "$5}') + rlServiceStart crond + sleep 20 + rlRun "journalctl --since \"$start_time\" | grep \"(CRON) INFO\"" 0 "cron startup" + rlServiceStop crond + # give dbus and cronie some time to shut down... + sleep 20 + rlRun "journalctl --since \"$start_time\" | grep \"(CRON) INFO (Shutting down)\"" 0 "cron shutdown" + # DEBUG + journalctl _COMM=cron --since="$start_time" + rlPhaseEnd + + rlPhaseStartCleanup + rlServiceRestore crond + #avoid systemd failing to start crond due start-limit + sleep 10 + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/tests/crond-is-missing-RELRO-flags/Makefile b/tests/crond-is-missing-RELRO-flags/Makefile new file mode 100644 index 0000000..87a9651 --- /dev/null +++ b/tests/crond-is-missing-RELRO-flags/Makefile @@ -0,0 +1,63 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /CoreOS/cronie/Regression/crond-is-missing-RELRO-flags +# Description: Test for crond is missing RELRO flags +# Author: Martin Cermak +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2011 Red Hat, Inc. All rights reserved. +# +# 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/cronie/Regression/crond-is-missing-RELRO-flags +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE + +.PHONY: all install download clean + +run: $(FILES) build + ./runtest.sh + +build: $(BUILT_FILES) + chmod a+x runtest.sh + +clean: + rm -f *~ $(BUILT_FILES) + + +include /usr/share/rhts/lib/rhts-make.include + +$(METADATA): Makefile + @echo "Owner: Martin Cermak " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: Test for crond is missing RELRO flags" >> $(METADATA) + @echo "Type: Regression" >> $(METADATA) + @echo "TestTime: 15m" >> $(METADATA) + @echo "RunFor: cronie" >> $(METADATA) + @echo "Requires: cronie elfutils" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/tests/crond-is-missing-RELRO-flags/PURPOSE b/tests/crond-is-missing-RELRO-flags/PURPOSE new file mode 100644 index 0000000..1ea8ffc --- /dev/null +++ b/tests/crond-is-missing-RELRO-flags/PURPOSE @@ -0,0 +1,5 @@ +PURPOSE of /CoreOS/cronie/Regression/crond-is-missing-RELRO-flags +Description: Test for crond is missing RELRO flags +Author: Martin Cermak +Bug summary: crond is missing RELRO flags + diff --git a/tests/crond-is-missing-RELRO-flags/runtest.sh b/tests/crond-is-missing-RELRO-flags/runtest.sh new file mode 100644 index 0000000..c6b55df --- /dev/null +++ b/tests/crond-is-missing-RELRO-flags/runtest.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /CoreOS/cronie/Regression/crond-is-missing-RELRO-flags +# Description: Test for crond is missing RELRO flags +# Author: Martin Cermak +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2011 Red Hat, Inc. All rights reserved. +# +# 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 rhts environment +. /usr/bin/rhts-environment.sh || exit 1 +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="cronie" + +rlJournalStart + rlPhaseStartSetup + rlAssertRpm $PACKAGE + rlPhaseEnd + + rlPhaseStartTest + rlRun "eu-readelf -l /usr/sbin/crond | fgrep -q 'GNU_RELRO'" 0 "Binary was compiled with RELRO." + rlPhaseEnd +rlJournalEnd diff --git a/tests/crond-subtask-abnormal-termination-removes-pid-file-in-error/Makefile b/tests/crond-subtask-abnormal-termination-removes-pid-file-in-error/Makefile new file mode 100644 index 0000000..729126c --- /dev/null +++ b/tests/crond-subtask-abnormal-termination-removes-pid-file-in-error/Makefile @@ -0,0 +1,62 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /CoreOS/cronie/Regression/crond-subtask-abnormal-termination-removes-pid-file-in-error +# Description: Test for crond subtask abnormal termination removes pid +# Author: Robin Hack +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2015 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# 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, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +export TEST=/CoreOS/cronie/Regression/crond-subtask-abnormal-termination-removes-pid-file-in-error +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE crontab-job run-job.sh + +.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: Robin Hack " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: Test for crond subtask abnormal termination removes pid" >> $(METADATA) + @echo "Type: Regression" >> $(METADATA) + @echo "TestTime: 20m" >> $(METADATA) + @echo "RunFor: cronie" >> $(METADATA) + @echo "Requires: cronie" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2+" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/tests/crond-subtask-abnormal-termination-removes-pid-file-in-error/PURPOSE b/tests/crond-subtask-abnormal-termination-removes-pid-file-in-error/PURPOSE new file mode 100644 index 0000000..3bc1db0 --- /dev/null +++ b/tests/crond-subtask-abnormal-termination-removes-pid-file-in-error/PURPOSE @@ -0,0 +1,4 @@ +PURPOSE of /CoreOS/cronie/Regression/crond-subtask-abnormal-termination-removes-pid-file-in-error +Description: Test for crond subtask abnormal termination removes pid +Author: Robin Hack +Bug summary: crond subtask abnormal termination removes pid file in error diff --git a/tests/crond-subtask-abnormal-termination-removes-pid-file-in-error/crontab-job b/tests/crond-subtask-abnormal-termination-removes-pid-file-in-error/crontab-job new file mode 100644 index 0000000..390ab9b --- /dev/null +++ b/tests/crond-subtask-abnormal-termination-removes-pid-file-in-error/crontab-job @@ -0,0 +1 @@ +*/1 * * * * /tmp/run-job.sh diff --git a/tests/crond-subtask-abnormal-termination-removes-pid-file-in-error/run-job.sh b/tests/crond-subtask-abnormal-termination-removes-pid-file-in-error/run-job.sh new file mode 100644 index 0000000..265e8db --- /dev/null +++ b/tests/crond-subtask-abnormal-termination-removes-pid-file-in-error/run-job.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +if [ -s /tmp/run-job.lock ]; then + exit 0 +fi + +echo $PPID > /tmp/run-job.lock +sleep 1234567 +exit 0 diff --git a/tests/crond-subtask-abnormal-termination-removes-pid-file-in-error/runtest.sh b/tests/crond-subtask-abnormal-termination-removes-pid-file-in-error/runtest.sh new file mode 100644 index 0000000..caaa895 --- /dev/null +++ b/tests/crond-subtask-abnormal-termination-removes-pid-file-in-error/runtest.sh @@ -0,0 +1,79 @@ +#!/bin/bash +# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /CoreOS/cronie/Regression/crond-subtask-abnormal-termination-removes-pid-file-in-error +# Description: Test for crond subtask abnormal termination removes pid +# Author: Robin Hack +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2015 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# 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, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Include Beaker environment +. /usr/bin/rhts-environment.sh || exit 1 +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="cronie" + +rlJournalStart + rlPhaseStartSetup + rlAssertRpm $PACKAGE + + rlRun "cp ./run-job.sh /tmp/" + rlRun "chmod +x /tmp/run-job.sh" + rm -f /tmp/run-job.lock + + rlServiceStop crond + rlServiceStart crond + rlRun "crontab -u root ./crontab-job" + rlRun "sleep 60" 0 "Wait for cron job to run" + rlPhaseEnd + + rlPhaseStartTest + if [ -s /var/run/crond.pid ]; then + rlPass "Crond pid file exists"; + else + rlFail "Cront pid file doesn't exists or is empty" + fi + + # /tmp/run-job.lock contains PPID of my job + rlRun "kill -SIGTERM $(cat /tmp/run-job.lock)" + + # Cut and pasta! Check file again! + # We love boiler plate code in our tests! + if [ -s /var/run/crond.pid ]; then + rlPass "Crond pid file exists"; + else + rlFail "Cront pid file doesn't exists or is empty" + fi + rlPhaseEnd + + rlPhaseStartCleanup + killall sleep + crontab -u root -r + rm -f /tmp/run-job.sh + rm -f /tmp/run-job.lock + + rlServiceStop crond + rlServiceRestore crond + #avoid systemd failing to start crond due start-limit + sleep 10 + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/tests/cronie-jobs-environment/Makefile b/tests/cronie-jobs-environment/Makefile new file mode 100644 index 0000000..c2a43a8 --- /dev/null +++ b/tests/cronie-jobs-environment/Makefile @@ -0,0 +1,63 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /CoreOS/cronie/Regression/cronie-jobs-environment +# Description: testing EUID with jobs are executed and if LANG is correctly set +# Author: Jakub Prokes +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2013 Red Hat, Inc. All rights reserved. +# +# 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/cronie/Regression/cronie-jobs-environment +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE libfaketime-0.9.1.tar.gz crontab.temp cron_test.sh + +.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: Jakub Prokes " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: testing EUID with jobs are executed and if LANG is correctly set" >> $(METADATA) + @echo "Type: Regression" >> $(METADATA) + @echo "TestTime: 10m" >> $(METADATA) + @echo "RunFor: cronie" >> $(METADATA) + @echo "Requires: cronie" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/tests/cronie-jobs-environment/PURPOSE b/tests/cronie-jobs-environment/PURPOSE new file mode 100644 index 0000000..6ef4539 --- /dev/null +++ b/tests/cronie-jobs-environment/PURPOSE @@ -0,0 +1,3 @@ +PURPOSE of /CoreOS/cronie/Regression/cronie-jobs-environment +Description: testing EUID with jobs are executed and if LANG is correctly set +Author: Jakub Prokes diff --git a/tests/cronie-jobs-environment/cron_test.sh b/tests/cronie-jobs-environment/cron_test.sh new file mode 100644 index 0000000..6a82d15 --- /dev/null +++ b/tests/cronie-jobs-environment/cron_test.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +printf "LANG=$LANG\n" > /tmp/cronie-jobs-environment.log; +printf "EUID=$EUID\n" >> /tmp/cronie-jobs-environment.log; + diff --git a/tests/cronie-jobs-environment/crontab.temp b/tests/cronie-jobs-environment/crontab.temp new file mode 100644 index 0000000..643879d --- /dev/null +++ b/tests/cronie-jobs-environment/crontab.temp @@ -0,0 +1,12 @@ +# Example of job definition: +# .---------------- minute (0 - 59) +# | .------------- hour (0 - 23) +# | | .---------- day of month (1 - 31) +# | | | .------- month (1 - 12) OR jan,feb,mar,apr ... +# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat +# | | | | | +# * * * * * command to be executed + +CRON_CORRECT_MAIL_HEADER=1 + +* * * * * %TMPDIR/cron_test.sh diff --git a/tests/cronie-jobs-environment/libfaketime-0.9.1.tar.gz b/tests/cronie-jobs-environment/libfaketime-0.9.1.tar.gz new file mode 100644 index 0000000..9913d21 Binary files /dev/null and b/tests/cronie-jobs-environment/libfaketime-0.9.1.tar.gz differ diff --git a/tests/cronie-jobs-environment/runtest.sh b/tests/cronie-jobs-environment/runtest.sh new file mode 100644 index 0000000..c6d83ac --- /dev/null +++ b/tests/cronie-jobs-environment/runtest.sh @@ -0,0 +1,124 @@ +#!/bin/bash +# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /CoreOS/cronie/Regression/cronie-jobs-environment +# Description: testing EUID with jobs are executed and if LANG is correctly set +# Author: Jakub Prokes +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2013 Red Hat, Inc. All rights reserved. +# +# 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 + + +## Is nice to know when things going wrong +trap 'errorHandler ${LINENO}' ERR; +function errorHandler() { + local code="${?}"; + local lineNO="$1"; + + case $code in + 127) + rlFail "Command not found on line $lineNO" + ;; + *) + rlFail "Unhandled error $code near line $lineNO"; + ;; + esac +} + +function makeUser() { + local userName="$(tr -dc "[:lower:]" < /dev/urandom | head -c 5 | sed 's/^/qa_/')"; + while getent passwd $userName; do + userName="$(tr -dc "[:lower:]" < /dev/urandom | head -c 5 | sed 's/^/qa_/')"; + done + useradd -d $tmpDir $userName; + echo $userName; +} + + +PACKAGE="cronie" +declare -r LIBFAKETTIMEPACKAGE="libfaketime-0.9.1.tar.gz"; +declare -r LIBFAKETIME="libfaketime.so.1"; + +rlJournalStart + rlPhaseStartSetup "Setup test environment" + rlAssertRpm $PACKAGE + rlRun "tmpDir=\$(mktemp -d)" 0 "Creating tmp directory"; + testDir="$(pwd)"; + rlRun "chmod 755 $tmpDir" 0 "Setting permissions for tmp directory"; + ls -lahdZ $tmpDir; + rlRun "pushd $tmpDir" + testUser="$(makeUser)"; + rlRun "getent passwd $testUser" 0 "Test user $testUser created"; + rlServiceStop crond; + rlPhaseEnd + + rlPhaseStartSetup "Prepare libfaketime"; + rlRun "cp ${testDir}/$LIBFAKETTIMEPACKAGE ./" 0 "Get library sources"; + rlRun "tar -xvzf $LIBFAKETTIMEPACKAGE" 0 "Unpack library sources"; + pushd ${LIBFAKETTIMEPACKAGE%.tar.gz}; + rlRun "make &>/dev/null" 0 "Building library from sources"; + rlRun "cp ./src/$LIBFAKETIME ../" 0 "Coping library to working directory"; + popd; + LD_PRELOAD=./libfaketime.so.1 FAKETIME='1994-07-29 12:00:01' date +%G | { year="$(cat)"; [[ $year -eq 1994 ]]; }; + rlAssert0 "Library preloading working well" $?; + rlPhaseEnd + + rlPhaseStartSetup "Prepare tests"; + rlRun "sed 's#%TMPDIR#$tmpDir#' $testDir/crontab.temp > crontab.source" #0 "Crontab prepared from template"; + rlRun "crontab -u $testUser crontab.source" 0 "Set crontab for test user"; + crontab -lu $testUser; + rlRun "cp $testDir/cron_test.sh ./" 0 "Copyed script for cron job"; + rlRun "chmod a+x cron_test.sh" 0 "Permissions to executed set"; + rlRun "[[ -e /var/spool/mail/$testUser ]] && printf '' > /var/spool/mail/$testUser" 0 "Clean up mails" + rlLog "Execute crond with faked time"; + LD_PRELOAD=./libfaketime.so.1 FAKETIME='@1994-07-29 12:12:50' /usr/sbin/crond -n -x sch & + cronPID=$!; + pstree -Aph + rlRun "kill -0 $cronPID" 0 "crond is running"; + rlLog "Security timeout for 30 sec to ensure all configs are loaded and crontab is succesfully processed"; + sleep 30; + rlPhaseEnd + + rlPhaseStartTest "cronie drops \$LANG and never passes it on to jobs run" + rlRun "[[ $(sed -n '/^LANG/s/LANG=//p' /tmp/cronie-jobs-environment.log) = $LANG ]]" 0 "LANG is set" + rlPhaseEnd + + rlPhaseStartTest "cronie doesn't drop privileges before popen" + rlRun "[[ $(sed -n '/^EUID/s/EUID=//p' /tmp/cronie-jobs-environment.log) -eq $(id -u $testUser) ]]" 0 \ + "Crontab is executed with correct EUID"; + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "kill $cronPID" 0 "Terminating crond" + rlRun "crontab -ru $testUser" 0 "Crontab removed" + rlRun "popd" + rlRun "rm -r $tmpDir" 0 "Removing tmp directory" + rlRun "userdel -rf $testUser"; + rlServiceRestore crond; + #avoid systemd failing to start crond due start-limit + sleep 10 + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/tests/crontab-can-invoke-lookup-for-nonexisted-user/Makefile b/tests/crontab-can-invoke-lookup-for-nonexisted-user/Makefile new file mode 100644 index 0000000..78b55ab --- /dev/null +++ b/tests/crontab-can-invoke-lookup-for-nonexisted-user/Makefile @@ -0,0 +1,62 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /CoreOS/cronie/Regression/crontab-can-invoke-lookup-for-nonexisted-user +# Description: Test for Cron does uid lookups for non-existent users +# Author: Jakub Prokes +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2016 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# 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, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +export TEST=/CoreOS/cronie/Regression/crontab-can-invoke-lookup-for-nonexisted-user +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE + +.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: Jakub Prokes " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: Test for Cron does uid lookups for non-existent users" >> $(METADATA) + @echo "Type: Regression" >> $(METADATA) + @echo "TestTime: 10m" >> $(METADATA) + @echo "RunFor: cronie" >> $(METADATA) + @echo "Requires: cronie" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2+" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/tests/crontab-can-invoke-lookup-for-nonexisted-user/PURPOSE b/tests/crontab-can-invoke-lookup-for-nonexisted-user/PURPOSE new file mode 100644 index 0000000..056f3fb --- /dev/null +++ b/tests/crontab-can-invoke-lookup-for-nonexisted-user/PURPOSE @@ -0,0 +1,4 @@ +PURPOSE of /CoreOS/cronie/Regression/crontab-can-invoke-lookup-for-nonexisted-user +Description: Test for Cron does uid lookups for non-existent users +Author: Jakub Prokes +Bug summary: Cron does uid lookups for non-existent users diff --git a/tests/crontab-can-invoke-lookup-for-nonexisted-user/runtest.sh b/tests/crontab-can-invoke-lookup-for-nonexisted-user/runtest.sh new file mode 100644 index 0000000..7387dd1 --- /dev/null +++ b/tests/crontab-can-invoke-lookup-for-nonexisted-user/runtest.sh @@ -0,0 +1,102 @@ +#!/bin/bash +# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k ft=beakerlib +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /CoreOS/cronie/Regression/crontab-can-invoke-lookup-for-nonexisted-user +# Description: Test for Cron does uid lookups for non-existent users +# Author: Jakub Prokes +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2016 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# 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, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Include Beaker environment +. /usr/bin/rhts-environment.sh || exit 1 +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="cronie" +declare -ri EXIT_FAILURE=1; +declare -ri EXIT_SUCCESS=0; +declare -r reportAllErrors=no; + +function isTrue() { + local string="$@"; + local oldOpt="shopt -p nocasematch"; + local -i rc=1; + + shopt -s nocasematch; + [[ -z "$string" ]] && return 1; + + case $string in + yes) rc=0;; + true) rc=0;; + ano) rc=0;; + 1) rc=0;; + jo) rc=0;; + yeah) rc=0;; + y) rc=0;; + a) rc=0;; + esac; + eval $oldOpt; + return $rc; +} + +## Is nice to know when things going wrong +function errorHandler() { + local code="${?}"; + local lineNO="$1"; + + case $code in + 127) + rlFail "Command not found on line $lineNO" + ;; + *) + isTrue $reportAllErrors && rlFail "Unhandled error $code near line $lineNO"; + ;; + esac +} + + +rlJournalStart + trap 'errorHandler ${LINENO}' ERR; + rlPhaseStart FAIL "Setup" + rlAssertRpm $PACKAGE; + rlRun "rlServiceStop 'crond'" + echo > /var/log/cron + rlRun "rlServiceStart 'crond'" + rlPhaseEnd + + rlPhaseStartTest + rlRun "sleep 61 | crontab -" & + sleep 5 + fileName="$(ls /var/spool/cron/ | grep 'tmp' | head -n 1)"; + ls -lah /var/spool/cron/; + rlRun "[[ -n '$fileName' ]]" 0 "$fileName found"; + rlRun "wait"; + rlRun "grep 'ORPHAN' /var/log/cron | grep '$fileName'" 1 ; + tail -n 20 /var/log/cron; + rlPhaseEnd + + rlPhaseStart WARN "Cleanup" + rlRun "rlServiceRestore 'crond'" + #avoid systemd failing to start crond due start-limit + sleep 10 + rlPhaseEnd + rlJournalPrintText + trap - ERR; +rlJournalEnd diff --git a/tests/crontab-has-wrong-permissions/Makefile b/tests/crontab-has-wrong-permissions/Makefile new file mode 100644 index 0000000..fd02095 --- /dev/null +++ b/tests/crontab-has-wrong-permissions/Makefile @@ -0,0 +1,63 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /CoreOS/cronie/Regression/crontab-has-wrong-permissions +# Description: What the test does +# Author: Jakub Prokes +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2013 Red Hat, Inc. All rights reserved. +# +# 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/cronie/Regression/crontab-has-wrong-permissions +export TESTVERSION=1.1 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE + +.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: Jakub Prokes " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: What the test does" >> $(METADATA) + @echo "Type: Regression" >> $(METADATA) + @echo "TestTime: 5m" >> $(METADATA) + @echo "RunFor: cronie" >> $(METADATA) + @echo "Requires: cronie" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/tests/crontab-has-wrong-permissions/PURPOSE b/tests/crontab-has-wrong-permissions/PURPOSE new file mode 100644 index 0000000..61f54cb --- /dev/null +++ b/tests/crontab-has-wrong-permissions/PURPOSE @@ -0,0 +1,3 @@ +PURPOSE of /CoreOS/cronie/Regression/crontab-has-wrong-permissions +Description: What the test does +Author: Jakub Prokes diff --git a/tests/crontab-has-wrong-permissions/runtest.sh b/tests/crontab-has-wrong-permissions/runtest.sh new file mode 100644 index 0000000..6a72dd2 --- /dev/null +++ b/tests/crontab-has-wrong-permissions/runtest.sh @@ -0,0 +1,56 @@ +#!/bin/bash +# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /CoreOS/cronie/Regression/crontab-has-wrong-permissions +# Description: What the test does +# Author: Jakub Prokes +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2013 Red Hat, Inc. All rights reserved. +# +# 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 + +PACKAGES="cronie vixie-cron" + +function myAssertRpms() { + rlRun "rpm -q $*" $((${#@}-1)) "One of required packages was found"; +} + + +rlJournalStart + rlPhaseStartSetup + myAssertRpms $PACKAGES + rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory" + rlRun "pushd $TmpDir" + rlPhaseEnd + + rlPhaseStartTest + rlRun "[[ $(stat /usr/bin/crontab -c \"%a\") -eq 4755 ]]" + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "popd" + rlRun "rm -r $TmpDir" 0 "Removing tmp directory" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/tests/echos-OK-twice-in-init-script/Makefile b/tests/echos-OK-twice-in-init-script/Makefile new file mode 100644 index 0000000..dec6383 --- /dev/null +++ b/tests/echos-OK-twice-in-init-script/Makefile @@ -0,0 +1,63 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /CoreOS/cronie/Regression/echos-OK-twice-in-init-script +# Description: Test for echos "OK" twice in init script +# Author: Martin Cermak +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2011 Red Hat, Inc. All rights reserved. +# +# 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/cronie/Regression/echos-OK-twice-in-init-script +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE + +.PHONY: all install download clean + +run: $(FILES) build + ./runtest.sh + +build: $(BUILT_FILES) + chmod a+x runtest.sh + +clean: + rm -f *~ $(BUILT_FILES) + + +include /usr/share/rhts/lib/rhts-make.include + +$(METADATA): Makefile + @echo "Owner: Martin Cermak " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: Test for echos \"OK\" twice in init script" >> $(METADATA) + @echo "Type: Regression" >> $(METADATA) + @echo "TestTime: 15m" >> $(METADATA) + @echo "RunFor: cronie" >> $(METADATA) + @echo "Requires: cronie" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/tests/echos-OK-twice-in-init-script/PURPOSE b/tests/echos-OK-twice-in-init-script/PURPOSE new file mode 100644 index 0000000..9a334d7 --- /dev/null +++ b/tests/echos-OK-twice-in-init-script/PURPOSE @@ -0,0 +1,4 @@ +PURPOSE of /CoreOS/cronie/Regression/echos-OK-twice-in-init-script +Description: Test for echos "OK" twice in init script +Author: Martin Cermak + diff --git a/tests/echos-OK-twice-in-init-script/runtest.sh b/tests/echos-OK-twice-in-init-script/runtest.sh new file mode 100644 index 0000000..54afa80 --- /dev/null +++ b/tests/echos-OK-twice-in-init-script/runtest.sh @@ -0,0 +1,76 @@ +#!/bin/bash +# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /CoreOS/cronie/Regression/echos-OK-twice-in-init-script +# Description: Test for echos "OK" twice in init script +# Author: Martin Cermak +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2011 Red Hat, Inc. All rights reserved. +# +# 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 rhts environment +. /usr/bin/rhts-environment.sh +. /usr/lib/beakerlib/beakerlib.sh + +PACKAGE="cronie" + +rlJournalStart + rlPhaseStartSetup + rlAssertRpm $PACKAGE + rlRun "TEMPDIR=\`mktemp -d\`" 0 "Creating tmp directory" + rlRun "pushd $TEMPDIR" + + rlFileBackup "/etc/rc.d/init.d/crond" + rlServiceStop crond + +cat > /etc/rc.d/init.d/functions2 <> $TEMPDIR/log.txt +} +EOF1 + rlRun "cat /etc/rc.d/init.d/functions2" + + sed -i "s/^\..*$/\0\n\. \/etc\/rc\.d\/init\.d\/functions2/" /etc/rc.d/init.d/crond + rlRun "grep ^\\\. /etc/rc.d/init.d/crond" + rlPhaseEnd + + rlPhaseStartTest + rlAssertNotExists log.txt + rlServiceStart crond + rlAssertExists log.txt + + rlRun "TIMES_PRINTED_OK=`grep OK log.txt | wc -l`" + rlRun "test $TIMES_PRINTED_OK -eq 1" + + rlServiceStop crond + rlPhaseEnd + + rlPhaseStartCleanup + rlBundleLogs TESTLOGS /etc/rc.d/init.d/functions2 /etc/rc.d/init.d/crond + rlRun "rm -f /etc/rc.d/init.d/functions2" + rlFileRestore + rlServiceRestore crond + rlRun "popd" + rlRun "rm -r $TEMPDIR" 0 "Removing tmp directory" + #avoid systemd failing to start crond due start-limit + sleep 10 + rlPhaseEnd +rlJournalEnd diff --git a/tests/init-script-failure/Makefile b/tests/init-script-failure/Makefile new file mode 100644 index 0000000..49b556c --- /dev/null +++ b/tests/init-script-failure/Makefile @@ -0,0 +1,63 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /CoreOS/cronie/Regression/init-script-failure +# Description: Testing some init script failures +# Author: Jakub Prokes +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2013 Red Hat, Inc. All rights reserved. +# +# 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/cronie/Regression/init-script-failure +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE + +.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: Jakub Prokes " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: Testing some init script failures" >> $(METADATA) + @echo "Type: Regression" >> $(METADATA) + @echo "TestTime: 5m" >> $(METADATA) + @echo "RunFor: cronie" >> $(METADATA) + @echo "Requires: cronie" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/tests/init-script-failure/PURPOSE b/tests/init-script-failure/PURPOSE new file mode 100644 index 0000000..81de15d --- /dev/null +++ b/tests/init-script-failure/PURPOSE @@ -0,0 +1,3 @@ +PURPOSE of /CoreOS/cronie/Regression/init-script-failure +Description: Testing some init script failures +Author: Jakub Prokes diff --git a/tests/init-script-failure/runtest.sh b/tests/init-script-failure/runtest.sh new file mode 100644 index 0000000..c0f6d02 --- /dev/null +++ b/tests/init-script-failure/runtest.sh @@ -0,0 +1,73 @@ +#!/bin/bash +# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /CoreOS/cronie/Regression/init-script-failure +# Description: Testing some init script failures +# Author: Jakub Prokes +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2013 Red Hat, Inc. All rights reserved. +# +# 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="cronie" + +function makeUser() { + local userName="$(tr -dc "[:lower:]" < /dev/urandom | head -c 5 | sed 's/^/qa_/')"; + while getent passwd $userName; do + userName="$(tr -dc "[:lower:]" < /dev/urandom | head -c 5 | sed 's/^/qa_/')"; + done + useradd -d $tmpDir $userName; + echo $userName; +} + +rlJournalStart + rlPhaseStartSetup + rlAssertRpm $PACKAGE + rlServiceStop crond + rlRun "tmpDir=\$(mktemp -d)" 0 "Creating tmp directory"; + testUser="$(makeUser)"; + rlPhaseEnd + + rlPhaseStartTest "Service restart needlessly reports failure" + rlRun -s "service crond restart" + rlAssertNotGrep "FAILED" $rlRun_LOG + rlPhaseEnd + + if ! rpm -q systemd &>/dev/null; then + rlPhaseStartTest "Check service restart exit code" + su -l $testUser -c "service crond restart"; + rlAssertEquals "Expected result of call initscript by unprivileged user is 4" $? 4 + rlPhaseEnd + fi + + rlPhaseStartCleanup + rm -f $rlRun_LOG + rm -rf $tmpDir; + userdel -rf $testUser; + rlServiceRestore crond + #avoid systemd failing to start crond due start-limit + sleep 10 + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/tests/init-scripts-LSB/Makefile b/tests/init-scripts-LSB/Makefile new file mode 100644 index 0000000..712f909 --- /dev/null +++ b/tests/init-scripts-LSB/Makefile @@ -0,0 +1,62 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /CoreOS/cronie/Sanity/init-script-LSB +# Description: Init script should meet LSB specifications +# Author: Yulia Kopkova +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2009 Red Hat, Inc. All rights reserved. +# +# 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/cronie/Sanity/init-script-LSB +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE + +.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: Petr Sklenar " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: Init script should meet LSB specifications" >> $(METADATA) + @echo "Type: Sanity" >> $(METADATA) + @echo "TestTime: 5m" >> $(METADATA) + @echo "RunFor: cronie" >> $(METADATA) + @echo "Requires: cronie" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + rhts-lint $(METADATA) diff --git a/tests/init-scripts-LSB/PURPOSE b/tests/init-scripts-LSB/PURPOSE new file mode 100644 index 0000000..26efe1c --- /dev/null +++ b/tests/init-scripts-LSB/PURPOSE @@ -0,0 +1,3 @@ +PURPOSE of /CoreOS/cronie/Sanity/init-script-LSB +Description: Init script should meet LSB specifications +Author: Yulia Kopkova diff --git a/tests/init-scripts-LSB/runtest.sh b/tests/init-scripts-LSB/runtest.sh new file mode 100644 index 0000000..7b72ea7 --- /dev/null +++ b/tests/init-scripts-LSB/runtest.sh @@ -0,0 +1,186 @@ +#!/bin/bash +# vim: dict=/usr/share/rhts-library/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /CoreOS/cronie/Sanity/init-script-LSB +# Description: Init script should meet LSB specifications +# Author: Jan Scotka , Yulia Kopkova +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2009 Red Hat, Inc. All rights reserved. +# +# 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 rhts environment +. /usr/bin/rhts-environment.sh +. /usr/share/rhts-library/rhtslib.sh + +PACKAGE="cronie" + +SERVICE="crond"; +reportAllErrors=no; + +function isTrue() { + local string="$@"; + local oldOpt="shopt -p nocasematch"; + local -i rc=1; + + shopt -s nocasematch; + [[ -z "$string" ]] && return 1; + + case $string in + yes) rc=0;; + true) rc=0;; + ano) rc=0;; + 1) rc=0;; + jo) rc=0;; + yeah) rc=0;; + y) rc=0;; + a) rc=0;; + esac; + eval $oldOpt; + return $rc; +} + +isTrue no && echo Yes || echo No; + +## Is nice to know when things going wrong +function errorHandler() { + local code="${?}"; + local lineNO="$1"; + + case $code in + 127) + rlFail "Command not found on line $lineNO" + ;; + *) + isTrue $reportAllErrors && rlFail "Unhandled error $code near line $lineNO"; + ;; + esac +} + +function getUserName() { + local userName="qa_$(tr -dc "[:lower:]" < /dev/urandom | head -c 5)"; + echo "$userName" >&2;⏎ + if getent passwd $userName &>/dev/null; then + getUserName; + return $? + fi + if [[ -n "$userName" ]]; then + echo "$userName"; + return $EXIT_SUCCESS; + else + return $EXIT_FAILURE; + fi +} + + +rlJournalStart +trap 'errorHandler ${LINENO}' ERR; + rlPhaseStartSetup + rlAssertRpm $PACKAGE + rlRun "tmpDir=\$(mktemp -d)" 0 "Creating tmp directory"; + testUser="$(getUserName || rlDie "Cannot get username")" + rlLog "${testUser}" + rlRun "useradd -d $tmpDir $testUser"; + pushd $tmpDir; + rlServiceStop $SERVICE + rlPhaseEnd + + rlPhaseStartTest "starts the service" + rlRun "service $SERVICE start" 0 " Service must start without problem" + rlRun "service $SERVICE status" 0 " Then Status command " + rlRun "service $SERVICE start" 0 " Already started service " + rlRun "service $SERVICE status" 0 " Again status command " + rlPhaseEnd + + rlPhaseStartTest "restart the service" + firstPid=$(ps h -C $SERVICE -o pid); + rlRun "service $SERVICE restart" 0 " Restarting of service" + rlRun "service $SERVICE status" 0 " Status command " + secondPid=$(ps h -C $SERVICE -o pid); + rlRun "[[ -n $firstPid ]] && [[ -n $secondPid ]] && [[ $firstPid -ne $secondPid ]]" 0 \ + "Pids are different after restart"; + rlPhaseEnd + + rlPhaseStartTest "stop the service" + rlRun "service $SERVICE stop" 0 " Stopping service " + rlRun "service $SERVICE status" 3 " Status of stopped service " || true + rlRun "service $SERVICE stop" 0 " Stopping service again " + rlRun "service $SERVICE status" 3 " Status of stopped service " || true + rlPhaseEnd + + if ! rlIsRHEL ">=7"; then + rlPhaseStartTest "pid file" + rlServiceStart $SERVICE + rlAssertExists "/var/run/$SERVICE.pid" "Pid file /var/run/$SERVICE.pid must exist" + sleep 1 + rlRun "kill -9 `pidof crond`" 0 "Kill $SERVICE" + sleep 10 + rlRun "service $SERVICE status" 1 " Existing pid file, but service not started " || true; + sleep 1 + rlRun "rm -fv /var/run/$SERVICE.pid" 0 "Remove .pid file" + rlPhaseEnd + + rlPhaseStartTest "lock file" + rlAssertExists "/var/lock/subsys/$SERVICE" "Lock file /var/lock/subsys/$SERVICE must exist" + rlRun "service $SERVICE status" 2 " Existing lock file, but service not started " || true; + rlServiceStop $SERVICE + rlPhaseEnd + fi + + rlPhaseStartTest "insufficient rights" + rlRun "service $SERVICE start " 0 " Starting service for restarting under nonpriv user " + rlRun "su $testUser -c 'service $SERVICE restart'" \ + $(rpm -q systemd &>/dev/null && echo 1 || echo 4) \ + "Insufficient rights, restarting service under nonprivileged user must fail"; + rlPhaseEnd + + rlPhaseStartTest "operations" + rlRun "service $SERVICE start" 0 " Service have to implement start function " + rlRun "service $SERVICE restart" 0 " Service have to implement restart function " + rlRun "service $SERVICE status" 0 " Service have to implement status function " + rlRun "service $SERVICE reload" 0 " Service have to implement reload function " + rlRun "service $SERVICE force-reload" 0 " Service have to implement force-reload function " + rlRun "service $SERVICE condrestart" 0 " Service have to implement condrestart function " + if ! rlIsRHEL ">=7"; then + rlRun "service $SERVICE try-restart" 0 " Service have to implement try-restart function " + fi + rlPhaseEnd + + rlPhaseStartTest "nonexisting operations" + rlRun "service $SERVICE noexistop" 2 " Testing proper return code when nonexisting function"; + rlRun "service $SERVICE stopex" 2 " Testing proper return code when nonexisting function"; + rlRun "service $SERVICE foo" 2 " Testing proper return code when nonexisting function" || true + rlPhaseEnd + + rlPhaseEnd + + rlPhaseStartCleanup + rlServiceRestore $SERVICE + rlRun "getent passwd $testUser"; + popd tmpDir; + rlRun "userdel -fr $testUser" 0 "Remove test user"; +# rlRun "rm -rf $testDir"; + #avoid systemd failing to start crond due start-limit + sleep 10 + rlPhaseEnd + +rlJournalPrintText +trap - ERR; +rlJournalEnd diff --git a/tests/ldap-users/Makefile b/tests/ldap-users/Makefile new file mode 100644 index 0000000..e1967a1 --- /dev/null +++ b/tests/ldap-users/Makefile @@ -0,0 +1,63 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /CoreOS/cronie/Regression/ldap-users +# Description: Test for cronie not creating jobs for ldap users if ldap +# Author: Jakub Prokes +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2016 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# 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, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +export TEST=/CoreOS/cronie/Regression/ldap-users +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE data.ldif slapd.conf user1.cron + +.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: Jakub Prokes " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: Test for cronie not creating jobs for ldap users if ldap" >> $(METADATA) + @echo "Type: Regression" >> $(METADATA) + @echo "TestTime: 10m" >> $(METADATA) + @echo "RunFor: cronie openldap" >> $(METADATA) + @echo "Requires: cronie authconfig openldap openldap-servers openldap-clients sssd sssd-ldap" >> $(METADATA) + @echo "RhtsRequires: library(authconfig/basic)" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2+" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/tests/ldap-users/PURPOSE b/tests/ldap-users/PURPOSE new file mode 100644 index 0000000..786822b --- /dev/null +++ b/tests/ldap-users/PURPOSE @@ -0,0 +1,5 @@ +PURPOSE of /CoreOS/cronie/Regression/ldap-users +Description: Test for cronie not creating jobs for ldap users if ldap +Author: Jakub Prokes +Bug summary: cronie not creating jobs for ldap users if ldap server is temporarily down. + diff --git a/tests/ldap-users/data.ldif b/tests/ldap-users/data.ldif new file mode 100644 index 0000000..9d8836a --- /dev/null +++ b/tests/ldap-users/data.ldif @@ -0,0 +1,26 @@ +dn: dc=foo,dc=bar,dc=com +dc: foo +objectClass: top +objectClass: domain + +dn: ou=people,dc=foo,dc=bar,dc=com +ou: people +objectClass: top +objectClass: organizationalUnit + +dn: uid=user1,ou=people,dc=foo,dc=bar,dc=com +uid: user1 +cn: user1 +objectClass: account +objectClass: posixAccount +objectClass: top +objectClass: shadowAccount +userPassword: {CRYPT}hebc0ErNA0uXY +shadowLastChange: 14460 +shadowMax: 99999 +shadowWarning: 7 +loginShell: /bin/bash +uidNumber: 1001 +gidNumber: 1000 +homeDirectory: /home/ldap/user1 +gecos: user1 diff --git a/tests/ldap-users/runtest.sh b/tests/ldap-users/runtest.sh new file mode 100644 index 0000000..4de269b --- /dev/null +++ b/tests/ldap-users/runtest.sh @@ -0,0 +1,133 @@ +#!/bin/bash +# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /CoreOS/cronie/Regression/ldap-users +# Description: Test for cronie not creating jobs for ldap users if ldap +# Author: Jakub Prokes +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2016 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# 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, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Include Beaker environment +. /usr/bin/rhts-environment.sh || exit 1 +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="cronie" + +rlJournalStart + rlPhaseStart FAIL "General Setup" + rlAssertRpm $PACKAGE + rlRun "tmpDir=\$(mktemp -d)" 0 "Creating tmp directory" + rlRun "testDir=\"$(pwd)\"" + rlRun "pushd $tmpDir" + rlRun "rlImport --all" + rlServiceStart "crond" + rlFileBackup /var/log/cron + echo > /var/log/cron + /bin/kill -HUP $(cat /var/run/syslogd.pid) + rlRun "getent passwd user1" 2 + rlPhaseEnd + + rlPhaseStart FAIL "LDAP Server Setup" + rlServiceStop "slapd" + rlFileBackup --clean "/etc/openldap" + rlFileBackup --clean "/var/run/openldap" + rlFileBackup --clean "/var/lib/ldap" + rlRun "rm -rf /etc/openldap/slapd.d/* /var/lib/ldap/* /var/run/openldap/*" 0 "Cleaning LDAP directories" + rlRun "slapadd -l ${testDir}/data.ldif -f ${testDir}/slapd.conf" 0 "Importing testing user into LDAP" + rlRun "chown ldap:ldap /var/run/openldap/*" 0 "Fixing permissions on '/var/run/openldap/*'" + rlRun "restorecon -Rv /etc/" 0 "Fixing SELinux contexts" + rlRun "slaptest -f ${testDir}/slapd.conf -F /etc/openldap/slapd.d" 0 "Importing LDAP configuration" + rlRun "chown -R ldap:ldap /etc/openldap/slapd.d" 0 "Fixing permissions on '/etc/openldap/slapd.d'" + rlServiceStart "slapd" + rlPhaseEnd + + rlPhaseStart FAIL "LDAP auth setup" + rlServiceStop "sssd" + rlRun "authconfig_setup" + rlRun "authconfig --savebackup=CoreOS_cronie_Regression_ldap-users" + rlRun "authconfig --enableldap --enableldapauth --ldapserver=ldap://127.0.0.1/ \ + --ldapbasedn=dc=foo,dc=bar,dc=com --update" + rlRun "getent passwd user1" + rlRun "mkdir -p /home/ldap/user1" + rlRun "chown user1 /home/ldap/user1" + rlPhaseEnd + + rlPhaseStartTest + rlRun "su user1 -c 'crontab ${testDir}/user1.cron'" 0 "Creating user cronjob" && \ + cat ${testDir}/user1.cron; + rlFileBackup /etc/crontab + rlRun "rlServiceStop slapd" + rlRun "service sssd stop" + rlRun "rm -rf /var/lib/sss/db/*" + rlRun "service sssd start" + rlRun "getent passwd user1" 2 + rlRun "echo \"* * * * * user1 /bin/echo foo > /tmp/cron.out\" > /etc/crontab" 0 \ + "Create record in system crontab" + cat /etc/crontab + rlRun "service crond restart" + rlRun "rlServiceStart slapd" + rlRun "service sssd stop" + rlRun "rm -rf /var/lib/sss/db/*" + rlRun "service sssd start" + waitCounter=60; + echo "Waiting for LDAP" + while ! getent passwd user1; do + sleep 1; + echo -n . + [[ waitCounter -le 0 ]] && break; + waitCounter=$((waitCounter-1)); + done + echo; + rlRun "getent passwd user1" + rm -f /home/ldap/user1/cron.out + echo "Waiting for cronjob execution" + sleep 65; + if rlRun "[[ -f /home/ldap/user1/cron.out ]]" 0 "User cronjob executed successfully"; then + rlAssertGrep "foo" /home/ldap/user1/cron.out; + fi + if rlRun "[[ -f /tmp/cron.out ]]" 0 "Crontab cronjob executed successfully"; then + rlAssertGrep "foo" /tmp/cron.out; + fi + rlRun "service crond stop" + cat /var/log/cron + rlPhaseEnd + + rlPhaseStart WARN "Cleanup" + rlRun "service crond restart" + rlRun "crontab -r -u user1" + rlRun "rlServiceStop slapd" + rlRun "authconfig --disableldap --disableldapauth --update" + rlRun "authconfig --restorebackup=CoreOS_cronie_Regression_ldap-users" + rlRun "authconfig_cleanup" + rlRun "popd" + rlRun "rm -r $tmpDir" 0 "Removing tmp directory" + rlRun "rm -r /home/ldap/user1" + rlRun "rm -r /home/ldap" + rlFileRestore + rlServiceRestore slapd + rlServiceRestore sssd + /bin/kill -HUP $(cat /var/run/syslogd.pid) + rlServiceRestore crond + #avoid systemd failing to start crond due start-limit + sleep 10 + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/tests/ldap-users/slapd.conf b/tests/ldap-users/slapd.conf new file mode 100644 index 0000000..97b3c2d --- /dev/null +++ b/tests/ldap-users/slapd.conf @@ -0,0 +1,32 @@ +include /etc/openldap/schema/core.schema +include /etc/openldap/schema/cosine.schema +include /etc/openldap/schema/inetorgperson.schema +include /etc/openldap/schema/nis.schema + +allow bind_v2 + +pidfile /var/run/openldap/slapd.pid +argsfile /var/run/openldap/slapd.args + +database bdb +suffix "dc=foo,dc=bar,dc=com" +rootdn "cn=admin,dc=foo,dc=bar,dc=com" + +# Password is 'x'. +rootpw {SSHA}GPhzu7pTYP4I+nGeujpBkODiPxX0v8n8 + +directory /var/run/openldap/ + +index objectClass eq,pres +index ou,cn,mail,surname,givenname eq,pres,sub +index uidNumber,gidNumber,loginShell eq,pres +index uid,memberUid eq,pres,sub +index nisMapName,nisMapEntry eq,pres,sub +index entryCSN,entryUUID eq + +access to attrs=shadowLastChange,userPassword + by self write + by * auth + +access to * + by * read diff --git a/tests/ldap-users/user1.cron b/tests/ldap-users/user1.cron new file mode 100644 index 0000000..20d07a4 --- /dev/null +++ b/tests/ldap-users/user1.cron @@ -0,0 +1,10 @@ +# Example of job definition: +# .---------------- minute (0 - 59) +# | .------------- hour (0 - 23) +# | | .---------- day of month (1 - 31) +# | | | .------- month (1 - 12) OR jan,feb,mar,apr ... +# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat +# | | | | | +# * * * * * command to be executed + + * * * * * /bin/echo foo > $HOME/cron.out diff --git a/tests/only-one-running-instance-in-time/Makefile b/tests/only-one-running-instance-in-time/Makefile new file mode 100644 index 0000000..25272de --- /dev/null +++ b/tests/only-one-running-instance-in-time/Makefile @@ -0,0 +1,63 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /CoreOS/cronie/Regression/only-one-running-instance-in-time +# Description: When crond is running in multiple instance, then cron jobs are executed multiple times. Is neccesary to prevent multiple instances of crond running in time. +# Author: Jakub Prokes +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2013 Red Hat, Inc. All rights reserved. +# +# 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/cronie/Regression/only-one-running-instance-in-time +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE + +.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: Jakub Prokes " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: When crond is running in multiple instance, then cron jobs are executed multiple times. Is neccesary to prevent multiple instances of crond running in time." >> $(METADATA) + @echo "Type: Regression" >> $(METADATA) + @echo "TestTime: 5m" >> $(METADATA) + @echo "RunFor: cronie" >> $(METADATA) + @echo "Requires: cronie" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/tests/only-one-running-instance-in-time/PURPOSE b/tests/only-one-running-instance-in-time/PURPOSE new file mode 100644 index 0000000..7928fc9 --- /dev/null +++ b/tests/only-one-running-instance-in-time/PURPOSE @@ -0,0 +1,3 @@ +PURPOSE of /CoreOS/cronie/Regression/only-one-running-instance-in-time +Description: When crond is running in multiple instance, then cron jobs are executed multiple times. Is neccesary to prevent multiple instances of crond running in time. +Author: Jakub Prokes diff --git a/tests/only-one-running-instance-in-time/runtest.sh b/tests/only-one-running-instance-in-time/runtest.sh new file mode 100644 index 0000000..7d7e8cb --- /dev/null +++ b/tests/only-one-running-instance-in-time/runtest.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /CoreOS/cronie/Regression/only-one-running-instance-in-time +# Description: When crond is running in multiple instance, then cron jobs are executed multiple times. Is neccesary to prevent multiple instances of crond running in time. +# Author: Jakub Prokes +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2013 Red Hat, Inc. All rights reserved. +# +# 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="cronie" + +rlJournalStart + rlPhaseStartSetup + rlServiceStart crond + rlPhaseEnd + + rlPhaseStartTest + rlRun "kill -0 $(cat /var/run/crond.pid)" 0 "Service crond is running"; + rlRun "/usr/sbin/crond" 1 "Executing another instance fail"; + rlAssertEquals "There is stil one instance of crond" $(ps h -C crond -o pid | wc -l) 1; + rlPhaseEnd + + rlPhaseStartCleanup + rlServiceRestore crond + #avoid systemd failing to start crond due start-limit + sleep 10 + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/tests/run-with-syslog-flag/Makefile b/tests/run-with-syslog-flag/Makefile new file mode 100644 index 0000000..bc16c08 --- /dev/null +++ b/tests/run-with-syslog-flag/Makefile @@ -0,0 +1,62 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /CoreOS/cronie/Regression/run-with-syslog-flag +# Description: Test for cronie has a bug when run with syslog flag +# Author: Jakub Prokes +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2016 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# 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, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +export TEST=/CoreOS/cronie/Regression/run-with-syslog-flag +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE + +.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: Jakub Prokes " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: Test for cronie has a bug when run with syslog flag" >> $(METADATA) + @echo "Type: Regression" >> $(METADATA) + @echo "TestTime: 10m" >> $(METADATA) + @echo "RunFor: cronie" >> $(METADATA) + @echo "Requires: cronie rsyslog" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2+" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/tests/run-with-syslog-flag/PURPOSE b/tests/run-with-syslog-flag/PURPOSE new file mode 100644 index 0000000..bd80d4b --- /dev/null +++ b/tests/run-with-syslog-flag/PURPOSE @@ -0,0 +1,4 @@ +PURPOSE of /CoreOS/cronie/Regression/run-with-syslog-flag +Description: Test for cronie has a bug when run with syslog flag +Author: Jakub Prokes +Bug summary: cronie has a bug when run with syslog flag diff --git a/tests/run-with-syslog-flag/runtest.sh b/tests/run-with-syslog-flag/runtest.sh new file mode 100644 index 0000000..1770208 --- /dev/null +++ b/tests/run-with-syslog-flag/runtest.sh @@ -0,0 +1,81 @@ +#!/bin/bash +# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /CoreOS/cronie/Regression/run-with-syslog-flag +# Description: Test for cronie has a bug when run with syslog flag +# Author: Jakub Prokes +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2016 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# 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, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Include Beaker environment +. /usr/bin/rhts-environment.sh || exit 1 +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="cronie" +declare -r sysConfig="/etc/sysconfig/crond"; +declare -r cronJobFile=/etc/cron.d/testjob + +rlJournalStart + rlPhaseStart FAIL "Setup" + ## nasty hack for journalctl + export PAGER="" + rlAssertRpm $PACKAGE + rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory" + rlRun "pushd $TmpDir" + rlServiceStart rsyslog + rlPhaseEnd + + rlPhaseStartTest + rlFileBackup ${sysConfig}; + crondOpts="$(sed -n '/^\s*CRONDARGS/s/^\s*CRONDARGS\s*=//p' ${sysConfig})"; + rlLog "Old CRONDARGS=\"${crondOpts}\""; + if echo "$crondOpts" | grep '"'; then + ## strip trailing quotes + crondOpts="$(echo "$crondOpts" | sed 's/\(^"\)\|\("$\)//g')"; + fi + crondOpts="$crondOpts -s -m off"; + rlLog "New CRONDARGS=\"${crondOpts}\""; + echo "CRONDARGS=\"${crondOpts}\"" > ${sysConfig}; + phrase="$(tr -dc 'a-zA-Z0-9' < /dev/urandom | head -c 32)"; + echo "* * * * * root /bin/echo $phrase" > ${cronJobFile}; + cp /var/log/cron ./oldLog; + [[ -f ./oldLog ]] || touch ./oldLog; + rlServiceStop crond; + sleep 1 + rlServiceStart crond; + sleep 65; + rlRun "diff ./oldLog /var/log/cron |grep -v '/bin/echo' \ + | grep '$phrase'" 0 "Output is logged correctly." \ + || rlLog "$(tail -n 5 /var/log/cron)" + rlPhaseEnd + + rlPhaseStart WARN "Cleanup" + rlRun "rm ${cronJobFile}"; + rlFileRestore; + rlRun "rlServiceRestore crond"; + rlServiceRestore rsyslog + rlRun "popd" + rlRun "rm -r $TmpDir" 0 "Removing tmp directory" + #avoid systemd failing to start crond due start-limit + sleep 10 + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/tests/tests.yml b/tests/tests.yml new file mode 100644 index 0000000..2b58b01 --- /dev/null +++ b/tests/tests.yml @@ -0,0 +1,62 @@ +--- +# Tests to run in a classic environment +- hosts: localhost + roles: + - role: standard-test-beakerlib + tags: + - classic + tests: + - anacron-segfaults-with-certain-config-data + - anacron-segfaults-with-certain-config-data-2 + - Can-t-remove-crontab-from-expired-accounts + - Cron-does-uid-lookups-for-non-existent-users + - cron-daemon-fails-to-log-that-it-is-shutting-down + - crond-is-missing-RELRO-flags + - crond-subtask-abnormal-termination-removes-pid-file-in-error + - config-parsing-issue + - cronie-jobs-environment + - crontab-can-invoke-lookup-for-nonexisted-user + - crontab-has-wrong-permissions +# - echos-OK-twice-in-init-script Does not work on Fedora-26 + - init-script-failure +# - init-scripts-LSB Does not work on Fedora-26 +# - ldap-users Does not work on Fedora-26 +# - MAILTO-problem-with-anacron Does not work on Fedora-26 + - Make-crontab-a-PIE + - only-one-running-instance-in-time + - run-with-syslog-flag + - usr-bin-crontab-has-wrong-permissions + required_packages: + - authconfig # ldap-users needs this package + - findutils # beakerlib needs find command + - elfutils # crond-is-missing-RELRO-flags needs eu-readelf tool + - gcc # cronie-jobs-environment needs gcc command + - openldap # ldap-users needs this package + - openldap-servers # ldap-users needs this package + - openldap-clients # ldap-users needs this package + - procps-ng # multiple tests need ps and pidof commands + - psmisc # multiple tests need killall command + - rsyslog # run-with-syslog-flag requires this package + - sendmail # MAILTO-problem-with-anacron needs sendmail command + - sssd # ldap-users needs this package + - sssd-ldap # ldap-users needs this package + +# Tests to run in a container environment +- hosts: localhost + roles: + - role: standard-test-beakerlib + tags: + - container + tests: + - Can-t-remove-crontab-from-expired-accounts + - Make-crontab-a-PIE + - config-parsing-issue + - crond-is-missing-RELRO-flags + - crontab-has-wrong-permissions + - usr-bin-crontab-has-wrong-permissions + required_packages: + - cronie # everything needs cronie package + - findutils # beakerlib needs find command + - procps-ng # multiple tests need ps and pidof commands + - psmisc # multiple tests need killall command + - elfutils # multiple tests need eu-readelf tool diff --git a/tests/usr-bin-crontab-has-wrong-permissions/Makefile b/tests/usr-bin-crontab-has-wrong-permissions/Makefile new file mode 100644 index 0000000..f76a672 --- /dev/null +++ b/tests/usr-bin-crontab-has-wrong-permissions/Makefile @@ -0,0 +1,63 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /CoreOS/cronie/Regression/usr-bin-crontab-has-wrong-permissions +# Description: Test for /usr/bin/crontab has wrong permissions +# Author: Martin Cermak +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2011 Red Hat, Inc. All rights reserved. +# +# 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/cronie/Regression/usr-bin-crontab-has-wrong-permissions +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE + +.PHONY: all install download clean + +run: $(FILES) build + ./runtest.sh + +build: $(BUILT_FILES) + chmod a+x runtest.sh + +clean: + rm -f *~ $(BUILT_FILES) + + +include /usr/share/rhts/lib/rhts-make.include + +$(METADATA): Makefile + @echo "Owner: Martin Cermak " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: Test for /usr/bin/crontab has wrong permissions" >> $(METADATA) + @echo "Type: Regression" >> $(METADATA) + @echo "TestTime: 15m" >> $(METADATA) + @echo "RunFor: cronie" >> $(METADATA) + @echo "Requires: cronie" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/tests/usr-bin-crontab-has-wrong-permissions/PURPOSE b/tests/usr-bin-crontab-has-wrong-permissions/PURPOSE new file mode 100644 index 0000000..fb2bd73 --- /dev/null +++ b/tests/usr-bin-crontab-has-wrong-permissions/PURPOSE @@ -0,0 +1,5 @@ +PURPOSE of /CoreOS/cronie/Regression/usr-bin-crontab-has-wrong-permissions +Description: Test for /usr/bin/crontab has wrong permissions +Author: Martin Cermak +Bug summary: /usr/bin/crontab has wrong permissions + diff --git a/tests/usr-bin-crontab-has-wrong-permissions/runtest.sh b/tests/usr-bin-crontab-has-wrong-permissions/runtest.sh new file mode 100644 index 0000000..5540876 --- /dev/null +++ b/tests/usr-bin-crontab-has-wrong-permissions/runtest.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /CoreOS/cronie/Regression/usr-bin-crontab-has-wrong-permissions +# Description: Test for /usr/bin/crontab has wrong permissions +# Author: Martin Cermak +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2011 Red Hat, Inc. All rights reserved. +# +# 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 rhts environment +. /usr/bin/rhts-environment.sh +. /usr/lib/beakerlib/beakerlib.sh + +PACKAGE="cronie" + +rlJournalStart + rlPhaseStartSetup + rlAssertRpm $PACKAGE + rlPhaseEnd + + rlPhaseStartTest + rlRun "test `stat -c %a /usr/bin/crontab` -eq 4755" + rlPhaseEnd +rlJournalEnd +rlJournalPrintText