]> git.proxmox.com Git - swtpm.git/commitdiff
tests: Extend swtpm-localca test with odd vmid strings
authorStefan Berger <stefanb@linux.vnet.ibm.com>
Mon, 10 Aug 2020 18:50:34 +0000 (14:50 -0400)
committerStefan Berger <stefanb@us.ibm.com>
Tue, 11 Aug 2020 19:01:59 +0000 (15:01 -0400)
Extend the swtpm-localca test with odd vmid string to ensure
that they go into the certificate unmodified.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
tests/test_tpm2_samples_swtpm_localca

index 11ad10ba8099b000e78473dae3927e0c173a7759..c5a3799ddcb2e0a1d3dd9c72c9129d54a0d5e000 100755 (executable)
@@ -116,4 +116,54 @@ do
   fi
 done
 
+echo "Test 1: OK"
+echo
+
+#A few tests with odd vm Ids
+for vmid in \
+       's p a c e|s p a c e' \
+       '$(ls)>foo|$(ls)\>foo' \
+       '`ls`&; #12|`ls`&\; #12' \
+       'foo>&1<&2;$(ls)|foo\>&1\<&2\;$(ls)' \
+       "'*|'*" \
+       '"*|\"*' \
+       ':$$|:$$' \
+       '${t}[]|${t}[]';
+do
+  in=$(echo "$vmid" | cut -d"|" -f1)
+  exp=$(echo "$vmid" | cut -d"|" -f2)
+
+  ${SWTPM_LOCALCA} \
+    --type ek \
+    --ek "${ek}" \
+    --dir "${workdir}" \
+    --vmid "$in" \
+    --tpm2 \
+    --configfile "${workdir}/swtpm-localca.conf" \
+    --optsfile "${workdir}/swtpm-localca.options" \
+    --tpm-spec-family 2.0 --tpm-spec-revision 146 --tpm-spec-level 0 \
+    ${params} &>/dev/null
+  if [ $? -ne 0 ]; then
+    echo "Error: Test with parameters '$params' failed."
+    exit 1
+  fi
+
+  if [ ! -r "${workdir}/ek.cert" ]; then
+    echo "Error: ${workdir}/ek.cert was not created."
+    exit 1
+  fi
+
+  ac=$(${CERTTOOL} -i --inder --infile "${workdir}/ek.cert" | \
+       sed -n "s/.*Subject: CN=\(.*\)$/\1/p")
+  if [ "$ac" != "$exp" ]; then
+    echo "Error: unexpected subject string"
+    echo "actual   : $ac"
+    echo "expected : $exp"
+  else
+    echo "Pass: $ac"
+  fi
+done
+
+echo "Test 2: OK"
+
 exit 0