]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/resolve/test-resolved-etc-hosts.c
license: LGPL-2.1+ -> LGPL-2.1-or-later
[thirdparty/systemd.git] / src / resolve / test-resolved-etc-hosts.c
index 0a08294d17effa559b47dfc9108672ac74f64ee6..045952e825d4a1cc2ff24c631e12136552f34999 100644 (file)
@@ -1,4 +1,4 @@
-/* SPDX-License-Identifier: LGPL-2.1+ */
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
 
 #include <arpa/inet.h>
 #include <netinet/in.h>
@@ -10,6 +10,7 @@
 #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) {
@@ -19,7 +20,7 @@ static void test_parse_etc_hosts_system(void) {
 
         f = fopen("/etc/hosts", "re");
         if (!f) {
-                assert_se(errno == -ENOENT);
+                assert_se(errno == ENOENT);
                 return;
         }
 
@@ -64,7 +65,7 @@ static void test_parse_etc_hosts(void) {
               "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);
@@ -91,15 +92,9 @@ static void test_parse_etc_hosts(void) {
         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);
@@ -128,7 +123,7 @@ static void test_parse_etc_hosts(void) {
 
         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"));
 }
 
@@ -143,9 +138,7 @@ static void test_parse_file(const char *fname) {
 }
 
 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();