]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
tests: added check for system priority file loading and parsing
authorNikos Mavrogiannopoulos <nmav@redhat.com>
Fri, 1 Apr 2016 09:08:38 +0000 (11:08 +0200)
committerNikos Mavrogiannopoulos <nmav@redhat.com>
Fri, 1 Apr 2016 09:08:38 +0000 (11:08 +0200)
This checks whether the file is properly loaded and its contents
are parsed as expected.

tests/Makefile.am
tests/system-prio-file.c [new file with mode: 0644]
tests/system.prio [new file with mode: 0644]

index f3a3fe92122692b1ab9c35c83db052a3eba5b42f..7e9631717372b529134715aa98a5483c4139413e 100644 (file)
@@ -35,7 +35,8 @@ EXTRA_DIST = suppressions.valgrind eagain-common.h cert-common.h test-chains.h \
        certs/ca-cert-ecc.pem  certs/cert-ecc256.pem  certs/cert-ecc521.pem \
        certs/cert-rsa-2432.pem certs/ecc384.pem certs/ecc.pem \
        certs/ca-ecc.pem certs/cert-ecc384.pem certs/cert-ecc.pem certs/ecc256.pem \
-       certs/ecc521.pem certs/rsa-2432.pem x509cert-dir/ca.pem psk.passwd
+       certs/ecc521.pem certs/rsa-2432.pem x509cert-dir/ca.pem psk.passwd \
+       system.prio
 
 AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS)
 AM_CPPFLAGS = \
@@ -96,7 +97,8 @@ ctests = mini-record-2 simple gc set_pkcs12_cred certder certuniqueid \
         rehandshake-switch-cert-client-allow handshake-versions dtls-handshake-versions \
         dtls-max-record tls-max-record alpn-server-prec ocsp-filename-memleak \
         dh-params rehandshake-ext-secret pcert-list session-export-funcs \
-        handshake-false-start version-checks key-material-dtls key-material-set-dtls
+        handshake-false-start version-checks key-material-dtls key-material-set-dtls \
+        system-prio-file
 
 if HAVE_SECCOMP_TESTS
 ctests += dtls-with-seccomp tls-with-seccomp dtls-client-with-seccomp tls-client-with-seccomp
@@ -183,6 +185,7 @@ TESTS_ENVIRONMENT =                                         \
        PKCS12PASSWORD_2=""                                     \
        PKCS12PATH=$(srcdir)/pkcs12-decode/                     \
        X509CERTDIR=$(srcdir)/x509cert-dir/                     \
+       GNUTLS_SYSTEM_PRIORITY_FILE=$(srcdir)/system.prio       \
        PSK_FILE=$(srcdir)/psk.passwd                           \
        EXEEXT=$(EXEEXT)                                        \
        top_builddir="$(top_builddir)"                          \
diff --git a/tests/system-prio-file.c b/tests/system-prio-file.c
new file mode 100644 (file)
index 0000000..261dc45
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ * Author: Nikos Mavrogiannopoulos
+ *
+ * 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 <stdlib.h>
+#include <string.h>
+#include <gnutls/gnutls.h>
+
+#include "utils.h"
+
+char *_gnutls_resolve_priorities(const char* priorities);
+
+static void
+try_prio(const char *prio, const char *expected_str)
+{
+       char *p;
+
+       /* this must be called once in the program
+        */
+       global_init();
+
+       p = _gnutls_resolve_priorities(prio);
+       if (p == NULL && expected_str == NULL)
+               goto ok;
+
+       if (p == NULL || strcmp(p, expected_str) != 0) {
+               fail("error; got: %s, expected: %s\n", p, expected_str);
+               exit(1);
+       }
+
+ ok:
+       free(p);
+       gnutls_global_deinit();
+}
+
+void doit(void)
+{
+       try_prio("NORMAL", "NORMAL");
+       try_prio("SUITEB192", "SUITEB192");
+       try_prio("@HELLO1", "NORMAL");
+       try_prio("@HELLO2", "NORMAL:+AES-128-CBC");
+       try_prio("@HELLO3", "NONE:+VERS-TLS-ALL:-VERS-SSL3.0:+AEAD:+SHA1:+SHA256:+SHA384:+ECDHE-RSA:+ECDHE-ECDSA:+RSA:+DHE-RSA:+DHE-DSS:+AES-256-GCM:+AES-256-CBC:+CAMELLIA-256-GCM:+CAMELLIA-256-CBC:+AES-128-GCM:+AES-128-CBC:+CAMELLIA-128-GCM:+CAMELLIA-128-CBC:+3DES-CBC:+SIGN-ALL:-SIGN-RSA-MD5:+CURVE-ALL:+COMP-NULL:%PROFILE_LOW");
+       try_prio("@HELLONO", NULL);
+}
+
diff --git a/tests/system.prio b/tests/system.prio
new file mode 100644 (file)
index 0000000..ef69f6a
--- /dev/null
@@ -0,0 +1,3 @@
+HELLO1=NORMAL
+HELLO2=NORMAL:+AES-128-CBC
+HELLO3=NONE:+VERS-TLS-ALL:-VERS-SSL3.0:+AEAD:+SHA1:+SHA256:+SHA384:+ECDHE-RSA:+ECDHE-ECDSA:+RSA:+DHE-RSA:+DHE-DSS:+AES-256-GCM:+AES-256-CBC:+CAMELLIA-256-GCM:+CAMELLIA-256-CBC:+AES-128-GCM:+AES-128-CBC:+CAMELLIA-128-GCM:+CAMELLIA-128-CBC:+3DES-CBC:+SIGN-ALL:-SIGN-RSA-MD5:+CURVE-ALL:+COMP-NULL:%PROFILE_LOW