summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2016-05-30 15:17:06 +0200
committerNikos Mavrogiannopoulos <nmav@redhat.com>2016-05-30 15:17:09 +0200
commit5e4eea5d60908c481c7623688772e75581cc4297 (patch)
treea04a0f707ac6b1723c0bb3456b2423c50c97908a
parent78daad3cf290f322075743c8eaa9a62009873633 (diff)
downloadgnutls-5e4eea5d60908c481c7623688772e75581cc4297.tar.gz
tests: added unit tests for gnutls_x509_tlsfeatures_t handling funcs
This includes DER import/export as well as feature appending.
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/tlsfeature-ext.c100
2 files changed, 101 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 517d0caa87..d68a06ea74 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -107,7 +107,7 @@ ctests = mini-record-2 simple gc set_pkcs12_cred certder certuniqueid \
set_x509_key_file_der set_x509_pkcs12_key crt_apis tls1.2-cert-key-exchange \
tls1.1-cert-key-exchange tls1.0-cert-key-exchange ssl3.0-cert-key-exchange \
dtls1.2-cert-key-exchange dtls1.0-cert-key-exchange x509-cert-callback-legacy \
- keylog-env ssl2-hello
+ keylog-env ssl2-hello tlsfeature-ext
if HAVE_SECCOMP_TESTS
ctests += dtls-with-seccomp tls-with-seccomp dtls-client-with-seccomp tls-client-with-seccomp
diff --git a/tests/tlsfeature-ext.c b/tests/tlsfeature-ext.c
new file mode 100644
index 0000000000..9723c3d9ab
--- /dev/null
+++ b/tests/tlsfeature-ext.c
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ * This file is part of GnuTLS.
+ *
+ * GnuTLS is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuTLS 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 GnuTLS; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+
+#include <gnutls/gnutls.h>
+#include <gnutls/x509.h>
+#include <gnutls/x509-ext.h>
+#include <assert.h>
+#include "utils.h"
+
+void doit(void)
+{
+ int ret;
+ gnutls_x509_tlsfeatures_t feat;
+ unsigned int out;
+ gnutls_datum_t der;
+
+ ret = global_init();
+ if (ret < 0)
+ fail("init %d\n", ret);
+
+ /* init and write >1 features
+ */
+ assert(gnutls_x509_tlsfeatures_init(&feat) >= 0);
+
+ assert(gnutls_x509_tlsfeatures_add(feat, 2) >= 0);
+ assert(gnutls_x509_tlsfeatures_add(feat, 3) >= 0);
+ assert(gnutls_x509_tlsfeatures_add(feat, 5) >= 0);
+ assert(gnutls_x509_tlsfeatures_add(feat, 7) >= 0);
+ assert(gnutls_x509_tlsfeatures_add(feat, 11) >= 0);
+
+ assert(gnutls_x509_ext_export_tlsfeatures(feat, &der) >= 0);
+
+ gnutls_x509_tlsfeatures_deinit(feat);
+
+ /* re-load and read
+ */
+ assert(gnutls_x509_tlsfeatures_init(&feat) >= 0);
+
+ assert(gnutls_x509_ext_import_tlsfeatures(&der, feat, 0) >= 0);
+
+ assert(gnutls_x509_tlsfeatures_get(feat, 0, &out) >= 0);
+ assert(out == 2);
+
+ assert(gnutls_x509_tlsfeatures_get(feat, 1, &out) >= 0);
+ assert(out == 3);
+
+ assert(gnutls_x509_tlsfeatures_get(feat, 2, &out) >= 0);
+ assert(out == 5);
+
+ assert(gnutls_x509_tlsfeatures_get(feat, 3, &out) >= 0);
+ assert(out == 7);
+
+ assert(gnutls_x509_tlsfeatures_get(feat, 4, &out) >= 0);
+ assert(out == 11);
+
+ gnutls_x509_tlsfeatures_deinit(feat);
+ gnutls_free(der.data);
+
+ /* check whether no feature is acceptable */
+ assert(gnutls_x509_tlsfeatures_init(&feat) >= 0);
+
+ assert(gnutls_x509_ext_export_tlsfeatures(feat, &der) >= 0);
+
+ gnutls_x509_tlsfeatures_deinit(feat);
+
+ assert(gnutls_x509_tlsfeatures_init(&feat) >= 0);
+
+ assert(gnutls_x509_ext_import_tlsfeatures(&der, feat, 0) >= 0);
+
+ assert(gnutls_x509_tlsfeatures_get(feat, 0, &out) == GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE);
+
+ gnutls_x509_tlsfeatures_deinit(feat);
+ gnutls_free(der.data);
+
+ gnutls_global_deinit();
+}
+