[gnutls-devel] [PATCH 3/4] tests: nist-pkits: cleanup shell/perl usage
Alon Bar-Lev
alon.barlev at gmail.com
Thu Jun 18 08:41:54 CEST 2015
Add quotes for most usages of variables.
Added ${} for variables.
Consistent indent.
Add perl shebang.
Signed-off-by: Alon Bar-Lev <alon.barlev at gmail.com>
---
tests/nist-pkits/build-chain | 28 +++++++++++++++-------------
tests/nist-pkits/gnutls_test_entry | 30 +++++++++++++++---------------
tests/nist-pkits/pkits | 11 +++++------
tests/nist-pkits/pkits_crl | 23 ++++++++++++-----------
tests/nist-pkits/pkits_crt | 23 ++++++++++++-----------
tests/nist-pkits/pkits_pkcs12 | 23 ++++++++++++-----------
tests/nist-pkits/pkits_smime | 33 +++++++++++++++++----------------
tests/nist-pkits/pkits_test | 8 +++++---
8 files changed, 93 insertions(+), 86 deletions(-)
diff --git a/tests/nist-pkits/build-chain b/tests/nist-pkits/build-chain
index e625a8c..ebe48db 100755
--- a/tests/nist-pkits/build-chain
+++ b/tests/nist-pkits/build-chain
@@ -1,3 +1,5 @@
+#!/usr/bin/perl
+
eval '(exit $?0)' && eval 'exec perl -wST "$0" ${1+"$@"}'
& eval 'exec perl -wST "$0" $argv:q'
if 0;
@@ -10,30 +12,30 @@ my $aki;
my $info;
my $list;
-if (! -f "$certdir/certinfo.txt") {
- system("for i in $certdir/*.crt; do echo -n \$i:; certtool --inder -i < \$i|grep 'Subject Key Id' -A 1|tail -1; done > $certdir/certinfo.txt");
+if (! -f "${certdir}/certinfo.txt") {
+ system("for i in '${certdir}'/*.crt; do echo -n \$i:; certtool --inder -i < \$i|grep 'Subject Key Id' -A 1|tail -1; done > '${certdir}/certinfo.txt'");
}
do {
- print "Parsing $certdir/$certfile...\n";
+ print "Parsing ${certdir}/${certfile}...\n";
- $info = `certtool --inder -i < $certdir/$certfile`;
+ $info = `certtool --inder -i < '${certdir}/${certfile}'`;
- print "$info";
+ print "${info}";
- if ($info =~ m,Authority Key Identifier.*:\n[\t]*([a-z0-9]+),m) {
- $aki = $1;
+ if (${info} =~ m,Authority Key Identifier.*:\n[\t ]*([a-z0-9]+),m) {
+ $aki = $1;
} else {
- die "Could not find AKI";
+ die "Could not find AKI";
}
- print "Finding AKI $aki...\n";
+ print "Finding AKI ${aki}...\n";
- $list = `cat $certdir/certinfo.txt | grep $aki`;
+ $list = `cat '${certdir}/certinfo.txt' | grep '${aki}'`;
if ($list =~m,.*/(.*):.*,) {
- $list = $1;
+ $list = $1;
} else {
- die "Could not find issuer";
+ die "Could not find issuer";
}
- $certfile = $list;
+ $certfile = ${list};
} while (1);
diff --git a/tests/nist-pkits/gnutls_test_entry b/tests/nist-pkits/gnutls_test_entry
index f94cf4b..87c435e 100755
--- a/tests/nist-pkits/gnutls_test_entry
+++ b/tests/nist-pkits/gnutls_test_entry
@@ -1,28 +1,28 @@
#!/bin/sh
-TITLE=$1
-EECERT=$2
-RESULT=$3
+TITLE="$1"
+EECERT="$2"
+RESULT="$3"
-./build-chain certs $EECERT > chain.pem
+./build-chain certs "${EECERT}" > chain.pem
certtool -e < chain.pem > output.txt
rm -f chain.pem
if grep 'Verification output:' output.txt > /dev/null; then
- if grep 'Verification output' output.txt | grep -v 'Verification output: Verified.' > /dev/null; then
- if test "$RESULT" = "0"; then
- echo "<font color=red>Unexpected reject</font>"
- else
- echo "<font color=green>Reject</font>"
- fi
+ if grep 'Verification output' output.txt | grep -v 'Verification output: Verified.' > /dev/null; then
+ if test "${RESULT}" = "0"; then
+ echo "<font color=red>Unexpected reject</font>"
else
- if test "$RESULT" = "1"; then
- echo "<font color=red>Unexpected success</font>"
- else
- echo "<font color=green>Success</font>"
- fi
+ echo "<font color=green>Reject</font>"
fi
+ else
+ if test "${RESULT}" = "1"; then
+ echo "<font color=red>Unexpected success</font>"
+ else
+ echo "<font color=green>Success</font>"
+ fi
+ fi
fi
rm -f output.txt
diff --git a/tests/nist-pkits/pkits b/tests/nist-pkits/pkits
index 83f4d29..ac72212 100755
--- a/tests/nist-pkits/pkits
+++ b/tests/nist-pkits/pkits
@@ -20,19 +20,18 @@
set -e
-srcdir=${srcdir:-.}
-CERTTOOL=${CERTTOOL:-../../src/certtool}
+srcdir="${srcdir:-.}"
echo "Running PKITS CRT..."
-$srcdir/pkits_crt
+"${srcdir}/pkits_crt"
echo "Running PKITS CRL..."
-$srcdir/pkits_crl
+"${srcdir}/pkits_crl"
echo "Running PKITS PKCS#12..."
-$srcdir/pkits_pkcs12
+"${srcdir}/pkits_pkcs12"
echo "Running PKITS S/MIME..."
-$srcdir/pkits_smime
+"${srcdir}/pkits_smime"
echo "Done"
diff --git a/tests/nist-pkits/pkits_crl b/tests/nist-pkits/pkits_crl
index 9bf00e6..1473587 100755
--- a/tests/nist-pkits/pkits_crl
+++ b/tests/nist-pkits/pkits_crl
@@ -18,20 +18,21 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-CERTTOOL=${CERTTOOL:-../../src/certtool}
+srcdir="${srcdir:-.}"
+CERTTOOL="${CERTTOOL:-../../src/certtool}"
-test -d crls || unzip PKITS_data.zip
+test -d crls || unzip "${srcdir}/PKITS_data.zip"
ret=0
-for crl in crls/*; do
- $CERTTOOL --crl-info --inder --infile $crl > out 2>&1
- rc=$?
- if test $rc != 0; then
- echo "CRL FATAL $crl"
- ret=1
- fi
+for crl in "${srcdir}/crls"/*; do
+ "${CERTTOOL}" --crl-info --inder --infile "${crl}" > out 2>&1
+ rc=$?
+ if test ${rc} != 0; then
+ echo "CRL FATAL ${crl}"
+ ret=1
+ fi
done
rm -f out
-echo "Done (exit code $ret)"
-exit $ret
+echo "Done (exit code ${ret})"
+exit ${ret}
diff --git a/tests/nist-pkits/pkits_crt b/tests/nist-pkits/pkits_crt
index 0fa37d4..5e22ca2 100755
--- a/tests/nist-pkits/pkits_crt
+++ b/tests/nist-pkits/pkits_crt
@@ -18,20 +18,21 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-CERTTOOL=${CERTTOOL:-../../src/certtool}
+srcdir="${srcdir:-.}"
+CERTTOOL="${CERTTOOL:-../../src/certtool}"
-test -d certs || unzip PKITS_data.zip
+test -d certs || unzip "${srcdir}/PKITS_data.zip"
ret=0
-for crt in certs/*; do
- $CERTTOOL --certificate-info --inder --infile $crt > out 2>&1
- rc=$?
- if test $rc != 0; then
- echo "Certificate FATAL $crt"
- ret=1
- fi
+for crt in "${srcdir}/certs"/*; do
+ "${CERTTOOL}" --certificate-info --inder --infile "${crt}" > out 2>&1
+ rc=$?
+ if test ${rc} != 0; then
+ echo "Certificate FATAL ${crt}"
+ ret=1
+ fi
done
rm -f out
-echo "Done (exit code $ret)"
-exit $ret
+echo "Done (exit code ${ret})"
+exit ${ret}
diff --git a/tests/nist-pkits/pkits_pkcs12 b/tests/nist-pkits/pkits_pkcs12
index bdaaa5b..24ba7e6 100755
--- a/tests/nist-pkits/pkits_pkcs12
+++ b/tests/nist-pkits/pkits_pkcs12
@@ -18,20 +18,21 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-CERTTOOL=${CERTTOOL:-../../src/certtool}
+srcdir="${srcdir:-.}"
+CERTTOOL="${CERTTOOL:-../../src/certtool}"
-test -d pkcs12 || unzip PKITS_data.zip
+test -d pkcs12 || unzip "${srcdir}/PKITS_data.zip"
ret=0
-for p12 in pkcs12/*; do
- $CERTTOOL --p12-info --inder --password password --infile $p12 > out 2>&1
- rc=$?
- if test $rc != 0; then
- echo "PKCS12 FATAL $p12"
- ret=1
- fi
+for p12 in "${srcdir}/pkcs12"/*; do
+ "${CERTTOOL}" --p12-info --inder --password password --infile "${p12}" > out 2>&1
+ rc=$?
+ if test ${rc} != 0; then
+ echo "PKCS12 FATAL $p12"
+ ret=1
+ fi
done
rm -f out
-echo "Done (exit code $ret)"
-exit $ret
+echo "Done (exit code ${ret})"
+exit ${ret}
diff --git a/tests/nist-pkits/pkits_smime b/tests/nist-pkits/pkits_smime
index cfd9843..a9b15aa 100755
--- a/tests/nist-pkits/pkits_smime
+++ b/tests/nist-pkits/pkits_smime
@@ -18,26 +18,27 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+srcdir="${srcdir:-.}"
CERTTOOL=${CERTTOOL:-../../src/certtool}
-test -d smime || unzip PKITS_data.zip
+test -d smime || unzip "${srcdir}/PKITS_data.zip"
ret=0
-for msg in smime/*; do
- $CERTTOOL --smime-to-p7 --infile $msg > out 2>&1
- rc=$?
- if test $rc != 0; then
- echo "S/MIME FATAL $msg"
- ret=1
- fi
- $CERTTOOL --p7-info --infile out > out2 2>&1
- rc=$?
- if test $rc != 0; then
- echo "PKCS#7 FATAL $msg"
- ret=1
- fi
+for msg in "${srcdir}/smime"/*; do
+ "${CERTTOOL}" --smime-to-p7 --infile "${msg}" > out 2>&1
+ rc=$?
+ if test ${rc} != 0; then
+ echo "S/MIME FATAL $msg"
+ ret=1
+ fi
+ "${CERTTOOL}" --p7-info --infile out > out2 2>&1
+ rc=$?
+ if test ${rc} != 0; then
+ echo "PKCS#7 FATAL $msg"
+ ret=1
+ fi
done
rm -f out out2
-echo "Done (exit code $ret)"
-exit $ret
+echo "Done (exit code ${ret})"
+exit ${ret}
diff --git a/tests/nist-pkits/pkits_test b/tests/nist-pkits/pkits_test
index 6daaa34..55653a3 100755
--- a/tests/nist-pkits/pkits_test
+++ b/tests/nist-pkits/pkits_test
@@ -2,11 +2,13 @@
set -e
-test -d certs || unzip PKITS_data.zip
+srcdir="${srcdir:-.}"
+
+test -d certs || unzip "${srcdir}/PKITS_data.zip"
if ! test -d pkits_test_list_generator; then
- tar xfz pkits_test_list_generator.tgz
- patch -p 0 < pkits_test_list_generator.patch
+ tar xfz "${srcdir}/pkits_test_list_generator.tgz"
+ patch -p 0 < pkits_test_list_generator.patch
fi
make -C pkits_test_list_generator/src
--
2.3.6
More information about the Gnutls-devel
mailing list