1 /* $NetBSD: nsec3_test.c,v 1.1.1.4 2014/12/10 03:34:43 christos Exp $ */
2
3 /*
4 * Copyright (C) 2012, 2014 Internet Systems Consortium, Inc. ("ISC")
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 /* Id */
20
21 /*! \file */
22
23 #include <config.h>
24
25 #include <atf-c.h>
26
27 #include <unistd.h>
28
29 #include <dns/db.h>
30 #include <dns/nsec3.h>
31
32 #include "dnstest.h"
33
34 #if defined(OPENSSL) || defined(PKCS11CRYPTO)
35 /*
36 * Helper functions
37 */
38
39 static void
iteration_test(const char * file,unsigned int expected)40 iteration_test(const char* file, unsigned int expected) {
41 isc_result_t result;
42 dns_db_t *db = NULL;
43 unsigned int iterations;
44
45 result = dns_test_begin(NULL, ISC_FALSE);
46 ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
47
48 result = dns_test_loaddb(&db, dns_dbtype_zone, "test", file);
49 ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
50
51 result = dns_nsec3_maxiterations(db, NULL, mctx, &iterations);
52 ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
53
54 ATF_REQUIRE_EQ(iterations, expected);
55
56 dns_db_detach(&db);
57
58 dns_test_end();
59 }
60
61 /*
62 * Individual unit tests
63 */
64
65 ATF_TC(max_iterations);
ATF_TC_HEAD(max_iterations,tc)66 ATF_TC_HEAD(max_iterations, tc) {
67 atf_tc_set_md_var(tc, "descr", "check that appropriate max iterations "
68 " is returned for different key size mixes");
69 }
ATF_TC_BODY(max_iterations,tc)70 ATF_TC_BODY(max_iterations, tc) {
71
72 UNUSED(tc);
73
74 iteration_test("testdata/nsec3/1024.db", 150);
75 iteration_test("testdata/nsec3/2048.db", 500);
76 iteration_test("testdata/nsec3/4096.db", 2500);
77 iteration_test("testdata/nsec3/min-1024.db", 150);
78 iteration_test("testdata/nsec3/min-2048.db", 500);
79 }
80 #else
81 ATF_TC(untested);
ATF_TC_HEAD(untested,tc)82 ATF_TC_HEAD(untested, tc) {
83 atf_tc_set_md_var(tc, "descr", "skipping nsec3 test");
84 }
ATF_TC_BODY(untested,tc)85 ATF_TC_BODY(untested, tc) {
86 UNUSED(tc);
87 atf_tc_skip("DNSSEC not available");
88 }
89 #endif
90
91 /*
92 * Main
93 */
ATF_TP_ADD_TCS(tp)94 ATF_TP_ADD_TCS(tp) {
95 #if defined(OPENSSL) || defined(PKCS11CRYPTO)
96 ATF_TP_ADD_TC(tp, max_iterations);
97 #else
98 ATF_TP_ADD_TC(tp, untested);
99 #endif
100
101 return (atf_no_error());
102 }
103
104