-/* SPDX-License-Identifier: LGPL-2.1+ */
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <arpa/inet.h>
#include <netinet/in.h>
#include "log.h"
#include "resolved-etc-hosts.h"
#include "strv.h"
+#include "tests.h"
#include "tmpfile-util.h"
static void test_parse_etc_hosts_system(void) {
f = fopen("/etc/hosts", "re");
if (!f) {
- assert_se(errno == -ENOENT);
+ assert_se(errno == ENOENT);
return;
}
"1::2::3 multi.colon\n"
"::0 some.where some.other\n"
- "0.0.0.0 black.listed\n"
+ "0.0.0.0 deny.listed\n"
"::5\t\t\t \tsome.where\tsome.other foobar.foo.foo\t\t\t\n"
" \n", f);
assert_se(fflush_and_check(f) >= 0);
assert_se(bn->n_allocated >= 1);
assert_se(address_equal_4(bn->addresses[0], inet_addr("1.2.3.6")));
- /* Those names do not follow the LDH rule, but so far we allow them.
- * Let's make this explicit by adding a test.
- * See https://tools.ietf.org/html/rfc1035#section-2.3.1 */
- FOREACH_STRING(s, "bad-dash-", "-bad-dash", "-bad-dash.bad-") {
- assert_se(bn = hashmap_get(hosts.by_name, s));
- assert_se(bn->n_addresses == 1);
- assert_se(bn->n_allocated >= 1);
- assert_se(address_equal_4(bn->addresses[0], inet_addr("1.2.3.7")));
- }
+ /* See https://tools.ietf.org/html/rfc1035#section-2.3.1 */
+ FOREACH_STRING(s, "bad-dash-", "-bad-dash", "-bad-dash.bad-")
+ assert_se(!hashmap_get(hosts.by_name, s));
assert_se(bn = hashmap_get(hosts.by_name, "before.comment"));
assert_se(bn->n_addresses == 4);
assert_se( set_contains(hosts.no_address, "some.where"));
assert_se( set_contains(hosts.no_address, "some.other"));
- assert_se( set_contains(hosts.no_address, "black.listed"));
+ assert_se( set_contains(hosts.no_address, "deny.listed"));
assert_se(!set_contains(hosts.no_address, "foobar.foo.foo"));
}
}
int main(int argc, char **argv) {
- log_set_max_level(LOG_DEBUG);
- log_parse_environment();
- log_open();
+ test_setup_logging(LOG_DEBUG);
if (argc == 1) {
test_parse_etc_hosts_system();