summaryrefslogtreecommitdiff
path: root/src/test/test-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-03-22 17:59:49 +0100
committerLennart Poettering <lennart@poettering.net>2013-03-22 17:59:49 +0100
commitaa3c5cf8eefa36a3ae727fe136587381e590d333 (patch)
treeacbed0a1fb454bd7e89d9539aa70ab0012274cc4 /src/test/test-util.c
parent4468addca6d01a0d2d154371dd72f54307a9c786 (diff)
util: be more picky when validating hostnames
No longer allow dots at the beginning or end of host names, Or double dots. https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1152187/comments/14
Diffstat (limited to 'src/test/test-util.c')
-rw-r--r--src/test/test-util.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/test/test-util.c b/src/test/test-util.c
index cd017ef6fc..08310c83ca 100644
--- a/src/test/test-util.c
+++ b/src/test/test-util.c
@@ -325,6 +325,19 @@ static void test_bus_path_escape(void) {
test_bus_path_escape_one(":1", "_3a1");
}
+static void test_hostname_is_valid(void) {
+ assert(hostname_is_valid("foobar"));
+ assert(hostname_is_valid("foobar.com"));
+ assert(!hostname_is_valid("fööbar"));
+ assert(!hostname_is_valid(""));
+ assert(!hostname_is_valid("."));
+ assert(!hostname_is_valid(".."));
+ assert(!hostname_is_valid("foobar."));
+ assert(!hostname_is_valid(".foobar"));
+ assert(!hostname_is_valid("foo..bar"));
+ assert(!hostname_is_valid("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"));
+}
+
int main(int argc, char *argv[]) {
test_streq_ptr();
test_first_word();
@@ -349,6 +362,7 @@ int main(int argc, char *argv[]) {
test_default_term_for_tty();
test_memdup_multiply();
test_bus_path_escape();
+ test_hostname_is_valid();
return 0;
}