summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-04-20 18:42:25 +0200
committerThomas Haller <thaller@redhat.com>2022-04-20 19:01:54 +0200
commitb3359126ba6b1a8e1d8961f1c2fb20dc181fea6a (patch)
tree3568750ec7faa3cc2b55c8d8736fe3d8d69d5155
parent47a46344c74e5428b7bad1212a9fc3e68adba2b5 (diff)
downloadNetworkManager-b3359126ba6b1a8e1d8961f1c2fb20dc181fea6a.tar.gz
glib-aux/tests: fix test for nm_hostname_is_valid() for different HOST_NAME_MAX
nm_hostname_is_valid() determines the valid length based on HOST_NAME_MAX, which is defined differently for glibc and musl. Fixes: 9ff1f666809a ('glib-aux: add nm_hostname_is_valid() helper from systemd')
-rw-r--r--src/libnm-glib-aux/tests/test-shared-general.c41
1 files changed, 31 insertions, 10 deletions
diff --git a/src/libnm-glib-aux/tests/test-shared-general.c b/src/libnm-glib-aux/tests/test-shared-general.c
index 0d588f17b7..15e709b62c 100644
--- a/src/libnm-glib-aux/tests/test-shared-general.c
+++ b/src/libnm-glib-aux/tests/test-shared-general.c
@@ -2119,13 +2119,29 @@ test_hostname_is_valid(void)
g_assert(!nm_hostname_is_valid(".foobar", FALSE));
g_assert(!nm_hostname_is_valid("foo..bar", FALSE));
g_assert(!nm_hostname_is_valid("foo.bar..", FALSE));
- g_assert(
- !nm_hostname_is_valid("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
- FALSE));
- g_assert(!nm_hostname_is_valid(
- "au-xph5-rvgrdsb5hcxc-47et3a5vvkrc-server-wyoz4elpdpe3.openstack.local",
- FALSE));
+
+#define _assert_hostname_length(n, valid) \
+ G_STMT_START \
+ { \
+ const gsize _n = (n); \
+ gs_free char *_h = g_strnfill(_n, 'x'); \
+ gboolean _valid; \
+ \
+ _valid = nm_hostname_is_valid(_h, FALSE); \
+ g_assert_cmpint(_valid, ==, (valid)); \
+ } \
+ G_STMT_END
+
+ _assert_hostname_length(HOST_NAME_MAX - 10, TRUE);
+ _assert_hostname_length(HOST_NAME_MAX - 1, TRUE);
+ _assert_hostname_length(HOST_NAME_MAX, TRUE);
+ _assert_hostname_length(HOST_NAME_MAX + 1, FALSE);
+ _assert_hostname_length(HOST_NAME_MAX + 10, FALSE);
+
+ g_assert(nm_hostname_is_valid(
+ "au-xph5-rvgrdsb5hcxc-47et3a5vvkrc-server-wyoz4elpdpe3.openstack.local",
+ FALSE)
+ == (HOST_NAME_MAX >= 69));
g_assert(nm_hostname_is_valid("foobar", TRUE));
g_assert(nm_hostname_is_valid("foobar.com", TRUE));
@@ -2143,9 +2159,14 @@ test_hostname_is_valid(void)
g_assert(!nm_hostname_is_valid("foo..bar", TRUE));
g_assert(!nm_hostname_is_valid("foo.bar..", TRUE));
g_assert(
- !nm_hostname_is_valid("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
- "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
- TRUE));
+ nm_hostname_is_valid("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
+ TRUE)
+ == (HOST_NAME_MAX >= 64));
+ g_assert(
+ nm_hostname_is_valid("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
+ TRUE)
+ == (HOST_NAME_MAX >= 104));
}
/*****************************************************************************/