Source: nss
Severity: wishlist
Tags: patch
Hi,
while dealing with nss issues I ended up testing the same things so
here's a small autopkgtest that handles at least some prominent
cases. Would be great to have this in sid so it comes to other
versions as well.
Cheers,
-- Guido
>From 9fe54ce68ae0b393a168f1c5e7bb548d93e22ee5 Mon Sep 17 00:00:00 2001
Message-Id: <9fe54ce68ae0b393a168f1c5e7bb548d93e22ee5.1448451548.git....@sigxcpu.org>
From: =?UTF-8?q?Guido=20G=C3=BCnther?= <[email protected]>
Date: Wed, 25 Nov 2015 11:59:02 +0100
Subject: [PATCH] Add minimal autopkgtest
This test does two things:
test-cert.sh - make sure we can create, sign and import certificates
test-link.mak - make sure we can link against libnss
---
debian/tests/control | 2 ++
debian/tests/test-cert.sh | 42 ++++++++++++++++++++++++++++++++++++++++++
debian/tests/test-link.cpp | 25 +++++++++++++++++++++++++
debian/tests/test-link.make | 10 ++++++++++
4 files changed, 79 insertions(+)
create mode 100644 debian/tests/control
create mode 100755 debian/tests/test-cert.sh
create mode 100644 debian/tests/test-link.cpp
create mode 100755 debian/tests/test-link.make
diff --git a/debian/tests/control b/debian/tests/control
new file mode 100644
index 0000000..7a323d7
--- /dev/null
+++ b/debian/tests/control
@@ -0,0 +1,2 @@
+Tests: test-cert.sh, test-link.make
+Depends: @, pkg-config
diff --git a/debian/tests/test-cert.sh b/debian/tests/test-cert.sh
new file mode 100755
index 0000000..14c0907
--- /dev/null
+++ b/debian/tests/test-cert.sh
@@ -0,0 +1,42 @@
+#!/bin/bash
+#
+# Check some basic CA operations
+
+set -e
+
+cleanup() {
+ [ -z "$DIR" ] || rm -rf "$DIR"
+}
+
+
+run_certutil() {
+ CMD="certutil -z $DIR/random -f $DIR/passwd -d sql:$DIR $@"
+ echo "Running: $CMD"
+ $CMD
+}
+
+DIR=`mktemp -p . -d`
+#trap cleanup EXIT ERR
+
+dd bs=20 count=1 if=/dev/urandom of=$DIR/random 2>/dev/null
+echo "password" > $DIR/passwd
+
+# Create the database
+run_certutil -N
+# Create a self signed certificate
+run_certutil -S -k rsa -n test-ca -s CN=testca -t c -x 2>/dev/null
+# Create a certificate request
+run_certutil -R -k rsa -g 2048 -n test-cert -s "CN=testcert" -o $DIR/cert.req -a 2>/dev/null
+# Sign with ca
+run_certutil -C -m 10000 -c test-ca -i $DIR/cert.req -o $DIR/cert.cer -a
+run_certutil -A -n test-cert -i $DIR/cert.cer -t c -a
+
+echo -n "Checking if ca is present..."
+run_certutil -L -n test-ca >/dev/null
+echo "OK."
+
+echo -n "Checking if cert present..."
+run_certutil -L -n test-cert >/dev/null
+echo "OK."
+
+exit 0
diff --git a/debian/tests/test-link.cpp b/debian/tests/test-link.cpp
new file mode 100644
index 0000000..0880b4e
--- /dev/null
+++ b/debian/tests/test-link.cpp
@@ -0,0 +1,25 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include <nss.h>
+
+int main()
+{
+ int ret = 0;
+ SECStatus s;
+ char *t = strdup("/tmp/nss.XXXXXX");
+ char *tmpdir = mkdtemp(t);
+
+ if (tmpdir == NULL)
+ fprintf(stderr, "Failed to create temp directory: %s", strerror(errno));
+
+ s = NSS_InitReadWrite(tmpdir);
+ if (s != SECSuccess)
+ ret = 2;
+
+ NSS_Shutdown();
+ free(t);
+
+ return ret;
+}
diff --git a/debian/tests/test-link.make b/debian/tests/test-link.make
new file mode 100755
index 0000000..19e4e7c
--- /dev/null
+++ b/debian/tests/test-link.make
@@ -0,0 +1,10 @@
+#!/usr/bin/make -f
+
+all: a.out
+ ./a.out
+ rm -f a.out
+
+a.out: debian/tests/test-link.cpp
+ g++ -Wall -Werror $< $(shell pkg-config --cflags nss) $(shell pkg-config --libs nss)
+
+.PHONY: all
--
2.6.2