2012-07-25 17:06:34 -05:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2012-07-25 17:06:34 -05:00
|
|
|
*
|
2016-06-27 14:56:38 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
2020-09-14 16:20:40 -07:00
|
|
|
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
2018-02-23 09:53:12 +01:00
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
2012-07-25 17:06:34 -05:00
|
|
|
*/
|
|
|
|
|
2018-10-24 10:24:35 -07:00
|
|
|
#if HAVE_CMOCKA
|
2012-07-25 17:06:34 -05:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <sched.h> /* IWYU pragma: keep */
|
|
|
|
#include <setjmp.h>
|
2018-10-24 10:24:35 -07:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2012-07-25 17:06:34 -05:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2018-10-24 10:24:35 -07:00
|
|
|
#define UNIT_TESTING
|
|
|
|
#include <cmocka.h>
|
|
|
|
|
|
|
|
#include <isc/util.h>
|
|
|
|
|
2012-07-25 17:06:34 -05:00
|
|
|
#include <dns/rdataset.h>
|
|
|
|
#include <dns/rdatastruct.h>
|
|
|
|
|
|
|
|
#include "dnstest.h"
|
|
|
|
|
2018-10-24 10:24:35 -07:00
|
|
|
static int
|
2020-02-13 14:44:37 -08:00
|
|
|
_setup(void **state) {
|
2018-10-24 10:24:35 -07:00
|
|
|
isc_result_t result;
|
2012-07-25 17:06:34 -05:00
|
|
|
|
2018-10-24 10:24:35 -07:00
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
result = dns_test_begin(NULL, false);
|
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
2012-07-25 17:06:34 -05:00
|
|
|
|
2018-10-24 10:24:35 -07:00
|
|
|
return (0);
|
2012-07-25 17:06:34 -05:00
|
|
|
}
|
2018-10-24 10:24:35 -07:00
|
|
|
|
|
|
|
static int
|
2020-02-13 14:44:37 -08:00
|
|
|
_teardown(void **state) {
|
2018-10-24 10:24:35 -07:00
|
|
|
UNUSED(state);
|
|
|
|
|
|
|
|
dns_test_end();
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* test trimming of rdataset TTLs */
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
trimttl(void **state) {
|
|
|
|
dns_rdataset_t rdataset, sigrdataset;
|
2012-07-25 17:06:34 -05:00
|
|
|
dns_rdata_rrsig_t rrsig;
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_stdtime_t ttltimenow, ttltimeexpire;
|
2012-07-25 17:06:34 -05:00
|
|
|
|
|
|
|
ttltimenow = 10000000;
|
|
|
|
ttltimeexpire = ttltimenow + 800;
|
|
|
|
|
2018-10-24 10:24:35 -07:00
|
|
|
UNUSED(state);
|
2012-07-25 17:06:34 -05:00
|
|
|
|
|
|
|
dns_rdataset_init(&rdataset);
|
|
|
|
dns_rdataset_init(&sigrdataset);
|
|
|
|
|
|
|
|
rdataset.ttl = 900;
|
|
|
|
sigrdataset.ttl = 1000;
|
|
|
|
rrsig.timeexpire = ttltimeexpire;
|
|
|
|
rrsig.originalttl = 1000;
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_rdataset_trimttl(&rdataset, &sigrdataset, &rrsig, ttltimenow, true);
|
2018-10-24 10:24:35 -07:00
|
|
|
assert_int_equal(rdataset.ttl, 800);
|
|
|
|
assert_int_equal(sigrdataset.ttl, 800);
|
2012-07-25 17:06:34 -05:00
|
|
|
|
|
|
|
rdataset.ttl = 900;
|
|
|
|
sigrdataset.ttl = 1000;
|
|
|
|
rrsig.timeexpire = ttltimenow - 200;
|
|
|
|
rrsig.originalttl = 1000;
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_rdataset_trimttl(&rdataset, &sigrdataset, &rrsig, ttltimenow, true);
|
2018-10-24 10:24:35 -07:00
|
|
|
assert_int_equal(rdataset.ttl, 120);
|
|
|
|
assert_int_equal(sigrdataset.ttl, 120);
|
2012-07-25 17:06:34 -05:00
|
|
|
|
|
|
|
rdataset.ttl = 900;
|
|
|
|
sigrdataset.ttl = 1000;
|
|
|
|
rrsig.timeexpire = ttltimenow - 200;
|
|
|
|
rrsig.originalttl = 1000;
|
|
|
|
|
|
|
|
dns_rdataset_trimttl(&rdataset, &sigrdataset, &rrsig, ttltimenow,
|
2018-04-17 08:29:14 -07:00
|
|
|
false);
|
2018-10-24 10:24:35 -07:00
|
|
|
assert_int_equal(rdataset.ttl, 0);
|
|
|
|
assert_int_equal(sigrdataset.ttl, 0);
|
2012-07-25 17:06:34 -05:00
|
|
|
|
|
|
|
sigrdataset.ttl = 900;
|
|
|
|
rdataset.ttl = 1000;
|
|
|
|
rrsig.timeexpire = ttltimeexpire;
|
|
|
|
rrsig.originalttl = 1000;
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_rdataset_trimttl(&rdataset, &sigrdataset, &rrsig, ttltimenow, true);
|
2018-10-24 10:24:35 -07:00
|
|
|
assert_int_equal(rdataset.ttl, 800);
|
|
|
|
assert_int_equal(sigrdataset.ttl, 800);
|
2012-07-25 17:06:34 -05:00
|
|
|
|
|
|
|
sigrdataset.ttl = 900;
|
|
|
|
rdataset.ttl = 1000;
|
|
|
|
rrsig.timeexpire = ttltimenow - 200;
|
|
|
|
rrsig.originalttl = 1000;
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_rdataset_trimttl(&rdataset, &sigrdataset, &rrsig, ttltimenow, true);
|
2018-10-24 10:24:35 -07:00
|
|
|
assert_int_equal(rdataset.ttl, 120);
|
|
|
|
assert_int_equal(sigrdataset.ttl, 120);
|
2012-07-25 17:06:34 -05:00
|
|
|
|
|
|
|
sigrdataset.ttl = 900;
|
|
|
|
rdataset.ttl = 1000;
|
|
|
|
rrsig.timeexpire = ttltimenow - 200;
|
|
|
|
rrsig.originalttl = 1000;
|
|
|
|
|
|
|
|
dns_rdataset_trimttl(&rdataset, &sigrdataset, &rrsig, ttltimenow,
|
2018-04-17 08:29:14 -07:00
|
|
|
false);
|
2018-10-24 10:24:35 -07:00
|
|
|
assert_int_equal(rdataset.ttl, 0);
|
|
|
|
assert_int_equal(sigrdataset.ttl, 0);
|
|
|
|
}
|
2012-07-25 17:06:34 -05:00
|
|
|
|
2018-10-24 10:24:35 -07:00
|
|
|
int
|
2020-02-13 14:44:37 -08:00
|
|
|
main(void) {
|
2018-10-24 10:24:35 -07:00
|
|
|
const struct CMUnitTest tests[] = {
|
|
|
|
cmocka_unit_test_setup_teardown(trimttl, _setup, _teardown),
|
|
|
|
};
|
|
|
|
|
|
|
|
return (cmocka_run_group_tests(tests, NULL, NULL));
|
2012-07-25 17:06:34 -05:00
|
|
|
}
|
|
|
|
|
2018-10-24 10:24:35 -07:00
|
|
|
#else /* HAVE_CMOCKA */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2012-07-25 17:06:34 -05:00
|
|
|
|
2018-10-24 10:24:35 -07:00
|
|
|
int
|
2020-02-13 14:44:37 -08:00
|
|
|
main(void) {
|
2018-10-24 10:24:35 -07:00
|
|
|
printf("1..0 # Skipped: cmocka not available\n");
|
|
|
|
return (0);
|
2012-07-25 17:06:34 -05:00
|
|
|
}
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* if HAVE_CMOCKA */
|