summaryrefslogtreecommitdiff
path: root/src/test/test-dns-domain.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-11-20 17:52:36 +0100
committerLennart Poettering <lennart@poettering.net>2015-11-23 21:31:28 +0100
commit0a49b6b6dce3a756bd8c4d458a34c2d8035ae99d (patch)
tree5d898be726a9560f44184a9d0af43d7de2c09cd7 /src/test/test-dns-domain.c
parente429762faaac0c49353d35144a9d45d283e91213 (diff)
dns-domain: add code for verifying validity of DNS-SD service names and types
Diffstat (limited to 'src/test/test-dns-domain.c')
-rw-r--r--src/test/test-dns-domain.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/test/test-dns-domain.c b/src/test/test-dns-domain.c
index 407c7d8ef7..a23d5dee05 100644
--- a/src/test/test-dns-domain.c
+++ b/src/test/test-dns-domain.c
@@ -316,6 +316,40 @@ static void test_dns_name_is_valid(void) {
test_dns_name_is_valid_one("\n", 0);
}
+static void test_dns_service_name_is_valid(void) {
+ assert_se(dns_service_name_is_valid("Lennart's Compüter"));
+ assert_se(dns_service_name_is_valid("piff.paff"));
+
+ assert_se(!dns_service_name_is_valid(NULL));
+ assert_se(!dns_service_name_is_valid(""));
+ assert_se(!dns_service_name_is_valid("foo\nbar"));
+ assert_se(!dns_service_name_is_valid("foo\201bar"));
+ assert_se(!dns_service_name_is_valid("this is an overly long string that is certainly longer than 63 characters"));
+}
+
+static void test_dns_srv_type_verify(void) {
+
+ assert_se(dns_srv_type_verify("_http._tcp") > 0);
+ assert_se(dns_srv_type_verify("_foo-bar._tcp") > 0);
+ assert_se(dns_srv_type_verify("_w._udp") > 0);
+ assert_se(dns_srv_type_verify("_piep._sub._w._udp") > 0);
+ assert_se(dns_srv_type_verify("_a800._tcp") > 0);
+ assert_se(dns_srv_type_verify("_a-800._tcp") > 0);
+
+ assert_se(dns_srv_type_verify(NULL) == 0);
+ assert_se(dns_srv_type_verify("") == 0);
+ assert_se(dns_srv_type_verify("x") == 0);
+ assert_se(dns_srv_type_verify("_foo") == 0);
+ assert_se(dns_srv_type_verify("_tcp") == 0);
+ assert_se(dns_srv_type_verify("_") == 0);
+ assert_se(dns_srv_type_verify("_foo.") == 0);
+ assert_se(dns_srv_type_verify("_föo._tcp") == 0);
+ assert_se(dns_srv_type_verify("_f\no._tcp") == 0);
+ assert_se(dns_srv_type_verify("_800._tcp") == 0);
+ assert_se(dns_srv_type_verify("_-800._tcp") == 0);
+ assert_se(dns_srv_type_verify("_-foo._tcp") == 0);
+}
+
int main(int argc, char *argv[]) {
test_dns_label_unescape();
@@ -331,6 +365,8 @@ int main(int argc, char *argv[]) {
test_dns_name_concat();
test_dns_name_is_valid();
test_dns_name_to_wire_format();
+ test_dns_service_name_is_valid();
+ test_dns_srv_type_verify();
return 0;
}