]>
git.saurik.com Git - apple/network_cmds.git/blob - unbound/testcode/unitanchor.c
8047eb2bf9889989fb397d37d5ee74ff67cae90f
2 * testcode/unitanchor.c - unit test for trust anchor storage.
4 * Copyright (c) 2007, NLnet Labs. All rights reserved.
6 * This software is open source.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
19 * Neither the name of the NLNET LABS nor the names of its contributors may
20 * be used to endorse or promote products derived from this software without
21 * specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 * Calls trust anchor unit tests. Exits with code 1 on a failure.
43 #include "util/data/dname.h"
44 #include "testcode/unitmain.h"
45 #include "validator/val_anchor.h"
46 #include "ldns/sbuffer.h"
47 #include "ldns/rrdef.h"
51 test_anchor_empty(struct val_anchors
* a
)
53 uint16_t c
= LDNS_RR_CLASS_IN
;
54 unit_assert(anchors_lookup(a
, (uint8_t*)"\000", 1, c
) == NULL
);
55 unit_assert(anchors_lookup(a
, (uint8_t*)"\003com\000", 5, c
) == NULL
);
56 unit_assert(anchors_lookup(a
,
57 (uint8_t*)"\007example\003com\000", 11, c
) == NULL
);
58 unit_assert(anchors_lookup(a
, (uint8_t*)"\002nl\000", 4, c
) == NULL
);
59 unit_assert(anchors_lookup(a
,
60 (uint8_t*)"\004labs\002nl\000", 9, c
) == NULL
);
61 unit_assert(anchors_lookup(a
,
62 (uint8_t*)"\004fabs\002nl\000", 9, c
) == NULL
);
65 /** test set of one anchor */
67 test_anchor_one(sldns_buffer
* buff
, struct val_anchors
* a
)
69 struct trust_anchor
* ta
;
70 uint16_t c
= LDNS_RR_CLASS_IN
;
71 unit_assert(anchor_store_str(a
, buff
,
72 "nl. DS 42860 5 1 14D739EB566D2B1A5E216A0BA4D17FA9B038BE4A"));
73 unit_assert(anchors_lookup(a
, (uint8_t*)"\000", 1, c
) == NULL
);
74 unit_assert(anchors_lookup(a
, (uint8_t*)"\003com\000", 5, c
) == NULL
);
75 unit_assert(anchors_lookup(a
,
76 (uint8_t*)"\007example\003com\000", 11, c
) == NULL
);
78 unit_assert((ta
=anchors_lookup(a
,
79 (uint8_t*)"\002nl\000", 4, c
)) != NULL
);
80 lock_basic_unlock(&ta
->lock
);
82 unit_assert((ta
=anchors_lookup(a
,
83 (uint8_t*)"\004labs\002nl\000", 9, c
)) != NULL
);
84 lock_basic_unlock(&ta
->lock
);
86 unit_assert((ta
=anchors_lookup(a
,
87 (uint8_t*)"\004fabs\002nl\000", 9, c
)) != NULL
);
88 lock_basic_unlock(&ta
->lock
);
90 unit_assert(anchors_lookup(a
, (uint8_t*)"\002oo\000", 4, c
) == NULL
);
93 /** test with several anchors */
95 test_anchors(sldns_buffer
* buff
, struct val_anchors
* a
)
97 struct trust_anchor
* ta
;
98 uint16_t c
= LDNS_RR_CLASS_IN
;
99 unit_assert(anchor_store_str(a
, buff
,
100 "labs.nl. DS 42860 5 1 14D739EB566D2B1A5E216A0BA4D17FA9B038BE4A"));
101 unit_assert(anchors_lookup(a
, (uint8_t*)"\000", 1, c
) == NULL
);
102 unit_assert(anchors_lookup(a
, (uint8_t*)"\003com\000", 5, c
) == NULL
);
103 unit_assert(anchors_lookup(a
,
104 (uint8_t*)"\007example\003com\000", 11, c
) == NULL
);
106 unit_assert(ta
= anchors_lookup(a
, (uint8_t*)"\002nl\000", 4, c
));
107 unit_assert(query_dname_compare(ta
->name
, (uint8_t*)"\002nl\000")==0);
108 lock_basic_unlock(&ta
->lock
);
110 unit_assert(ta
= anchors_lookup(a
,
111 (uint8_t*)"\004labs\002nl\000", 9, c
));
112 unit_assert(query_dname_compare(ta
->name
,
113 (uint8_t*)"\004labs\002nl\000") == 0);
114 lock_basic_unlock(&ta
->lock
);
116 unit_assert(ta
= anchors_lookup(a
,
117 (uint8_t*)"\004fabs\002nl\000", 9, c
));
118 unit_assert(query_dname_compare(ta
->name
,
119 (uint8_t*)"\002nl\000") == 0);
120 lock_basic_unlock(&ta
->lock
);
122 unit_assert(anchors_lookup(a
, (uint8_t*)"\002oo\000", 4, c
) == NULL
);
125 void anchors_test(void)
127 sldns_buffer
* buff
= sldns_buffer_new(65800);
128 struct val_anchors
* a
;
129 unit_show_feature("trust anchor store");
130 unit_assert(a
= anchors_create());
131 sldns_buffer_flip(buff
);
132 test_anchor_empty(a
);
133 test_anchor_one(buff
, a
);
134 test_anchors(buff
, a
);
136 sldns_buffer_free(buff
);