From 9683a64f733dcb93f858aff6a029a3660f1388fb Mon Sep 17 00:00:00 2001 From: Jim Hague Date: Wed, 13 Sep 2017 15:01:13 +0100 Subject: [PATCH] Add test 255-yaml-config with basic test of getdns_yaml2dict. --- .../255-yaml-config.Makefile | 15 ++++ .../255-yaml-config.tpkg/255-yaml-config.c | 60 ++++++++++++++ .../255-yaml-config.tpkg/255-yaml-config.dsc | 16 ++++ .../255-yaml-config.tpkg/255-yaml-config.good | 80 +++++++++++++++++++ .../255-yaml-config.input | 47 +++++++++++ .../255-yaml-config.tpkg/255-yaml-config.pre | 14 ++++ .../255-yaml-config.tpkg/255-yaml-config.test | 7 ++ 7 files changed, 239 insertions(+) create mode 100644 src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.Makefile create mode 100644 src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.c create mode 100644 src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.dsc create mode 100644 src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.good create mode 100644 src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.input create mode 100644 src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.pre create mode 100644 src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.test diff --git a/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.Makefile b/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.Makefile new file mode 100644 index 00000000..c297df6d --- /dev/null +++ b/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.Makefile @@ -0,0 +1,15 @@ +builddir = @BUILDDIR@ +testname = @TPKG_NAME@ +LIBTOOL = $(builddir)/libtool + +CFLAGS=-I$(builddir)/src +LDLIBS=$(builddir)/src/libgetdns.la + +.SUFFIXES: .c .o .a .lo .h + +.c.lo: + $(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) -c $< -o $@ + +$(testname): $(testname).lo + $(LIBTOOL) --tag=CC --mode=link $(CC) $(LDLIBS) $(LDFLAGS) -o $(testname) $(testname).lo + diff --git a/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.c b/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.c new file mode 100644 index 00000000..b2a5f15b --- /dev/null +++ b/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.c @@ -0,0 +1,60 @@ +#include +#include +#include +#include + +int main(int ac, char *av[]) +{ + FILE *f; + char *buf = NULL; + size_t len; + ssize_t bytes_read; + + f = fopen(av[1], "r"); + if (!f) { + fprintf(stderr, "Could not open %s", av[1]); + exit(EXIT_FAILURE); + } + + bytes_read = getdelim(&buf, &len, '\0', f); + fclose(f); + + if (bytes_read == -1) { + fprintf(stderr, "Could not read %s", av[1]); + exit(EXIT_FAILURE); + } + + buf = realloc(buf, bytes_read + 1); + if (!buf) { + fprintf(stderr, "Could not grow buffer"); + exit(EXIT_FAILURE); + } + buf[bytes_read] = '\0'; + + getdns_dict *dict = NULL; + getdns_return_t r; + + if (!(dict = getdns_dict_create())) { + fprintf(stderr, "Could not create dict"); + exit(EXIT_FAILURE); + } + + r = getdns_yaml2dict(buf, &dict); + if (r) { + fprintf(stderr, "Error setting dict data: %s", getdns_get_errorstr_by_id(r)); + getdns_dict_destroy(dict); + exit(EXIT_FAILURE); + } + + char *dict_str = getdns_pretty_print_dict(dict); + if (!dict_str) { + fprintf(stderr, "Could not convert dict to string"); + getdns_dict_destroy(dict); + exit(EXIT_FAILURE); + } + + printf("%s\n", dict_str); + free(dict_str); + getdns_dict_destroy(dict); + exit(EXIT_SUCCESS); +} diff --git a/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.dsc b/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.dsc new file mode 100644 index 00000000..e00f4468 --- /dev/null +++ b/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.dsc @@ -0,0 +1,16 @@ +BaseName: 255-yaml-config +Version: 1.0 +Description: Test YAML configuration +CreationDate: Wed 13 Sep 2017 12:42:32 BST +Maintainer: Jim Hague +Category: +Component: +CmdDepends: +Depends: 200-stub-only-compile.tpkg +Help: +Pre: 255-yaml-config.pre +Post: +Test: 255-yaml-config.test +AuxFiles: +Passed: +Failure: diff --git a/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.good b/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.good new file mode 100644 index 00000000..aae0e318 --- /dev/null +++ b/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.good @@ -0,0 +1,80 @@ +{ + "dnssec_return_status": 1000, + "upstream_recursive_servers": + [ + { + "address_data": , + "tls_auth_name": , + "tls_pubkey_pinset": + [ + { + "digest": , + "value": + } + ] + }, + { + "address_data": , + "tls_auth_name": , + "tls_pubkey_pinset": + [ + { + "digest": , + "value": + } + ] + }, + { + "address_data": , + "tls_auth_name": , + "tls_pubkey_pinset": + [ + { + "digest": , + "value": + } + ] + }, + { + "address_data": , + "tls_auth_name": + }, + { + "address_data": , + "tls_auth_name": , + "tls_pubkey_pinset": + [ + { + "digest": , + "value": + } + ] + }, + { + "address_data": , + "tls_auth_name": , + "tls_pubkey_pinset": + [ + { + "digest": , + "value": + } + ] + }, + { + "address_data": , + "tls_auth_name": , + "tls_pubkey_pinset": + [ + { + "digest": , + "value": + } + ] + }, + { + "address_data": , + "tls_auth_name": + } + ] +} diff --git a/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.input b/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.input new file mode 100644 index 00000000..68e4460f --- /dev/null +++ b/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.input @@ -0,0 +1,47 @@ +upstream_recursive_servers: +# IPv4 addresses +# The Surfnet/Sinodun servers + - address_data: 145.100.185.15 + tls_auth_name: "dnsovertls.sinodun.com" + tls_pubkey_pinset: + - digest: "sha256" + value: 62lKu9HsDVbyiPenApnc4sfmSYTHOVfFgL3pyB+cBL4= + - address_data: 145.100.185.16 + tls_auth_name: "dnsovertls1.sinodun.com" + tls_pubkey_pinset: + - digest: "sha256" + value: cE2ecALeE5B+urJhDrJlVFmf38cJLAvqekONvjvpqUA= +# The getdnsapi.net server + - address_data: 185.49.141.37 + tls_auth_name: "getdnsapi.net" + tls_pubkey_pinset: + - digest: "sha256" + value: foxZRnIh9gZpWnl+zEiKa0EJ2rdCGroMWm02gaxSc9Q= +# The uncensored DNS servers (no SPKI available) + - address_data: 184.105.193.78 + tls_auth_name: "unicast.censurfridns.dk" +# IPv6 addresses +# The Surfnet/Sinodun servers + - address_data: 2001:610:1:40ba:145:100:185:15 + tls_auth_name: "dnsovertls.sinodun.com" + tls_pubkey_pinset: + - digest: "sha256" + value: 62lKu9HsDVbyiPenApnc4sfmSYTHOVfFgL3pyB+cBL4= + - address_data: 2001:610:1:40ba:145:100:185:16 + tls_auth_name: "dnsovertls1.sinodun.com" + tls_pubkey_pinset: + - digest: "sha256" + value: cE2ecALeE5B+urJhDrJlVFmf38cJLAvqekONvjvpqUA= +# The getdnsapi.net server + - address_data: 2a04:b900:0:100::38 + tls_auth_name: "getdnsapi.net" + tls_pubkey_pinset: + - digest: "sha256" + value: foxZRnIh9gZpWnl+zEiKa0EJ2rdCGroMWm02gaxSc9Q= +# The uncensored DNS server (no SPKI available) + - address_data: 2620:ff:c000:0:1::64:25 + tls_auth_name: "unicast.censurfridns.dk" + +# Require DNSSEC validation. For releases earlier than 1.2 a trust anchor must +# be configured configured manually. This can be done with unbound-anchor. +dnssec_return_status: GETDNS_EXTENSION_TRUE diff --git a/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.pre b/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.pre new file mode 100644 index 00000000..802443c2 --- /dev/null +++ b/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.pre @@ -0,0 +1,14 @@ +# #-- 255-yaml-config.test --# +# source the master var file when it's there +[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master +# use .tpkg.var.test for in test variable passing +[ -f .tpkg.var.test ] && source .tpkg.var.test + +( + grep '^CC=' "${BUILDDIR}/build-stub-only/src/Makefile" + grep '^LDFLAGS=' "${BUILDDIR}/build-stub-only/src/Makefile" + + BUILDDIR4SED=`echo "${BUILDDIR}/build-stub-only" | sed 's/\//\\\\\//g'` + sed -e "s/@BUILDDIR@/${BUILDDIR4SED}/g" \ + -e "s/@TPKG_NAME@/${TPKG_NAME}/g" "${TPKG_NAME}.Makefile" +) > Makefile diff --git a/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.test b/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.test new file mode 100644 index 00000000..b3735fb4 --- /dev/null +++ b/src/test/tpkg/255-yaml-config.tpkg/255-yaml-config.test @@ -0,0 +1,7 @@ +# #-- 255-yaml-config.test --# +# source the master var file when it's there +[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master +# use .tpkg.var.test for in test variable passing +[ -f .tpkg.var.test ] && source .tpkg.var.test + +make && "./${TPKG_NAME}" 255-yaml-config.input | tee out && diff out "${TPKG_NAME}.good"