Add pkcsstats-basic-functionality
This commit is contained in:
parent
1271a83b06
commit
5a2484de86
2 changed files with 156 additions and 0 deletions
30
Sanity/pkcsstats-basic-functionality/main.fmf
Normal file
30
Sanity/pkcsstats-basic-functionality/main.fmf
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
summary: Tests basic functionality of the pkcsstats command
|
||||
description: |
|
||||
Bug summary: openCryptoki: add crypto counters
|
||||
Bugzilla link: https://bugzilla.redhat.com/show_bug.cgi?id=2043854
|
||||
Bugzilla link: https://bugzilla.redhat.com/show_bug.cgi?id=2044180
|
||||
contact: Karel Srot <ksrot@redhat.com>
|
||||
component:
|
||||
- opencryptoki
|
||||
test: ./runtest.sh
|
||||
framework: beakerlib
|
||||
require:
|
||||
- url: https://src.fedoraproject.org/tests/opencryptoki.git
|
||||
name: /Library/token-manipulation
|
||||
recommend:
|
||||
- opencryptoki
|
||||
- opencryptoki-swtok
|
||||
- expect
|
||||
duration: 5m
|
||||
enabled: true
|
||||
tag:
|
||||
- CI-Tier-1
|
||||
- Tier1
|
||||
tier: '1'
|
||||
link:
|
||||
- relates: https://bugzilla.redhat.com/show_bug.cgi?id=2043854
|
||||
- relates: https://bugzilla.redhat.com/show_bug.cgi?id=2044180
|
||||
adjust:
|
||||
- enabled: false
|
||||
when: distro == rhel-4, rhel-5, rhel-6, rhel-7
|
||||
continue: false
|
||||
126
Sanity/pkcsstats-basic-functionality/runtest.sh
Executable file
126
Sanity/pkcsstats-basic-functionality/runtest.sh
Executable file
|
|
@ -0,0 +1,126 @@
|
|||
#!/bin/bash
|
||||
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
#
|
||||
# Author: Karel Srot <ksrot@redhat.com>
|
||||
#
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
#
|
||||
# Copyright (c) 2022 Red Hat, Inc.
|
||||
#
|
||||
# This copyrighted material is made available to anyone wishing
|
||||
# to use, modify, copy, or redistribute it subject to the terms
|
||||
# and conditions of the GNU General Public License version 2.
|
||||
#
|
||||
# This program is distributed in the hope that it will be
|
||||
# useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
# PURPOSE. See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public
|
||||
# License along with this program; if not, write to the Free
|
||||
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
# Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
# Include Beaker environment
|
||||
. /usr/share/beakerlib/beakerlib.sh || exit 1
|
||||
|
||||
PACKAGE="opencryptoki"
|
||||
[ -n "$SLOT" ] || SLOT=sw
|
||||
USER="user$RANDOM"
|
||||
|
||||
rlJournalStart
|
||||
rlPhaseStartSetup
|
||||
rlAssertRpm $PACKAGE
|
||||
rlRun "rlImport opencryptoki/token-manipulation" || rlDie "Could not import opencryptoki/token-manipulation library"
|
||||
rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
|
||||
rlRun "pushd $TmpDir"
|
||||
rlRun "useradd -m $USER -G pkcs11"
|
||||
rlRun -s "su $USER -c 'id'"
|
||||
rlFileBackup /etc/opencryptoki/opencryptoki.conf
|
||||
rlServiceStop pkcsslotd
|
||||
rlRun "pkcsResetTokens"
|
||||
rlServiceStart pkcsslotd
|
||||
sleep 1
|
||||
rlRun "pkcsconf -t | grep 'Soft'"
|
||||
SLOT=$( pkcsGetTokenSlot $SLOT )
|
||||
rlRun "pkcsInitToken $SLOT"
|
||||
rlRun "pkcsconf -t"
|
||||
rlRun "pkcsstats -R"
|
||||
rlPhaseEnd
|
||||
|
||||
rlPhaseStartTest "Generate aes key as root and verify stats"
|
||||
rlRun -s "pkcsstats -s $SLOT -U root"
|
||||
rlAssertGrep "[no mechanisms were used]" $rlRun_LOG
|
||||
rlRun "p11sak generate-key aes 128 --slot $SLOT --pin $pkcsUSER_PIN --label aes_key --attr ED"
|
||||
rlRun -s "p11sak list-key aes --slot $SLOT --pin $pkcsUSER_PIN"
|
||||
rlAssertGrep "AES 128 | aes_key" $rlRun_LOG
|
||||
rlRun -s "p11sak gen-key ec prime256v1 --slot $SLOT --pin $pkcsUSER_PIN --label ec_key"
|
||||
rlRun -s "p11sak ls secret --long --slot $SLOT --pin $pkcsUSER_PIN"
|
||||
rlRun -s "pkcsstats -s $SLOT -U root"
|
||||
rlAssertGrep "CKM_AES_KEY_GEN *\| *0 *0 *1 *0 *0" $rlRun_LOG -E
|
||||
rlAssertGrep "CKM_EC_KEY_PAIR_GEN *\| *0 *0 *1 *0 *0" $rlRun_LOG -E
|
||||
rlPhaseEnd
|
||||
|
||||
rlPhaseStartTest "Generate aes key as $USER and verify stats"
|
||||
rlRun -s "pkcsstats -s $SLOT -U $USER" 0,1
|
||||
rlAssertGrep "(no mechanisms were used|No statistics are available for user '$USER')" $rlRun_LOG -E
|
||||
rlRun "su - $USER -c 'p11sak generate-key aes 128 --slot $SLOT --pin $pkcsUSER_PIN --label aes_key --attr ED'"
|
||||
rlRun -s "p11sak list-key aes --slot $SLOT --pin $pkcsUSER_PIN"
|
||||
rlAssertGrep "AES 128 | aes_key" $rlRun_LOG
|
||||
rlRun -s "pkcsstats -s $SLOT -U $USER"
|
||||
rlAssertGrep "CKM_AES_KEY_GEN *\| *0 *0 *1 *0 *0" $rlRun_LOG -E
|
||||
rlPhaseEnd
|
||||
|
||||
rlPhaseStartTest "Print acummulated stats for all users"
|
||||
rlRun -s "pkcsstats -s $SLOT -S"
|
||||
rlAssertGrep "CKM_AES_KEY_GEN *\| *0 *0 *2 *0 *0" $rlRun_LOG -E
|
||||
rlPhaseEnd
|
||||
|
||||
rlPhaseStartTest "Print --all-mechs stats for $USER"
|
||||
rlRun -s "pkcsstats -s $SLOT --all-mechs -U $USER"
|
||||
rlAssertGrep "CKM_AES_KEY_GEN *\| *0 *0 *1 *0 *0" $rlRun_LOG -E
|
||||
rlAssertGrep "CKM_EC_KEY_PAIR_GEN *\| *0 *0 *0 *0 *0" $rlRun_LOG -E
|
||||
rlPhaseEnd
|
||||
|
||||
rlPhaseStartTest "Reset stats for $USER"
|
||||
rlRun -s "pkcsstats -r -U $USER"
|
||||
rlRun -s "pkcsstats -s $SLOT -U $USER"
|
||||
rlAssertGrep "no mechanisms were used" $rlRun_LOG
|
||||
rlRun -s "pkcsstats -s $SLOT -U $USER -a"
|
||||
rlAssertGrep "CKM_AES_KEY_GEN *\| *0 *0 *0 *0 *0" $rlRun_LOG -E
|
||||
rlPhaseEnd
|
||||
|
||||
rlPhaseStartTest "Delete stats for $USER"
|
||||
rlRun -s "pkcsstats -d -U $USER"
|
||||
rlRun -s "pkcsstats -s $SLOT -U $USER -a" 1
|
||||
rlAssertGrep "No statistics are available for user '$USER'" $rlRun_LOG -E
|
||||
rlPhaseEnd
|
||||
|
||||
rlPhaseStartTest "Print user stats in JSON"
|
||||
rlRun -s "pkcsstats -s $SLOT -j"
|
||||
rlAssertGrep '"user": "root",' $rlRun_LOG
|
||||
rlAssertGrep '"mechanism": "CKM_AES_KEY_GEN",' $rlRun_LOG
|
||||
rlAssertGrep '"strength-128": 1,' $rlRun_LOG
|
||||
rlPhaseEnd
|
||||
|
||||
rlPhaseStartTest "Print help"
|
||||
rlRun -s "pkcsstats -h"
|
||||
rlAssertGrep "Usage: pkcsstats \[OPTIONS\]" $rlRun_LOG
|
||||
rlPhaseEnd
|
||||
|
||||
rlPhaseStartCleanup
|
||||
rlServiceStop pkcsslotd
|
||||
rlRun "pkcsRestoreTokens"
|
||||
rlFileRestore
|
||||
rlServiceRestore pkcsslotd
|
||||
rlRun "popd"
|
||||
rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
|
||||
rlLog "Waiting 12 for systemd --user process to exit..."
|
||||
sleep 15
|
||||
rlRun "userdel -r $USER" || ps -ef
|
||||
rlPhaseEnd
|
||||
rlJournalPrintText
|
||||
rlJournalEnd
|
||||
Loading…
Add table
Add a link
Reference in a new issue