summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2017-03-16 14:29:10 +0100
committerNikos Mavrogiannopoulos <nmav@redhat.com>2017-03-16 16:30:47 +0100
commit4905f8563f89424e42ac2e4dad39d0cc8a37a223 (patch)
tree99c87c77df76b9f428823e02c380ba85ba21305c
parentf313fd45f01c8520b78908c926cf3bf735cacc5b (diff)
downloadgnutls-tmp-string-tests.tar.gz
tests: added basic unit tests for several string functions of libstmp-string-tests
Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
-rw-r--r--tests/Makefile.am5
-rw-r--r--tests/dane-strcodes.c81
-rw-r--r--tests/gnutls-strcodes.c124
3 files changed, 208 insertions, 2 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c6d93f1a46..2874ad77dc 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -71,6 +71,7 @@ LDADD = $(COMMON_GNUTLS_LDADD) \
$(COMMON_DEPS_LDADD)
dane_LDADD = $(LDADD) ../libdane/libgnutls-dane.la
+dane_strcodes_LDADD = $(LDADD) ../libdane/libgnutls-dane.la
if ENABLE_MINITASN1
AM_CPPFLAGS += -I$(srcdir)/../lib/minitasn1
@@ -92,7 +93,7 @@ ctests = mini-record-2 simple gc set_pkcs12_cred cert certuniqueid \
mini-termination mini-x509-cas mini-x509-2 pkcs12_simple \
mini-emsgsize-dtls chainverify-unsorted mini-overhead \
mini-dtls-heartbeat mini-x509-callbacks key-openssl priorities \
- mini-dtls-srtp rsa-encrypt-decrypt mini-loss-time \
+ mini-dtls-srtp rsa-encrypt-decrypt mini-loss-time gnutls-strcodes \
mini-record mini-dtls-record mini-handshake-timeout mini-record-range \
mini-cert-status mini-rsa-psk global-init sec-params \
fips-test mini-global-load name-constraints x509-extensions \
@@ -240,7 +241,7 @@ ctests += ocsp
endif
if ENABLE_DANE
-ctests += dane
+ctests += dane dane-strcodes
endif
rsa_illegal_import_CPPFLAGS = $(AM_CPPFLAGS) $(NETTLE_CFLAGS)
diff --git a/tests/dane-strcodes.c b/tests/dane-strcodes.c
new file mode 100644
index 0000000000..030c7f20e0
--- /dev/null
+++ b/tests/dane-strcodes.c
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2017 Red Hat
+ *
+ * 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 <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <gnutls/gnutls.h>
+#include <gnutls/dane.h>
+
+#include "utils.h"
+
+/* Check whether the DANE string functions will return a non-repeated and
+ * non null value.
+ */
+
+static
+void _check_unique_non_null(int line, int i, const char *val)
+{
+ static char previous_val[128];
+
+ if (val == NULL)
+ fail("issue in line %d, item %d\n", line, i);
+
+ if (strcmp(val, previous_val)==0) {
+ fail("issue in line %d, item %d: %s\n", line, i, val);
+ }
+
+ snprintf(previous_val, sizeof(previous_val), "%s", val);
+}
+
+#define check_unique_non_null(x) _check_unique_non_null(__LINE__, i, x)
+
+void doit(void)
+{
+ int ret;
+ int i;
+
+ ret = global_init();
+ if (ret < 0) {
+ fail("global_init\n");
+ exit(1);
+ }
+
+ for (i=0;i<4;i++)
+ check_unique_non_null(dane_cert_usage_name(i));
+
+ for (i=0;i<1;i++)
+ check_unique_non_null(dane_cert_type_name(i));
+
+ for (i=0;i<3;i++)
+ check_unique_non_null(dane_match_type_name(i));
+
+ for (i=-14;i<=0;i++) {
+ check_unique_non_null(dane_strerror(i));
+ }
+
+ gnutls_global_deinit();
+}
diff --git a/tests/gnutls-strcodes.c b/tests/gnutls-strcodes.c
new file mode 100644
index 0000000000..69d2228424
--- /dev/null
+++ b/tests/gnutls-strcodes.c
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2017 Red Hat
+ *
+ * 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 <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <gnutls/gnutls.h>
+#include <gnutls/dane.h>
+
+#include "utils.h"
+
+/* Check whether the string functions will return a non-repeated and
+ * non null value.
+ */
+
+static
+void _check_non_null(int line, int i, const char *val)
+{
+ if (val == NULL)
+ fail("issue in line %d, item %d\n", line, i);
+}
+
+static
+void _check_unique_non_null(int line, int i, const char *val)
+{
+ static char previous_val[128];
+
+ if (val == NULL)
+ fail("issue in line %d, item %d\n", line, i);
+
+ if (strcmp(val, previous_val)==0) {
+ fail("issue in line %d, item %d: %s\n", line, i, val);
+ }
+
+ snprintf(previous_val, sizeof(previous_val), "%s", val);
+}
+
+static
+void _check_unique(int line, int i, const char *val)
+{
+ static char previous_val[128];
+
+ if (val == NULL) {
+ previous_val[0] = 0;
+ return;
+ }
+
+ if (strcmp(val, previous_val)==0)
+ fail("issue in line %d, item %d: %s\n", line, i, val);
+
+ snprintf(previous_val, sizeof(previous_val), "%s", val);
+}
+
+#define check_unique(x) _check_unique(__LINE__, i, x)
+#define check_unique_non_null(x) _check_unique_non_null(__LINE__, i, x)
+#define check_non_null(x) _check_non_null(__LINE__, i, x)
+
+void doit(void)
+{
+ int ret;
+ int i;
+
+ ret = global_init();
+ if (ret < 0) {
+ fail("global_init\n");
+ exit(1);
+ }
+
+ for (i=GNUTLS_E_UNIMPLEMENTED_FEATURE;i<=0;i++) {
+ check_unique(gnutls_strerror(i));
+ check_unique(gnutls_strerror_name(i));
+ }
+
+ for (i=0;i<GNUTLS_HANDSHAKE_CHANGE_CIPHER_SPEC;i++)
+ check_non_null(gnutls_handshake_description_get_name(i));
+
+ for (i=GNUTLS_PK_UNKNOWN+1;i<GNUTLS_PK_MAX;i++)
+ check_unique_non_null(gnutls_pk_algorithm_get_name(i));
+
+ for (i=GNUTLS_SIGN_UNKNOWN+1;i<GNUTLS_SIGN_MAX;i++) {
+ if (i==19) continue;
+ check_unique_non_null(gnutls_sign_algorithm_get_name(i));
+ }
+
+ for (i=GNUTLS_A_CLOSE_NOTIFY;i<GNUTLS_A_MAX;i++) {
+ check_unique(gnutls_alert_get_strname(i));
+ }
+
+ for (i=GNUTLS_SEC_PARAM_INSECURE;i<GNUTLS_SEC_PARAM_MAX;i++) {
+ check_non_null(gnutls_sec_param_get_name(i));
+ }
+
+ for (i=GNUTLS_ECC_CURVE_INVALID+1;i<GNUTLS_ECC_CURVE_MAX;i++) {
+ check_unique_non_null(gnutls_ecc_curve_get_name(i));
+ if (i == GNUTLS_ECC_CURVE_X25519)
+ continue; /* no oid yet */
+ check_unique_non_null(gnutls_ecc_curve_get_oid(i));
+ }
+
+ gnutls_global_deinit();
+}