]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved: tests for dns_question_new_service()
authorJames Coglan <james@neighbourhood.ie>
Thu, 30 May 2024 17:11:10 +0000 (18:11 +0100)
committerLuca Boccassi <bluca@debian.org>
Tue, 23 Jul 2024 12:09:46 +0000 (13:09 +0100)
src/resolve/test-dns-question.c

index 880bb996d833e785ff95bc4a3f6461b61c66f598..ff75fa08e5f2d4b4315939d34211f275ac804e3b 100644 (file)
@@ -118,4 +118,129 @@ TEST(dns_question_new_reverse_ipv4) {
         ASSERT_TRUE(dns_question_contains_key(question, key));
 }
 
+/* ================================================================
+ * dns_question_new_service()
+ * ================================================================ */
+
+TEST(dns_question_new_service_no_domain) {
+        _cleanup_(dns_question_unrefp) DnsQuestion *question = NULL;
+
+        ASSERT_ERROR(dns_question_new_service(&question, NULL, "_xmpp._tcp", NULL, 0, 0), EINVAL);
+        ASSERT_NULL(question);
+}
+
+TEST(dns_question_new_service_domain_only) {
+        _cleanup_(dns_question_unrefp) DnsQuestion *question = NULL;
+        _cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL;
+
+        ASSERT_OK(dns_question_new_service(&question, NULL, NULL, "www.example.com", 0, 0));
+        ASSERT_NOT_NULL(question);
+        ASSERT_EQ(dns_question_size(question), 1u);
+
+        key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_SRV, "www.example.com");
+        ASSERT_NOT_NULL(key);
+        ASSERT_TRUE(dns_question_contains_key(question, key));
+}
+
+TEST(dns_question_new_service_domain_ignores_idna) {
+        _cleanup_(dns_question_unrefp) DnsQuestion *question = NULL;
+        _cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL;
+
+        ASSERT_OK(dns_question_new_service(&question, NULL, NULL, "\xF0\x9F\x98\xB1.com", 0, 1));
+        ASSERT_NOT_NULL(question);
+        ASSERT_EQ(dns_question_size(question), 1u);
+
+        key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_SRV, "\xF0\x9F\x98\xB1.com");
+        ASSERT_NOT_NULL(key);
+        ASSERT_TRUE(dns_question_contains_key(question, key));
+}
+
+TEST(dns_question_new_service_with_type) {
+        _cleanup_(dns_question_unrefp) DnsQuestion *question = NULL;
+        _cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL;
+
+        ASSERT_OK(dns_question_new_service(&question, NULL, "_xmpp._tcp", "example.com", 0, 0));
+        ASSERT_NOT_NULL(question);
+        ASSERT_EQ(dns_question_size(question), 1u);
+
+        key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_SRV, "_xmpp._tcp.example.com");
+        ASSERT_NOT_NULL(key);
+        ASSERT_TRUE(dns_question_contains_key(question, key));
+}
+
+#if HAVE_LIBIDN || HAVE_LIBIDN2
+TEST(dns_question_new_service_with_type_applies_idna) {
+        _cleanup_(dns_question_unrefp) DnsQuestion *question = NULL;
+        _cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL;
+
+        ASSERT_OK(dns_question_new_service(&question, NULL, "_xmpp._tcp", "\xF0\x9F\x98\xB1.com", 0, 1));
+        ASSERT_NOT_NULL(question);
+        ASSERT_EQ(dns_question_size(question), 1u);
+
+        key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_SRV, "_xmpp._tcp.xn--s38h.com");
+        ASSERT_NOT_NULL(key);
+        ASSERT_TRUE(dns_question_contains_key(question, key));
+}
+
+TEST(dns_question_new_service_with_type_with_txt) {
+        _cleanup_(dns_question_unrefp) DnsQuestion *question = NULL;
+        DnsResourceKey *key = NULL;
+
+        ASSERT_OK(dns_question_new_service(&question, NULL, "_xmpp._tcp", "\xF0\x9F\x98\xB1.com", 1, 1));
+        ASSERT_NOT_NULL(question);
+        ASSERT_EQ(dns_question_size(question), 2u);
+
+        key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_SRV, "_xmpp._tcp.xn--s38h.com");
+        ASSERT_NOT_NULL(key);
+        ASSERT_TRUE(dns_question_contains_key(question, key));
+        dns_resource_key_unref(key);
+
+        key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_TXT, "_xmpp._tcp.xn--s38h.com");
+        ASSERT_NOT_NULL(key);
+        ASSERT_TRUE(dns_question_contains_key(question, key));
+        dns_resource_key_unref(key);
+}
+#endif
+
+TEST(dns_question_new_service_with_invalid_type) {
+        _cleanup_(dns_question_unrefp) DnsQuestion *question = NULL;
+
+        ASSERT_ERROR(dns_question_new_service(&question, NULL, "_xmpp.tcp", "example.com", 0, 0), EINVAL);
+        ASSERT_NULL(question);
+}
+
+TEST(dns_question_new_service_with_type_too_short) {
+        _cleanup_(dns_question_unrefp) DnsQuestion *question = NULL;
+
+        ASSERT_ERROR(dns_question_new_service(&question, NULL, "_xmpp", "example.com", 0, 0), EINVAL);
+        ASSERT_NULL(question);
+}
+
+TEST(dns_question_new_service_with_type_too_long) {
+        _cleanup_(dns_question_unrefp) DnsQuestion *question = NULL;
+
+        ASSERT_ERROR(dns_question_new_service(&question, NULL, "_xmpp._tcp._extra", "example.com", 0, 0), EINVAL);
+        ASSERT_NULL(question);
+}
+
+TEST(dns_question_new_service_with_service_and_type) {
+        _cleanup_(dns_question_unrefp) DnsQuestion *question = NULL;
+        _cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL;
+
+        ASSERT_OK(dns_question_new_service(&question, "service", "_xmpp._tcp", "example.com", 0, 0));
+        ASSERT_NOT_NULL(question);
+        ASSERT_EQ(dns_question_size(question), 1u);
+
+        key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_SRV, "service._xmpp._tcp.example.com");
+        ASSERT_NOT_NULL(key);
+        ASSERT_TRUE(dns_question_contains_key(question, key));
+}
+
+TEST(dns_question_new_service_with_service_no_type) {
+        _cleanup_(dns_question_unrefp) DnsQuestion *question = NULL;
+
+        ASSERT_ERROR(dns_question_new_service(&question, "service", NULL, "example.com", 0, 0), EINVAL);
+        ASSERT_NULL(question);
+}
+
 DEFINE_TEST_MAIN(LOG_DEBUG);