nsec3_test.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2012, 2014  Internet Systems Consortium, Inc. ("ISC")
00003  *
00004  * Permission to use, copy, modify, and/or distribute this software for any
00005  * purpose with or without fee is hereby granted, provided that the above
00006  * copyright notice and this permission notice appear in all copies.
00007  *
00008  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00009  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00010  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00011  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00012  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00013  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00014  * PERFORMANCE OF THIS SOFTWARE.
00015  */
00016 
00017 /* $Id$ */
00018 
00019 /*! \file */
00020 
00021 #include <config.h>
00022 
00023 #include <atf-c.h>
00024 
00025 #include <unistd.h>
00026 
00027 #include <dns/db.h>
00028 #include <dns/nsec3.h>
00029 
00030 #include "dnstest.h"
00031 
00032 #if defined(OPENSSL) || defined(PKCS11CRYPTO)
00033 /*
00034  * Helper functions
00035  */
00036 
00037 static void
00038 iteration_test(const char* file, unsigned int expected) {
00039         isc_result_t result;
00040         dns_db_t *db = NULL;
00041         unsigned int iterations;
00042 
00043         result = dns_test_begin(NULL, ISC_FALSE);
00044         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00045 
00046         result = dns_test_loaddb(&db, dns_dbtype_zone, "test", file);
00047         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00048 
00049         result = dns_nsec3_maxiterations(db, NULL, mctx, &iterations);
00050         ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
00051 
00052         ATF_REQUIRE_EQ(iterations, expected);
00053 
00054         dns_db_detach(&db);
00055 
00056         dns_test_end();
00057 }
00058 
00059 /*
00060  * Individual unit tests
00061  */
00062 
00063 ATF_TC(max_iterations);
00064 ATF_TC_HEAD(max_iterations, tc) {
00065         atf_tc_set_md_var(tc, "descr", "check that appropriate max iterations "
00066                           " is returned for different key size mixes");
00067 }
00068 ATF_TC_BODY(max_iterations, tc) {
00069 
00070         UNUSED(tc);
00071 
00072         iteration_test("testdata/nsec3/1024.db", 150);
00073         iteration_test("testdata/nsec3/2048.db", 500);
00074         iteration_test("testdata/nsec3/4096.db", 2500);
00075         iteration_test("testdata/nsec3/min-1024.db", 150);
00076         iteration_test("testdata/nsec3/min-2048.db", 500);
00077 }
00078 #else
00079 ATF_TC(untested);
00080 ATF_TC_HEAD(untested, tc) {
00081         atf_tc_set_md_var(tc, "descr", "skipping nsec3 test");
00082 }
00083 ATF_TC_BODY(untested, tc) {
00084         UNUSED(tc);
00085         atf_tc_skip("DNSSEC not available");
00086 }
00087 #endif
00088 
00089 /*
00090  * Main
00091  */
00092 ATF_TP_ADD_TCS(tp) {
00093 #if defined(OPENSSL) || defined(PKCS11CRYPTO)
00094         ATF_TP_ADD_TC(tp, max_iterations);
00095 #else
00096         ATF_TP_ADD_TC(tp, untested);
00097 #endif
00098 
00099         return (atf_no_error());
00100 }
00101 

Generated on Tue Apr 28 17:41:01 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha