unbound 0.1
unitauth.c File Reference

Unit test for auth zone code. More...

#include "config.h"
#include "services/authzone.h"
#include "testcode/unitmain.h"
#include "util/regional.h"
#include "util/net_help.h"
#include "util/config_file.h"
#include "util/data/msgreply.h"
#include "services/cache/dns.h"
#include "sldns/str2wire.h"
#include "sldns/wire2str.h"
#include "sldns/sbuffer.h"

Data Structures

struct  q_ans
 struct for query and answer checks More...

Functions

static void tmpfilecleanup (void)
 cleanup tmp files at exit
static char * create_tmp_file (const char *s)
 create temp file, return (malloced) name string, write contents to it
static void del_tmp_file (char *fname)
 delete temp file and free name string
struct auth_zone * authtest_addzone (struct auth_zones *az, const char *name, char *fname)
 Add zone from file for testing.
static void checkfile (char *f1, char *f2)
 check that file is the same as other file
static void check_read_exact (const char *name, const char *zone)
 check that a zone (in string) can be read and reproduced
static void q_ans_parse (struct q_ans *q, struct regional *region, struct query_info **qinfo, int *fallback, uint8_t **dp_nm, size_t *dp_nmlen)
 parse q_ans structure for making query
static void pr_flags (sldns_buffer *buf, uint16_t flags)
 print flags to string
static void pr_rrs (sldns_buffer *buf, struct reply_info *rep)
 print RRs to string
static char * msgtostr (struct dns_msg *msg)
 create string for message
static void line_diff (const char *p, const char *q, const char *pdesc, const char *qdesc)
 find line diff between strings
static void q_ans_query (struct q_ans *q, struct auth_zones *az, struct query_info *qinfo, struct regional *region, int expected_fallback, uint8_t *dp_nm, size_t dp_nmlen)
 make q_ans query
static void check_az_q_ans (struct auth_zones *az, struct q_ans *queries)
 check queries on a loaded zone
static void check_queries (const char *name, const char *zone, struct q_ans *queries)
 check queries for a zone are returned as specified
static void authzone_compare_serial (void)
 Test authzone compare_serial.
static void authzone_read_test (void)
 Test authzone read from file.
static void authzone_query_test (void)
 Test authzone query from zone.
static void authzone_chunkline_count_parens_test (void)
 Test chunkline_count_parens output.
void authzone_test (void)
 test authzone code

Variables

static int vbmp = 0
 verbosity for this test
static const char * zone_example_com
 auth zone for test
static struct q_ans example_com_queries []
 queries for example.com: zone, query, flags, answer.
static int tempno = 0
 number of tmpfiles
static int delno = 0
 number of deleted files

Detailed Description

Unit test for auth zone code.

Function Documentation

◆ tmpfilecleanup()

void tmpfilecleanup ( void )
static

cleanup tmp files at exit

References tempno, tmpfilecleanup(), and vbmp.

Referenced by authzone_test(), and tmpfilecleanup().

◆ create_tmp_file()

char * create_tmp_file ( const char * s)
static

create temp file, return (malloced) name string, write contents to it

References create_tmp_file(), fatal_exit(), and tempno.

Referenced by check_queries(), check_read_exact(), and create_tmp_file().

◆ del_tmp_file()

void del_tmp_file ( char * fname)
static

delete temp file and free name string

References del_tmp_file(), delno, and tempno.

Referenced by check_queries(), check_read_exact(), and del_tmp_file().

◆ authtest_addzone()

◆ checkfile()

void checkfile ( char * f1,
char * f2 )
static

check that file is the same as other file

References checkfile(), fatal_exit(), log_info(), and unit_assert.

Referenced by check_read_exact(), and checkfile().

◆ check_read_exact()

void check_read_exact ( const char * name,
const char * zone )
static

◆ q_ans_parse()

void q_ans_parse ( struct q_ans * q,
struct regional * region,
struct query_info ** qinfo,
int * fallback,
uint8_t ** dp_nm,
size_t * dp_nmlen )
static

◆ pr_flags()

void pr_flags ( sldns_buffer * buf,
uint16_t flags )
static

print flags to string

References BIT_AA, BIT_AD, BIT_CD, BIT_QR, BIT_RA, BIT_RD, BIT_TC, BIT_Z, FLAGS_GET_RCODE, pr_flags(), and sldns_wire2str_rcode_buf().

Referenced by msgtostr(), and pr_flags().

◆ pr_rrs()

◆ msgtostr()

char * msgtostr ( struct dns_msg * msg)
static

◆ line_diff()

void line_diff ( const char * p,
const char * q,
const char * pdesc,
const char * qdesc )
static

find line diff between strings

References fatal_exit(), and line_diff().

Referenced by line_diff(), and q_ans_query().

◆ q_ans_query()

void q_ans_query ( struct q_ans * q,
struct auth_zones * az,
struct query_info * qinfo,
struct regional * region,
int expected_fallback,
uint8_t * dp_nm,
size_t dp_nmlen )
static

◆ check_az_q_ans()

void check_az_q_ans ( struct auth_zones * az,
struct q_ans * queries )
static

◆ check_queries()

void check_queries ( const char * name,
const char * zone,
struct q_ans * queries )
static

◆ authzone_compare_serial()

void authzone_compare_serial ( void )
static

Test authzone compare_serial.

References authzone_compare_serial(), unit_assert, and vbmp.

Referenced by authzone_compare_serial(), and authzone_test().

◆ authzone_read_test()

void authzone_read_test ( void )
static

Test authzone read from file.

References authzone_read_test(), check_read_exact(), vbmp, and zone_example_com.

Referenced by authzone_read_test(), and authzone_test().

◆ authzone_query_test()

void authzone_query_test ( void )
static

Test authzone query from zone.

References authzone_query_test(), check_queries(), example_com_queries, vbmp, and zone_example_com.

Referenced by authzone_query_test(), and authzone_test().

◆ authzone_chunkline_count_parens_test()

void authzone_chunkline_count_parens_test ( void )
static

◆ authzone_test()

void authzone_test ( void )

test authzone code

unit test for auth zone functions

test authzone code

References authzone_chunkline_count_parens_test(), authzone_compare_serial(), authzone_query_test(), authzone_read_test(), authzone_test(), tmpfilecleanup(), and unit_show_feature().

Referenced by authzone_test(), and main().

Variable Documentation

◆ vbmp

◆ zone_example_com

const char* zone_example_com
static

auth zone for test

Referenced by authzone_query_test(), and authzone_read_test().

◆ example_com_queries

struct q_ans example_com_queries[]
static

queries for example.com: zone, query, flags, answer.

end with NULL

Referenced by authzone_query_test().

◆ tempno

int tempno = 0
static

number of tmpfiles

Referenced by create_tmp_file(), del_tmp_file(), and tmpfilecleanup().

◆ delno

int delno = 0
static

number of deleted files

Referenced by del_tmp_file().