summaryrefslogtreecommitdiff
path: root/src/test/test-dns-domain.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2017-07-11 04:42:21 -0400
committerLennart Poettering <lennart@poettering.net>2017-07-11 10:42:21 +0200
commitad1f3fe6a816ddd7c2e80f4639825e88d93b5a98 (patch)
treea91f5615184170b98bd6365e81074b224db1fc9a /src/test/test-dns-domain.c
parente3e42fc2b52dbd284a56457269ca920d6ab46295 (diff)
downloadsystemd-ad1f3fe6a816ddd7c2e80f4639825e88d93b5a98.tar.gz
resolved: allow resolution of names which libidn2 considers invalid (#6315)
https://tools.ietf.org/html/rfc5891#section-4.2.3.1 says that > The Unicode string MUST NOT contain "--" (two consecutive hyphens) in the third > and fourth character positions and MUST NOT start or end with a "-" (hyphen). This means that libidn2 refuses to encode such names. Let's just resolve them without trying to use IDN.
Diffstat (limited to 'src/test/test-dns-domain.c')
-rw-r--r--src/test/test-dns-domain.c60
1 files changed, 46 insertions, 14 deletions
diff --git a/src/test/test-dns-domain.c b/src/test/test-dns-domain.c
index d86add94db..11cf0b1f0b 100644
--- a/src/test/test-dns-domain.c
+++ b/src/test/test-dns-domain.c
@@ -607,24 +607,53 @@ static void test_dns_name_common_suffix(void) {
test_dns_name_common_suffix_one("FOO.BAR", "tEST.bAR", "BAR");
}
-static void test_dns_name_apply_idna_one(const char *s, const char *result) {
-#if defined(HAVE_LIBIDN2) || defined(HAVE_LIBIDN)
+static void test_dns_name_apply_idna_one(const char *s, int expected, const char *result) {
_cleanup_free_ char *buf = NULL;
- assert_se(dns_name_apply_idna(s, &buf) >= 0);
- assert_se(dns_name_equal(buf, result) > 0);
-#endif
+ int r;
+
+ r = dns_name_apply_idna(s, &buf);
+ log_debug("dns_name_apply_idna: \"%s\" → %d/\"%s\" (expected %d/\"%s\")",
+ s, r, strnull(buf), expected, strnull(result));
+
+ assert_se(r == expected);
+ if (expected == 1)
+ assert_se(dns_name_equal(buf, result) == 1);
}
static void test_dns_name_apply_idna(void) {
- test_dns_name_apply_idna_one("", "");
- test_dns_name_apply_idna_one("foo", "foo");
- test_dns_name_apply_idna_one("foo.", "foo");
- test_dns_name_apply_idna_one("foo.bar", "foo.bar");
- test_dns_name_apply_idna_one("foo.bar.", "foo.bar");
- test_dns_name_apply_idna_one("föö", "xn--f-1gaa");
- test_dns_name_apply_idna_one("föö.", "xn--f-1gaa");
- test_dns_name_apply_idna_one("föö.bär", "xn--f-1gaa.xn--br-via");
- test_dns_name_apply_idna_one("föö.bär.", "xn--f-1gaa.xn--br-via");
+#if defined HAVE_LIBIDN2 || defined HAVE_LIBIDN
+ const int ret = 1;
+#else
+ const int ret = 0;
+#endif
+
+ /* IDNA2008 forbids names with hyphens in third and fourth positions
+ * (https://tools.ietf.org/html/rfc5891#section-4.2.3.1).
+ * IDNA2003 does not have this restriction
+ * (https://tools.ietf.org/html/rfc3490#section-5).
+ * This means that when using libidn we will transform and test more
+ * labels. If registrars follow IDNA2008 we'll just be performing a
+ * useless lookup.
+ */
+#if defined HAVE_LIBIDN
+ const int ret2 = 1;
+#else
+ const int ret2 = 0;
+#endif
+
+ test_dns_name_apply_idna_one("", ret, "");
+ test_dns_name_apply_idna_one("foo", ret, "foo");
+ test_dns_name_apply_idna_one("foo.", ret, "foo");
+ test_dns_name_apply_idna_one("foo.bar", ret, "foo.bar");
+ test_dns_name_apply_idna_one("foo.bar.", ret, "foo.bar");
+ test_dns_name_apply_idna_one("föö", ret, "xn--f-1gaa");
+ test_dns_name_apply_idna_one("föö.", ret, "xn--f-1gaa");
+ test_dns_name_apply_idna_one("föö.bär", ret, "xn--f-1gaa.xn--br-via");
+ test_dns_name_apply_idna_one("föö.bär.", ret, "xn--f-1gaa.xn--br-via");
+ test_dns_name_apply_idna_one("xn--f-1gaa.xn--br-via", ret, "xn--f-1gaa.xn--br-via");
+
+ test_dns_name_apply_idna_one("r3---sn-ab5l6ne7.googlevideo.com", ret2,
+ ret2 ? "r3---sn-ab5l6ne7.googlevideo.com" : "");
}
static void test_dns_name_is_valid_or_address(void) {
@@ -640,6 +669,9 @@ static void test_dns_name_is_valid_or_address(void) {
}
int main(int argc, char *argv[]) {
+ log_set_max_level(LOG_DEBUG);
+ log_parse_environment();
+ log_open();
test_dns_label_unescape();
test_dns_label_unescape_suffix();