mirror of https://github.com/getdnsapi/getdns.git
Add test 255-yaml-config with basic test of getdns_yaml2dict.
This commit is contained in:
parent
eabad34af9
commit
9683a64f73
|
@ -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
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <getdns/getdns.h>
|
||||
#include <getdns/getdns_extra.h>
|
||||
|
||||
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);
|
||||
}
|
|
@ -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:
|
|
@ -0,0 +1,80 @@
|
|||
{
|
||||
"dnssec_return_status": 1000,
|
||||
"upstream_recursive_servers":
|
||||
[
|
||||
{
|
||||
"address_data": <bindata for 145.100.185.15>,
|
||||
"tls_auth_name": <bindata of "dnsovertls.sinodun.com">,
|
||||
"tls_pubkey_pinset":
|
||||
[
|
||||
{
|
||||
"digest": <bindata of "sha256">,
|
||||
"value": <bindata of 62lKu9HsDVbyiPenApnc4sfmSYTHOVfFgL3pyB+cBL4=>
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"address_data": <bindata for 145.100.185.16>,
|
||||
"tls_auth_name": <bindata of "dnsovertls1.sinodun.com">,
|
||||
"tls_pubkey_pinset":
|
||||
[
|
||||
{
|
||||
"digest": <bindata of "sha256">,
|
||||
"value": <bindata of cE2ecALeE5B+urJhDrJlVFmf38cJLAvqekONvjvpqUA=>
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"address_data": <bindata for 185.49.141.37>,
|
||||
"tls_auth_name": <bindata of "getdnsapi.net">,
|
||||
"tls_pubkey_pinset":
|
||||
[
|
||||
{
|
||||
"digest": <bindata of "sha256">,
|
||||
"value": <bindata of foxZRnIh9gZpWnl+zEiKa0EJ2rdCGroMWm02gaxSc9Q=>
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"address_data": <bindata for 184.105.193.78>,
|
||||
"tls_auth_name": <bindata of "unicast.censurfridns.dk">
|
||||
},
|
||||
{
|
||||
"address_data": <bindata for 2001:610:1:40ba:145:100:185:15>,
|
||||
"tls_auth_name": <bindata of "dnsovertls.sinodun.com">,
|
||||
"tls_pubkey_pinset":
|
||||
[
|
||||
{
|
||||
"digest": <bindata of "sha256">,
|
||||
"value": <bindata of 62lKu9HsDVbyiPenApnc4sfmSYTHOVfFgL3pyB+cBL4=>
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"address_data": <bindata for 2001:610:1:40ba:145:100:185:16>,
|
||||
"tls_auth_name": <bindata of "dnsovertls1.sinodun.com">,
|
||||
"tls_pubkey_pinset":
|
||||
[
|
||||
{
|
||||
"digest": <bindata of "sha256">,
|
||||
"value": <bindata of cE2ecALeE5B+urJhDrJlVFmf38cJLAvqekONvjvpqUA=>
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"address_data": <bindata for 2a04:b900:0:100::38>,
|
||||
"tls_auth_name": <bindata of "getdnsapi.net">,
|
||||
"tls_pubkey_pinset":
|
||||
[
|
||||
{
|
||||
"digest": <bindata of "sha256">,
|
||||
"value": <bindata of foxZRnIh9gZpWnl+zEiKa0EJ2rdCGroMWm02gaxSc9Q=>
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"address_data": <bindata for 2620:ff:c000:0:1:0:64:25>,
|
||||
"tls_auth_name": <bindata of "unicast.censurfridns.dk">
|
||||
}
|
||||
]
|
||||
}
|
|
@ -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
|
|
@ -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
|
|
@ -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"
|
Loading…
Reference in New Issue