summaryrefslogtreecommitdiffstats
path: root/common/t-mbox-util.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2018-07-27 11:56:06 +0200
committerWerner Koch <wk@gnupg.org>2018-07-27 12:24:23 +0200
commitddee9f9409fb5a089883eab0fadef7b9b7e61e72 (patch)
tree0eb9bef9122ae99b29b5e25903de6f2a4c7f4b68 /common/t-mbox-util.c
parentscd: Add support for Trustica Cryptoucan. (diff)
downloadgnupg2-ddee9f9409fb5a089883eab0fadef7b9b7e61e72.tar.xz
gnupg2-ddee9f9409fb5a089883eab0fadef7b9b7e61e72.zip
common: New function to validate domain names.
* common/mbox-util.c (is_valid_domain_name): New. * common/t-mbox-util.c (run_dns_test): New test. Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to '')
-rw-r--r--common/t-mbox-util.c55
1 files changed, 53 insertions, 2 deletions
diff --git a/common/t-mbox-util.c b/common/t-mbox-util.c
index 979d4b37c..fb1ac12e0 100644
--- a/common/t-mbox-util.c
+++ b/common/t-mbox-util.c
@@ -33,7 +33,7 @@
static void
-run_test (void)
+run_mbox_test (void)
{
static struct
{
@@ -93,13 +93,64 @@ run_test (void)
}
+static void
+run_dns_test (void)
+{
+ static struct
+ {
+ const char *name;
+ int valid;
+ } testtbl[] =
+ {
+ { "", 0 },
+ { ".", 0 },
+ { "-", 0 },
+ { "a", 1 },
+ { "ab", 1 },
+ { "a.b", 1 },
+ { "a.b.", 1 },
+ { ".a.b.", 0 },
+ { ".a.b", 0 },
+ { "-a.b", 0 },
+ { "a-.b", 0 },
+ { "a.-b", 0 },
+ { "a.b-", 0 },
+ { "a.b-.", 0 },
+ { "a..b", 0 },
+ { "ab.c", 1 },
+ { "a-b.c", 1 },
+ { "a-b-.c", 0 },
+ { "-a-b.c", 0 },
+ { "example.org", 1 },
+ { "x.example.org", 1 },
+ { "xy.example.org", 1 },
+ { "Xy.example.org", 1 },
+ { "-Xy.example.org", 0 },
+ { "Xy.example-.org", 0 },
+ { "foo.example.org..", 0 },
+ { "foo.example.org.", 1 },
+ { ".foo.example.org.", 0 },
+ { "..foo.example.org.", 0 },
+ { NULL, 0 }
+ };
+ int idx;
+
+ for (idx=0; testtbl[idx].name; idx++)
+ {
+ if (is_valid_domain_name (testtbl[idx].name) != testtbl[idx].valid)
+ fail (idx);
+ }
+}
+
+
int
main (int argc, char **argv)
{
(void)argc;
(void)argv;
- run_test ();
+ run_mbox_test ();
+ run_dns_test ();
return 0;
}