summary refs log tree commit diff
path: root/src/tests/test-policy-hosts.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/test-policy-hosts.c')
-rw-r--r--src/tests/test-policy-hosts.c595
1 files changed, 545 insertions, 50 deletions
diff --git a/src/tests/test-policy-hosts.c b/src/tests/test-policy-hosts.c
index e14f15e5..8865c426 100644
--- a/src/tests/test-policy-hosts.c
+++ b/src/tests/test-policy-hosts.c
@@ -23,12 +23,17 @@
 
 #include "nm-policy-hosts.h"
 
-#define FALLBACK_HOSTNAME "localhost.localdomain"
+#define FALLBACK_HOSTNAME4 "localhost.localdomain"
+#define FALLBACK_HOSTNAME6 "localhost6.localdomain6"
+
+#define DEBUG 0
 
 static void
 test_generic (const char *before,
               const char *after,
               const char *hostname,
+              const char *ip4_addr,
+              const char *ip6_addr,
               gboolean expect_error)
 {
 	char **lines;
@@ -40,7 +45,11 @@ test_generic (const char *before,
 	newc = nm_policy_get_etc_hosts ((const char **) lines,
 	                                strlen (before),
 	                                hostname,
-	                                FALLBACK_HOSTNAME,
+	                                NULL,
+	                                FALLBACK_HOSTNAME4,
+	                                FALLBACK_HOSTNAME6,
+	                                ip4_addr,
+	                                ip6_addr,
 	                                &error);
 	g_strfreev (lines);
 
@@ -50,17 +59,27 @@ test_generic (const char *before,
 		g_clear_error (&error);
 	} else if (after == NULL) {
 		/* No change to /etc/hosts required */
+#if DEBUG
+		if (newc != NULL) {
+			g_message ("\n- NEW ---------------------------------\n"
+			           "%s"
+			           "+ EXPECTED NONE +++++++++++++++++++++++++\n",
+			           newc->str);
+		}
+#endif
 		g_assert (newc == NULL);
 		g_assert (error == NULL);
 	} else {
 		g_assert (newc != NULL);
 		g_assert (error == NULL);
 
-#if 0
-		g_message ("\n--------------------------------------\n"
+#if DEBUG
+		g_message ("\n- NEW ---------------------------------\n"
 		           "%s"
-		           "--------------------------------------",
-		           newc->str);
+		           "+ EXPECTED ++++++++++++++++++++++++++++++\n"
+		           "%s"
+		           "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
+		           newc->str, after);
 #endif
 		g_assert (strlen (newc->str) == strlen (after));
 		g_assert (strcmp (newc->str, after) == 0);
@@ -80,7 +99,7 @@ static const char *generic_before = \
 static void
 test_hosts_generic (void)
 {
-	test_generic (generic_before, NULL, "localhost.localdomain", FALSE);
+	test_generic (generic_before, NULL, "localhost.localdomain", NULL, NULL, FALSE);
 }
 
 /*******************************************/
@@ -93,20 +112,19 @@ static const char *generic_no_boilerplate_before = \
 static void
 test_hosts_generic_no_boilerplate (void)
 {
-	test_generic (generic_no_boilerplate_before, NULL, "localhost.localdomain", FALSE);
+	test_generic (generic_no_boilerplate_before, NULL, "localhost.localdomain", NULL, NULL, FALSE);
 }
 
 /*******************************************/
 
 static const char *generic_no_boilerplate_no_lh_before = \
 	"127.0.0.1	localhost.localdomain\n"
-	"::1		localhost6.localdomain6 localhost6\n"
+	"::1		localhost6.localdomain6	localhost6\n"
 	"127.0.0.1	lcmd.us.intellitxt.com\n";
 
 static const char *generic_no_boilerplate_no_lh_after = \
-	"127.0.0.1	localhost\n"
-	"127.0.0.1	localhost.localdomain\n"
-	"::1		localhost6.localdomain6 localhost6\n"
+	"127.0.0.1	localhost.localdomain	localhost\n"
+	"::1	localhost6.localdomain6	localhost6\n"
 	"127.0.0.1	lcmd.us.intellitxt.com\n";
 
 static void
@@ -115,6 +133,8 @@ test_hosts_generic_no_boilerplate_no_lh (void)
 	test_generic (generic_no_boilerplate_no_lh_before,
 	              generic_no_boilerplate_no_lh_after,
 	              "localhost.localdomain",
+	              NULL,
+	              NULL,
 	              FALSE);
 }
 
@@ -128,7 +148,7 @@ static const char *generic_no_boilerplate_no_lh_no_host_before = \
 
 static const char *generic_no_boilerplate_no_lh_no_host_after = \
 	"127.0.0.1	comet	localhost.localdomain	localhost\n"
-	"::1		localhost6.localdomain6 localhost6\n"
+	"::1	comet	localhost6.localdomain6	localhost6\n"
 	"127.0.0.1	lcmd.us.intellitxt.com\n";
 
 static void
@@ -137,6 +157,8 @@ test_hosts_generic_no_boilerplate_no_lh_no_host (void)
 	test_generic (generic_no_boilerplate_no_lh_no_host_before,
 	              generic_no_boilerplate_no_lh_no_host_after,
 	              "comet",
+	              NULL,
+	              NULL,
 	              FALSE);
 }
 
@@ -148,35 +170,58 @@ static const char *named_generic_before = \
 	"::1		localhost6.localdomain6 localhost6\n"
 	"127.0.0.1	lcmd.us.intellitxt.com\n";
 
+static const char *named_generic_after = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"127.0.0.1	playboy	localhost.localdomain	localhost\n"
+	"::1	playboy	localhost6.localdomain6	localhost6\n"
+	"127.0.0.1	lcmd.us.intellitxt.com\n";
+
 static void
 test_hosts_named_generic (void)
 {
-	test_generic (named_generic_before, NULL, "playboy", FALSE);
+	test_generic (named_generic_before, named_generic_after, "playboy", NULL, NULL, FALSE);
 }
 
 /*******************************************/
 
-static const char *named_non127_before = \
+static const char *named4_non127_before = \
 	"# Do not remove the following line, or various programs\n"
 	"# that require network functionality will fail.\n"
 	"127.0.0.1	localhost.localdomain localhost\n"
-	"::1		localhost6.localdomain6 localhost6\n"
+	"::1	tomcat	localhost6.localdomain6 localhost6\n"
 	"127.0.0.1	lcmd.us.intellitxt.com\n"
 	"192.168.1.2	tomcat\n";
 
 static void
-test_hosts_named_non127 (void)
+test_hosts_named4_non127 (void)
 {
-	test_generic (named_non127_before, NULL, "tomcat", FALSE);
+	test_generic (named4_non127_before, NULL, "tomcat", "192.168.1.2", NULL, FALSE);
 }
 
 /*******************************************/
 
-static const char *named2_non127_before = \
+static const char *named6_non127_before = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"127.0.0.1	tomcat localhost.localdomain localhost\n"
+	"::1	localhost6.localdomain6 localhost6\n"
+	"127.0.0.1	lcmd.us.intellitxt.com\n"
+	"3001:abba::3234 tomcat\n";
+
+static void
+test_hosts_named6_non127 (void)
+{
+	test_generic (named6_non127_before, NULL, "tomcat", NULL, "3001:abba::3234", FALSE);
+}
+
+/*******************************************/
+
+static const char *named4_non127_more_before = \
 	"# Do not remove the following line, or various programs\n"
 	"# that require network functionality will fail.\n"
 	"127.0.0.1	localhost.localdomain localhost\n"
-	"::1		localhost6.localdomain6 localhost6\n"
+	"::1	tomcat	localhost6.localdomain6 localhost6\n"
 	"127.0.0.1	lcmd.us.intellitxt.com\n"
 	"192.168.1.2	tomcat\n"
 	"127.0.0.1	lcmd.us.intellitxt.com\n"
@@ -184,9 +229,28 @@ static const char *named2_non127_before = \
 	"127.0.0.1	cdn5.tribalfusion.com\n";
 
 static void
-test_hosts_named2_non127 (void)
+test_hosts_named4_non127_more (void)
+{
+	test_generic (named4_non127_more_before, NULL, "tomcat", "192.168.1.2", NULL, FALSE);
+}
+
+/*******************************************/
+
+static const char *named6_non127_more_before = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"127.0.0.1	tomcat localhost.localdomain localhost\n"
+	"::1	localhost6.localdomain6 localhost6\n"
+	"127.0.0.1	lcmd.us.intellitxt.com\n"
+	"3001:abba::3234	tomcat\n"
+	"127.0.0.1	lcmd.us.intellitxt.com\n"
+	"127.0.0.1	srx.main.ebayrtm.com\n"
+	"127.0.0.1	cdn5.tribalfusion.com\n";
+
+static void
+test_hosts_named6_non127_more (void)
 {
-	test_generic (named2_non127_before, NULL, "tomcat", FALSE);
+	test_generic (named6_non127_more_before, NULL, "tomcat", NULL, "3001:abba::3234", FALSE);
 }
 
 /*******************************************/
@@ -203,14 +267,14 @@ static const char *named_no_lh_after = \
 	"# Do not remove the following line, or various programs\n"
 	"# that require network functionality will fail.\n"
 	"127.0.0.1	localhost.localdomain	localhost\n"
-	"::1		localhost6.localdomain6 localhost6\n"
+	"::1	tomcat	localhost6.localdomain6	localhost6\n"
 	"127.0.0.1	lcmd.us.intellitxt.com\n"
 	"192.168.1.2	tomcat\n";
 
 static void
 test_hosts_named_no_localhost (void)
 {
-	test_generic (named_no_lh_before, named_no_lh_after, "tomcat", FALSE);
+	test_generic (named_no_lh_before, named_no_lh_after, "tomcat", "192.168.1.2", NULL, FALSE);
 }
 
 /*******************************************/
@@ -225,15 +289,14 @@ static const char *no_lh_before = \
 static const char *no_lh_after = \
 	"# Do not remove the following line, or various programs\n"
 	"# that require network functionality will fail.\n"
-	"127.0.0.1	localhost.localdomain	localhost\n"
-	"127.0.0.1	tomcat\n"
-	"::1		localhost6.localdomain6 localhost6\n"
+	"127.0.0.1	tomcat	localhost.localdomain	localhost\n"
+	"::1	tomcat	localhost6.localdomain6	localhost6\n"
 	"127.0.0.1	lcmd.us.intellitxt.com\n";
 
 static void
 test_hosts_no_localhost (void)
 {
-	test_generic (no_lh_before, no_lh_after, "tomcat", FALSE);
+	test_generic (no_lh_before, no_lh_after, "tomcat", NULL, NULL, FALSE);
 }
 
 /*******************************************/
@@ -247,12 +310,12 @@ static const char *named_last_before = \
 static void
 test_hosts_named_last (void)
 {
-	test_generic (named_last_before, NULL, "sparcbook.ausil.us", FALSE);
+	test_generic (named_last_before, NULL, "sparcbook.ausil.us", NULL, NULL, FALSE);
 }
 
 /*******************************************/
 
-static const char *no_host_before = \
+static const char *no_host4_before = \
 	"# Do not remove the following line, or various programs\n"
 	"# that require network functionality will fail.\n"
 	"::1		localhost6.localdomain6 localhost6\n"
@@ -262,11 +325,11 @@ static const char *no_host_before = \
 	"127.0.0.1	cdn5.tribalfusion.com\n"
 	"127.0.0.1	a.tribalfusion.com\n";
 
-static const char *no_host_after = \
+static const char *no_host4_after = \
 	"# Do not remove the following line, or various programs\n"
 	"# that require network functionality will fail.\n"
 	"127.0.0.1	comet	localhost.localdomain	localhost\n"
-	"::1		localhost6.localdomain6 localhost6\n"
+	"::1	comet	localhost6.localdomain6	localhost6\n"
 	"\n"
 	"127.0.0.1	lcmd.us.intellitxt.com\n"
 	"127.0.0.1	srx.main.ebayrtm.com\n"
@@ -274,9 +337,264 @@ static const char *no_host_after = \
 	"127.0.0.1	a.tribalfusion.com\n";
 
 static void
-test_hosts_no_host (void)
+test_hosts_no_host4 (void)
+{
+	test_generic (no_host4_before, no_host4_after, "comet", NULL, NULL, FALSE);
+}
+
+/*******************************************/
+
+static const char *no_host6_before = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"127.0.0.1	localhost.localdomain localhost\n"
+	"\n"
+	"127.0.0.1	lcmd.us.intellitxt.com\n";
+
+static const char *no_host6_after = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"127.0.0.1	comet	localhost.localdomain	localhost\n"
+	"::1	comet	localhost6.localdomain6	localhost6\n"
+	"\n"
+	"127.0.0.1	lcmd.us.intellitxt.com\n";
+
+static void
+test_hosts_no_host6 (void)
+{
+	test_generic (no_host6_before, no_host6_after, "comet", NULL, NULL, FALSE);
+}
+
+/*******************************************/
+
+static const char *named46_non127_before = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"127.0.0.1	localhost.localdomain localhost\n"
+	"::1	localhost6.localdomain6	localhost6\n"
+	"192.168.1.2 comet\n"
+	"3001:abba::3234 comet\n"
+	"\n"
+	"127.0.0.1	lcmd.us.intellitxt.com\n";
+
+static void
+test_hosts_named46_non127 (void)
+{
+	test_generic (named46_non127_before, NULL, "comet", "192.168.1.2", "3001:abba::3234", FALSE);
+}
+
+/*******************************************/
+
+static const char *named46_non127_long_before = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"127.0.0.1	localhost.localdomain localhost\n"
+	"::1	localhost6.localdomain6	localhost6\n"
+	"192.168.1.2 comet.space	comet\n"
+	"3001:abba::3234 comet.space	comet\n"
+	"\n"
+	"127.0.0.1	lcmd.us.intellitxt.com\n";
+
+static void
+test_hosts_named46_non127_long (void)
+{
+	test_generic (named46_non127_long_before, NULL, "comet.space", "192.168.1.2", "3001:abba::3234", FALSE);
+}
+
+/*******************************************/
+
+static const char *named46_non127_other4_before = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"127.0.0.1	localhost.localdomain localhost\n"
+	"::1	localhost6.localdomain6	localhost6\n"
+	"192.168.1.3	comet\n"
+	"3001:abba::3234	comet\n"
+	"\n"
+	"127.0.0.1	lcmd.us.intellitxt.com\n";
+
+static const char *named46_non127_other4_after = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"192.168.1.2	comet	# Added by NetworkManager\n"
+	"127.0.0.1	localhost.localdomain	localhost\n"
+	"::1	localhost6.localdomain6	localhost6\n"
+	"192.168.1.3	comet\n"
+	"3001:abba::3234	comet\n"
+	"\n"
+	"127.0.0.1	lcmd.us.intellitxt.com\n";
+
+static void
+test_hosts_named46_non127_other4 (void)
+{
+	test_generic (named46_non127_other4_before, named46_non127_other4_after, "comet", "192.168.1.2", "3001:abba::3234", FALSE);
+}
+
+/*******************************************/
+
+static const char *named46_non127_other4_long_before = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"127.0.0.1	localhost.localdomain localhost\n"
+	"::1	localhost6.localdomain6	localhost6\n"
+	"192.168.1.3	comet.space\n"
+	"3001:abba::3234	comet.space\n"
+	"\n"
+	"127.0.0.1	lcmd.us.intellitxt.com\n";
+
+static const char *named46_non127_other4_long_after = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"192.168.1.2	comet.space	comet	# Added by NetworkManager\n"
+	"127.0.0.1	localhost.localdomain	localhost\n"
+	"::1	localhost6.localdomain6	localhost6\n"
+	"192.168.1.3	comet.space\n"
+	"3001:abba::3234	comet.space\n"
+	"\n"
+	"127.0.0.1	lcmd.us.intellitxt.com\n";
+
+static void
+test_hosts_named46_non127_other4_long (void)
+{
+	test_generic (named46_non127_other4_long_before, named46_non127_other4_long_after, "comet.space", "192.168.1.2", "3001:abba::3234", FALSE);
+}
+
+/*******************************************/
+
+static const char *named46_non127_other6_before = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"127.0.0.1	localhost.localdomain localhost\n"
+	"::1	localhost6.localdomain6	localhost6\n"
+	"192.168.1.2	comet\n"
+	"3001:abba::9675	comet\n"
+	"\n"
+	"127.0.0.1	lcmd.us.intellitxt.com\n";
+
+static const char *named46_non127_other6_after = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"3001:abba::3234	comet	# Added by NetworkManager\n"
+	"127.0.0.1	localhost.localdomain	localhost\n"
+	"::1	localhost6.localdomain6	localhost6\n"
+	"192.168.1.2	comet\n"
+	"3001:abba::9675	comet\n"
+	"\n"
+	"127.0.0.1	lcmd.us.intellitxt.com\n";
+
+static void
+test_hosts_named46_non127_other6 (void)
+{
+	test_generic (named46_non127_other6_before, named46_non127_other6_after, "comet", "192.168.1.2", "3001:abba::3234", FALSE);
+}
+
+/*******************************************/
+
+static const char *named46_non127_other6_long_before = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"127.0.0.1	localhost.localdomain localhost\n"
+	"::1	localhost6.localdomain6	localhost6\n"
+	"192.168.1.2	comet.space\n"
+	"3001:abba::9675	comet.space\n"
+	"\n"
+	"127.0.0.1	lcmd.us.intellitxt.com\n";
+
+static const char *named46_non127_other6_long_after = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"3001:abba::3234	comet.space	comet	# Added by NetworkManager\n"
+	"127.0.0.1	localhost.localdomain	localhost\n"
+	"::1	localhost6.localdomain6	localhost6\n"
+	"192.168.1.2	comet.space\n"
+	"3001:abba::9675	comet.space\n"
+	"\n"
+	"127.0.0.1	lcmd.us.intellitxt.com\n";
+
+static void
+test_hosts_named46_non127_other6_long (void)
+{
+	test_generic (named46_non127_other6_long_before, named46_non127_other6_long_after, "comet.space", "192.168.1.2", "3001:abba::3234", FALSE);
+}
+
+/*******************************************/
+
+static const char *unnamed46_non127_before = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"127.0.0.1	localhost.localdomain localhost\n"
+	"::1	localhost6.localdomain6	localhost6\n"
+	"\n"
+	"127.0.0.1	lcmd.us.intellitxt.com\n";
+
+static const char *unnamed46_non127_after = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"192.168.1.2	comet	# Added by NetworkManager\n"
+	"3001:abba::3234	comet	# Added by NetworkManager\n"
+	"127.0.0.1	localhost.localdomain	localhost\n"
+	"::1	localhost6.localdomain6	localhost6\n"
+	"\n"
+	"127.0.0.1	lcmd.us.intellitxt.com\n";
+
+static void
+test_hosts_unnamed46_non127 (void)
 {
-	test_generic (no_host_before, no_host_after, "comet", FALSE);
+	test_generic (unnamed46_non127_before, unnamed46_non127_after, "comet", "192.168.1.2", "3001:abba::3234", FALSE);
+}
+
+/*******************************************/
+
+static const char *unnamed46_non127_long_before = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"127.0.0.1	localhost.localdomain localhost\n"
+	"::1	localhost6.localdomain6	localhost6\n"
+	"\n"
+	"127.0.0.1	lcmd.us.intellitxt.com\n";
+
+static const char *unnamed46_non127_long_after = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"192.168.1.2	comet.space	comet	# Added by NetworkManager\n"
+	"3001:abba::3234	comet.space	comet	# Added by NetworkManager\n"
+	"127.0.0.1	localhost.localdomain	localhost\n"
+	"::1	localhost6.localdomain6	localhost6\n"
+	"\n"
+	"127.0.0.1	lcmd.us.intellitxt.com\n";
+
+static void
+test_hosts_unnamed46_non127_long (void)
+{
+	test_generic (unnamed46_non127_long_before, unnamed46_non127_long_after, "comet.space", "192.168.1.2", "3001:abba::3234", FALSE);
+}
+
+/*******************************************/
+
+static const char *named46_non127_wrong_before = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"127.0.0.1	localhost.localdomain localhost\n"
+	"::1	localhost6.localdomain6	localhost6\n"
+	"192.168.1.3	comet	# Added by NetworkManager\n"
+	"3001:abba::9876	comet	# Added by NetworkManager\n"
+	"\n"
+	"127.0.0.1	lcmd.us.intellitxt.com\n";
+
+static const char *named46_non127_wrong_after = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"192.168.1.2	comet	# Added by NetworkManager\n"
+	"3001:abba::3234	comet	# Added by NetworkManager\n"
+	"127.0.0.1	localhost.localdomain	localhost\n"
+	"::1	localhost6.localdomain6	localhost6\n"
+	"\n"
+	"127.0.0.1	lcmd.us.intellitxt.com\n";
+
+static void
+test_hosts_named46_non127_wrong (void)
+{
+	test_generic (named46_non127_wrong_before, named46_non127_wrong_after, "comet", "192.168.1.2", "3001:abba::3234", FALSE);
 }
 
 /*******************************************/
@@ -301,24 +619,178 @@ static const char *long_before = \
 	"127.0.0.1	ad.doubleclick.net\n"
 	"127.0.0.1	oascentral.movietickets.com\n"
 	"127.0.0.1	view.atdmt.com\n"
-	"127.0.0.1	ads.chumcity.com\n"
-	"127.0.0.1	ads.as4x.tmcs.net\n"
-	"127.0.0.1	n4403ad.doubleclick.net\n"
-	"127.0.0.1	www.assoc-amazon.com\n"
-	"127.0.0.1	s25.sitemeter.com\n"
-	"127.0.0.1	adlog.com.com\n"
-	"127.0.0.1	ahs.laptopmag.com\n"
-	"127.0.0.1	altfarm.mediaplex.com\n"
-	"127.0.0.1	ads.addynamix.com\n"
-	"127.0.0.1	srx.main.ebayrtm.com\n"
-	"127.0.0.1	cdn5.tribalfusion.com\n"
-	"127.0.0.1	a.tribalfusion.com\n";
+	"127.0.0.1	ads.chumcity.com\n";
 
+static const char *long_after = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"127.0.0.1	comet	localhost.localdomain	localhost\n"
+	"::1	comet	localhost6.localdomain6	localhost6\n"
+	"\n"
+	"127.0.0.1	lcmd.us.intellitxt.com\n"
+	"127.0.0.1	adserver.adtech.de\n"
+	"127.0.0.1	a.as-us.falkag.net\n"
+	"127.0.0.1	a.as-eu.falkag.net\n"
+	"127.0.0.1	ads.doubleclick.com\n"
+	"\n"
+	"# random comment\n"
+	"127.0.0.1	m1.2mdn.net\n"
+	"127.0.0.1	ds.serving-sys.com\n"
+	"127.0.0.1	pagead2.googlesyndication.com\n"
+	"127.0.0.1	ad.doubleclick.com\n"
+	"127.0.0.1	ad.doubleclick.net\n"
+	"127.0.0.1	oascentral.movietickets.com\n"
+	"127.0.0.1	view.atdmt.com\n"
+	"127.0.0.1	ads.chumcity.com\n";
 
 static void
 test_hosts_long (void)
 {
-	test_generic (long_before, NULL, "comet", FALSE);
+	test_generic (long_before, long_after, "comet", NULL, NULL, FALSE);
+}
+
+/*******************************************/
+
+static const char *custom4_before = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"127.0.0.1	localhost.localdomain localhost pintglass\n"
+	"::1	localhost6.localdomain6	localhost6\n";
+
+static const char *custom4_after = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"127.0.0.1	comet	localhost.localdomain	localhost	pintglass\n"
+	"::1	comet	localhost6.localdomain6	localhost6\n";
+
+static void
+test_hosts_custom4 (void)
+{
+	test_generic (custom4_before, custom4_after, "comet", NULL, NULL, FALSE);
+}
+
+/*******************************************/
+
+static const char *custom6_before = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"127.0.0.1	localhost.localdomain localhost\n"
+	"::1	localhost6.localdomain6	localhost6	pintglass\n";
+
+static const char *custom6_after = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"127.0.0.1	comet	localhost.localdomain	localhost\n"
+	"::1	comet	localhost6.localdomain6	localhost6	pintglass\n";
+
+static void
+test_hosts_custom6 (void)
+{
+	test_generic (custom6_before, custom6_after, "comet", NULL, NULL, FALSE);
+}
+
+/*******************************************/
+
+static const char *custom46_before = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"127.0.0.1	localhost.localdomain localhost shotglass\n"
+	"::1	localhost6.localdomain6	localhost6 pintglass\n";
+
+static const char *custom46_after = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"127.0.0.1	comet	localhost.localdomain	localhost	shotglass\n"
+	"::1	comet	localhost6.localdomain6	localhost6	pintglass\n";
+
+static void
+test_hosts_custom46 (void)
+{
+	test_generic (custom46_before, custom46_after, "comet", NULL, NULL, FALSE);
+}
+
+/*******************************************/
+
+static const char *custom46_mixed_before = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"127.0.0.1	localhost.localdomain localhost shotglass\n"
+	"::1	localhost6.localdomain6	localhost6 pintglass\n";
+
+static const char *custom46_mixed_after = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"127.0.0.1	comet	localhost.localdomain	localhost	shotglass\n"
+	"::1	comet	localhost6.localdomain6	localhost6	pintglass\n";
+
+static void
+test_hosts_custom46_mixed (void)
+{
+	test_generic (custom46_mixed_before, custom46_mixed_after, "comet", NULL, NULL, FALSE);
+}
+
+/*******************************************/
+
+static const char *stale4_removed_before = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"1.2.3.4	comet	# Added by NetworkManager\n"
+	"127.0.0.1	localhost.localdomain localhost\n"
+	"::1	comet	localhost6.localdomain6	localhost6\n";
+
+static const char *stale4_removed_after = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"127.0.0.1	comet	localhost.localdomain	localhost\n"
+	"::1	comet	localhost6.localdomain6	localhost6\n";
+
+static void
+test_hosts_stale4_removed (void)
+{
+	test_generic (stale4_removed_before, stale4_removed_after, "comet", NULL, NULL, FALSE);
+}
+
+/*******************************************/
+
+static const char *stale6_removed_before = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"3001:abba::3234	comet	# Added by NetworkManager\n"
+	"127.0.0.1	comet	localhost.localdomain localhost\n"
+	"::1	localhost6.localdomain6	localhost6\n";
+
+static const char *stale6_removed_after = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"127.0.0.1	comet	localhost.localdomain	localhost\n"
+	"::1	comet	localhost6.localdomain6	localhost6\n";
+
+static void
+test_hosts_stale6_removed (void)
+{
+	test_generic (stale6_removed_before, stale6_removed_after, "comet", NULL, NULL, FALSE);
+}
+
+/*******************************************/
+
+static const char *stale46_removed_before = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"1.2.3.4	comet	# Added by NetworkManager\n"
+	"3001:abba::3234	comet	# Added by NetworkManager\n"
+	"127.0.0.1	localhost.localdomain localhost\n"
+	"::1	localhost6.localdomain6	localhost6\n";
+
+static const char *stale46_removed_after = \
+	"# Do not remove the following line, or various programs\n"
+	"# that require network functionality will fail.\n"
+	"127.0.0.1	comet	localhost.localdomain	localhost\n"
+	"::1	comet	localhost6.localdomain6	localhost6\n";
+
+static void
+test_hosts_stale46_removed (void)
+{
+	test_generic (stale46_removed_before, stale46_removed_after, "comet", NULL, NULL, FALSE);
 }
 
 /*******************************************/
@@ -363,7 +835,11 @@ test_find_token (void)
 	}
 }
 
+#if GLIB_CHECK_VERSION(2,25,12)
+typedef GTestFixtureFunc TCFunc;
+#else
 typedef void (*TCFunc)(void);
+#endif
 
 #define TESTCASE(t, d) g_test_create_case (#t, 0, d, NULL, (TCFunc) t, NULL)
 
@@ -381,13 +857,32 @@ int main (int argc, char **argv)
 	g_test_suite_add (suite, TESTCASE (test_hosts_generic_no_boilerplate_no_lh, NULL));
 	g_test_suite_add (suite, TESTCASE (test_hosts_generic_no_boilerplate_no_lh_no_host, NULL));
 	g_test_suite_add (suite, TESTCASE (test_hosts_named_generic, NULL));
-	g_test_suite_add (suite, TESTCASE (test_hosts_named_non127, NULL));
-	g_test_suite_add (suite, TESTCASE (test_hosts_named2_non127, NULL));
+	g_test_suite_add (suite, TESTCASE (test_hosts_named4_non127, NULL));
+	g_test_suite_add (suite, TESTCASE (test_hosts_named6_non127, NULL));
+	g_test_suite_add (suite, TESTCASE (test_hosts_named4_non127_more, NULL));
+	g_test_suite_add (suite, TESTCASE (test_hosts_named6_non127_more, NULL));
+	g_test_suite_add (suite, TESTCASE (test_hosts_named46_non127, NULL));
+	g_test_suite_add (suite, TESTCASE (test_hosts_named46_non127_long, NULL));
+	g_test_suite_add (suite, TESTCASE (test_hosts_named46_non127_other4, NULL));
+	g_test_suite_add (suite, TESTCASE (test_hosts_named46_non127_other4_long, NULL));
+	g_test_suite_add (suite, TESTCASE (test_hosts_named46_non127_other6, NULL));
+	g_test_suite_add (suite, TESTCASE (test_hosts_named46_non127_other6_long, NULL));
+	g_test_suite_add (suite, TESTCASE (test_hosts_named46_non127_wrong, NULL));
+	g_test_suite_add (suite, TESTCASE (test_hosts_unnamed46_non127, NULL));
+	g_test_suite_add (suite, TESTCASE (test_hosts_unnamed46_non127_long, NULL));
 	g_test_suite_add (suite, TESTCASE (test_hosts_named_no_localhost, NULL));
 	g_test_suite_add (suite, TESTCASE (test_hosts_no_localhost, NULL));
 	g_test_suite_add (suite, TESTCASE (test_hosts_named_last, NULL));
-	g_test_suite_add (suite, TESTCASE (test_hosts_no_host, NULL));
+	g_test_suite_add (suite, TESTCASE (test_hosts_no_host4, NULL));
+	g_test_suite_add (suite, TESTCASE (test_hosts_no_host6, NULL));
 	g_test_suite_add (suite, TESTCASE (test_hosts_long, NULL));
+	g_test_suite_add (suite, TESTCASE (test_hosts_custom4, NULL));
+	g_test_suite_add (suite, TESTCASE (test_hosts_custom6, NULL));
+	g_test_suite_add (suite, TESTCASE (test_hosts_custom46, NULL));
+	g_test_suite_add (suite, TESTCASE (test_hosts_custom46_mixed, NULL));
+	g_test_suite_add (suite, TESTCASE (test_hosts_stale4_removed, NULL));
+	g_test_suite_add (suite, TESTCASE (test_hosts_stale6_removed, NULL));
+	g_test_suite_add (suite, TESTCASE (test_hosts_stale46_removed, NULL));
 
 	return g_test_run ();
 }