Blame Sanity/init-token-as-a-nonroot-user/runtest.sh

c33e9f2
#!/bin/bash
c33e9f2
# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
c33e9f2
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
c33e9f2
#
c33e9f2
#   runtest.sh of /CoreOS/openCryptoki/Sanity/bz1054661-init-token-as-a-nonroot-user
c33e9f2
#   Description: basic token initialization as a nonroot user
c33e9f2
#   Author: Karel Srot <ksrot@redhat.com>
c33e9f2
#
c33e9f2
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
c33e9f2
#
c33e9f2
#   Copyright (c) 2014 Red Hat, Inc.
c33e9f2
#
c33e9f2
#   This copyrighted material is made available to anyone wishing
c33e9f2
#   to use, modify, copy, or redistribute it subject to the terms
c33e9f2
#   and conditions of the GNU General Public License version 2.
c33e9f2
#
c33e9f2
#   This program is distributed in the hope that it will be
c33e9f2
#   useful, but WITHOUT ANY WARRANTY; without even the implied
c33e9f2
#   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
c33e9f2
#   PURPOSE. See the GNU General Public License for more details.
c33e9f2
#
c33e9f2
#   You should have received a copy of the GNU General Public
c33e9f2
#   License along with this program; if not, write to the Free
c33e9f2
#   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
c33e9f2
#   Boston, MA 02110-1301, USA.
c33e9f2
#
c33e9f2
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
c33e9f2
c33e9f2
# Include Beaker environment
c33e9f2
. /usr/share/beakerlib/beakerlib.sh || exit 1
c33e9f2
c33e9f2
PACKAGE="opencryptoki"
c33e9f2
USER="user$RANDOM"
c33e9f2
c33e9f2
TESTDIR=`pwd`
c33e9f2
c33e9f2
rlJournalStart
c33e9f2
    rlPhaseStartSetup
2d46c2c
        rlRun "rlImport nvr/nvr" || rlDie "cannot import distribution/nvr library"
c33e9f2
	# need to find out the library path so a user can import it too
2d46c2c
	rlRun "rlImport ./token-manipulation" 2> import.log || rlDie "Could not import opencryptoki/token-manipulation library"
2d46c2c
	LIBPATH=`grep 'Will try to import .\/token-manipulation from' import.log | sed 's/^.*token-manipulation from//'`
c33e9f2
	echo "LIBPATH=$LIBPATH"
c33e9f2
        rlAssertRpm $PACKAGE
c33e9f2
        rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
c33e9f2
        rlRun "pushd $TmpDir"
c33e9f2
	rlRun "useradd -m $USER -G pkcs11"
c33e9f2
	rlServiceStop pkcsslotd
c33e9f2
	rlRun "pkcsResetTokens"
c33e9f2
	rlServiceStart pkcsslotd
c33e9f2
    rlPhaseEnd
c33e9f2
c33e9f2
    rlPhaseStartTest "listing available tokens as a testuser"
c33e9f2
	rlRun "su $USER -c 'pkcsconf -t' &> query1.log"
c33e9f2
	cat query1.log
c33e9f2
    if nvrTestPackage opencryptoki '<' 3.14.0; then
c33e9f2
	    rlAssertGrep "Model: IBM SoftTok" query1.log
c33e9f2
    else
c33e9f2
        rlAssertGrep "Model: Soft " query1.log
c33e9f2
    fi
c33e9f2
    rlPhaseEnd
c33e9f2
c33e9f2
  # initialize every token available
c33e9f2
  for SLOT in `sed -n 's/^Token #\([0-9]\).*/\1/gp' query1.log`; do
c33e9f2
c33e9f2
    rlPhaseStartTest "initialize token #$SLOT"
c33e9f2
	rlRun "su $USER -c 'source $LIBPATH && pkcsInitToken $SLOT'"
c33e9f2
	rlRun "su $USER -c 'pkcsconf -t -c $SLOT' &> query2.log"
c33e9f2
	cat query2.log
c33e9f2
	rlAssertGrep 'Flags:.*LOGIN_REQUIRED.*USER_PIN_INITIALIZED.*TOKEN_INITIALIZED' query2.log -E
c33e9f2
    rlPhaseEnd
c33e9f2
c33e9f2
  done
c33e9f2
c33e9f2
    rlPhaseStartCleanup
c33e9f2
	rlServiceStop pkcsslotd
c33e9f2
	rlRun "pkcsRestoreTokens"
c33e9f2
	    rlServiceRestore pkcsslotd
c33e9f2
        rlRun "popd"
c33e9f2
        rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
c33e9f2
        rlLog "Waiting 12 for systemd --user process to exit..."
c33e9f2
        sleep 15
c33e9f2
        rlRun "userdel -r $USER" || ps -ef
c33e9f2
    rlPhaseEnd
c33e9f2
rlJournalPrintText
c33e9f2
rlJournalEnd