git » chasquid » commit 01a6d08

test: Add a set of tests for handling bad/invalid configs

author Alberto Bertogli
2023-05-16 10:47:31 UTC
committer Alberto Bertogli
2023-05-16 23:44:54 UTC
parent 0c9d1536db11397a6e254531b71d118caf747ef0

test: Add a set of tests for handling bad/invalid configs

This patch adds a set of tests to validate chasquid's handling of bad
and invalid configurations, to make sure we fail as expected.

internal/smtpsrv/server.go +1 -1
test/t-01-simple_local/run.sh +0 -6
test/t-20-bad_configs/.gitignore +1 -0
test/t-20-bad_configs/c-01-empty/.expected-error +1 -0
test/t-20-bad_configs/c-02-all_dirs_missing/.expected-error +1 -0
test/t-20-bad_configs/c-02-all_dirs_missing/chasquid.conf +9 -0
test/t-20-bad_configs/c-03-no_certs/.expected-error +1 -0
test/t-20-bad_configs/c-03-no_certs/certs/testserver/.keep +0 -0
test/t-20-bad_configs/c-03-no_certs/chasquid.conf +9 -0
test/t-20-bad_configs/c-03-no_certs/domains/testserver/users +26 -0
test/t-20-bad_configs/c-04-no_cert_dirs/.expected-error +1 -0
test/t-20-bad_configs/c-04-no_cert_dirs/chasquid.conf +9 -0
test/t-20-bad_configs/c-04-no_cert_dirs/domains/testserver/users +26 -0
test/t-20-bad_configs/c-05-no_addrs/.expected-error +1 -0
test/t-20-bad_configs/c-05-no_addrs/chasquid.conf +5 -0
test/t-20-bad_configs/c-05-no_addrs/domains/testserver/users +26 -0
test/t-20-bad_configs/c-06-bad_maillog/.expected-error +1 -0
test/t-20-bad_configs/c-06-bad_maillog/chasquid.conf +11 -0
test/t-20-bad_configs/c-06-bad_maillog/domains/testserver/users +26 -0
test/t-20-bad_configs/c-07-bad_domain_info/.expected-error +1 -0
test/t-20-bad_configs/c-07-bad_domain_info/chasquid.conf +9 -0
test/t-20-bad_configs/c-07-bad_domain_info/domains/testserver/users +26 -0
test/t-20-bad_configs/c-08-bad_sts_cache/.expected-error +1 -0
test/t-20-bad_configs/c-08-bad_sts_cache/chasquid.conf +9 -0
test/t-20-bad_configs/c-08-bad_sts_cache/domains/testserver/users +26 -0
test/t-20-bad_configs/c-09-bad_queue_dir/.expected-error +1 -0
test/t-20-bad_configs/c-09-bad_queue_dir/chasquid.conf +9 -0
test/t-20-bad_configs/c-09-bad_queue_dir/domains/testserver/users +26 -0
test/t-20-bad_configs/data-c-07-bad_domain_info/domaininfo +1 -0
test/t-20-bad_configs/data-c-08-bad_sts_cache/sts-cache +1 -0
test/t-20-bad_configs/data-c-09-bad_queue_dir/queue +1 -0
test/t-20-bad_configs/run.sh +48 -0

diff --git a/internal/smtpsrv/server.go b/internal/smtpsrv/server.go
index f07c7b2..42be1d1 100644
--- a/internal/smtpsrv/server.go
+++ b/internal/smtpsrv/server.go
@@ -153,7 +153,7 @@ func (s *Server) InitDomainInfo(dir string) *domaininfo.DB {
 func (s *Server) InitQueue(path string, localC, remoteC courier.Courier) {
 	q, err := queue.New(path, s.localDomains, s.aliasesR, localC, remoteC)
 	if err != nil {
-		log.Fatalf("Error initializing queue: %v:", err)
+		log.Fatalf("Error initializing queue: %v", err)
 	}
 
 	err = q.Load()
diff --git a/test/t-01-simple_local/run.sh b/test/t-01-simple_local/run.sh
index 8427f11..2854b45 100755
--- a/test/t-01-simple_local/run.sh
+++ b/test/t-01-simple_local/run.sh
@@ -12,12 +12,6 @@ if ! chasquid --version > /dev/null; then
 	fail "chasquid --version failed"
 fi
 
-# This should fail, as it has no certificates.
-rm -f config/certs/testserver/*.pem
-if chasquid -v=2 --logfile=.logs/chasquid.log --config_dir=config; then
-	fail "chasquid should not start without certificates"
-fi
-
 generate_certs_for testserver
 chasquid-util-user-add user@testserver secretpassword
 chasquid-util-user-add someone@testserver secretpassword
diff --git a/test/t-20-bad_configs/.gitignore b/test/t-20-bad_configs/.gitignore
new file mode 100644
index 0000000..3b78ed9
--- /dev/null
+++ b/test/t-20-bad_configs/.gitignore
@@ -0,0 +1 @@
+!.expected-error
diff --git a/test/t-20-bad_configs/c-01-empty/.expected-error b/test/t-20-bad_configs/c-01-empty/.expected-error
new file mode 100644
index 0000000..96c463c
--- /dev/null
+++ b/test/t-20-bad_configs/c-01-empty/.expected-error
@@ -0,0 +1 @@
+open c-01-empty/chasquid.conf: no such file or directory
diff --git a/test/t-20-bad_configs/c-02-all_dirs_missing/.expected-error b/test/t-20-bad_configs/c-02-all_dirs_missing/.expected-error
new file mode 100644
index 0000000..47eb847
--- /dev/null
+++ b/test/t-20-bad_configs/c-02-all_dirs_missing/.expected-error
@@ -0,0 +1 @@
+open certs/: no such file or directory
diff --git a/test/t-20-bad_configs/c-02-all_dirs_missing/chasquid.conf b/test/t-20-bad_configs/c-02-all_dirs_missing/chasquid.conf
new file mode 100644
index 0000000..a47c3db
--- /dev/null
+++ b/test/t-20-bad_configs/c-02-all_dirs_missing/chasquid.conf
@@ -0,0 +1,9 @@
+smtp_address: ":1025"
+submission_address: ":1587"
+submission_over_tls_address: ":1465"
+
+mail_delivery_agent_bin: "test-mda"
+mail_delivery_agent_args: "%to%"
+
+data_dir: "../.data"
+mail_log_path: "../.logs/mail_log"
diff --git a/test/t-20-bad_configs/c-03-no_certs/.expected-error b/test/t-20-bad_configs/c-03-no_certs/.expected-error
new file mode 100644
index 0000000..57557bc
--- /dev/null
+++ b/test/t-20-bad_configs/c-03-no_certs/.expected-error
@@ -0,0 +1 @@
+At least one valid certificate is needed
diff --git a/test/t-20-bad_configs/c-03-no_certs/certs/testserver/.keep b/test/t-20-bad_configs/c-03-no_certs/certs/testserver/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/test/t-20-bad_configs/c-03-no_certs/chasquid.conf b/test/t-20-bad_configs/c-03-no_certs/chasquid.conf
new file mode 100644
index 0000000..a47c3db
--- /dev/null
+++ b/test/t-20-bad_configs/c-03-no_certs/chasquid.conf
@@ -0,0 +1,9 @@
+smtp_address: ":1025"
+submission_address: ":1587"
+submission_over_tls_address: ":1465"
+
+mail_delivery_agent_bin: "test-mda"
+mail_delivery_agent_args: "%to%"
+
+data_dir: "../.data"
+mail_log_path: "../.logs/mail_log"
diff --git a/test/t-20-bad_configs/c-03-no_certs/domains/testserver/users b/test/t-20-bad_configs/c-03-no_certs/domains/testserver/users
new file mode 100644
index 0000000..0ad775b
--- /dev/null
+++ b/test/t-20-bad_configs/c-03-no_certs/domains/testserver/users
@@ -0,0 +1,26 @@
+users:  {
+  key:  "someone"
+  value:  {
+    scrypt:  {
+      logN:  14
+      r:  8
+      p:  1
+      keyLen:  32
+      salt:  "J\x01\xed7]\x02\n\xe9;z[\x8d˱\x10\xc1"
+      encrypted:  "\xa50宴\xcbb\xc1!r]K\xd1yI\xa2\x99\x8d\xdaQx\x8e69\xac\xf4$\x01\x11\x03\x8d\x10"
+    }
+  }
+}
+users:  {
+  key:  "user"
+  value:  {
+    scrypt:  {
+      logN:  14
+      r:  8
+      p:  1
+      keyLen:  32
+      salt:  "\n\xc6\x1c\x8f\xb2\x0c\x15p\x8d\xa1\xc3\x05U6\xdb\xc4"
+      encrypted:  "\xc3\xe6B2\x84W\x1a\nq{\x07\xe0\x9c\x854\n\xac\xbc\xb7\x9c\x86Kyk\x8dj\x16\x1a\x8c$*N"
+    }
+  }
+}
diff --git a/test/t-20-bad_configs/c-04-no_cert_dirs/.expected-error b/test/t-20-bad_configs/c-04-no_cert_dirs/.expected-error
new file mode 100644
index 0000000..021beae
--- /dev/null
+++ b/test/t-20-bad_configs/c-04-no_cert_dirs/.expected-error
@@ -0,0 +1 @@
+No entries found in "certs/"
diff --git a/test/t-20-bad_configs/c-04-no_cert_dirs/chasquid.conf b/test/t-20-bad_configs/c-04-no_cert_dirs/chasquid.conf
new file mode 100644
index 0000000..a47c3db
--- /dev/null
+++ b/test/t-20-bad_configs/c-04-no_cert_dirs/chasquid.conf
@@ -0,0 +1,9 @@
+smtp_address: ":1025"
+submission_address: ":1587"
+submission_over_tls_address: ":1465"
+
+mail_delivery_agent_bin: "test-mda"
+mail_delivery_agent_args: "%to%"
+
+data_dir: "../.data"
+mail_log_path: "../.logs/mail_log"
diff --git a/test/t-20-bad_configs/c-04-no_cert_dirs/domains/testserver/users b/test/t-20-bad_configs/c-04-no_cert_dirs/domains/testserver/users
new file mode 100644
index 0000000..0ad775b
--- /dev/null
+++ b/test/t-20-bad_configs/c-04-no_cert_dirs/domains/testserver/users
@@ -0,0 +1,26 @@
+users:  {
+  key:  "someone"
+  value:  {
+    scrypt:  {
+      logN:  14
+      r:  8
+      p:  1
+      keyLen:  32
+      salt:  "J\x01\xed7]\x02\n\xe9;z[\x8d˱\x10\xc1"
+      encrypted:  "\xa50宴\xcbb\xc1!r]K\xd1yI\xa2\x99\x8d\xdaQx\x8e69\xac\xf4$\x01\x11\x03\x8d\x10"
+    }
+  }
+}
+users:  {
+  key:  "user"
+  value:  {
+    scrypt:  {
+      logN:  14
+      r:  8
+      p:  1
+      keyLen:  32
+      salt:  "\n\xc6\x1c\x8f\xb2\x0c\x15p\x8d\xa1\xc3\x05U6\xdb\xc4"
+      encrypted:  "\xc3\xe6B2\x84W\x1a\nq{\x07\xe0\x9c\x854\n\xac\xbc\xb7\x9c\x86Kyk\x8dj\x16\x1a\x8c$*N"
+    }
+  }
+}
diff --git a/test/t-20-bad_configs/c-05-no_addrs/.expected-error b/test/t-20-bad_configs/c-05-no_addrs/.expected-error
new file mode 100644
index 0000000..d0ca847
--- /dev/null
+++ b/test/t-20-bad_configs/c-05-no_addrs/.expected-error
@@ -0,0 +1 @@
+No address to listen on
diff --git a/test/t-20-bad_configs/c-05-no_addrs/chasquid.conf b/test/t-20-bad_configs/c-05-no_addrs/chasquid.conf
new file mode 100644
index 0000000..306089c
--- /dev/null
+++ b/test/t-20-bad_configs/c-05-no_addrs/chasquid.conf
@@ -0,0 +1,5 @@
+mail_delivery_agent_bin: "test-mda"
+mail_delivery_agent_args: "%to%"
+
+data_dir: "../.data"
+mail_log_path: "../.logs/mail_log"
diff --git a/test/t-20-bad_configs/c-05-no_addrs/domains/testserver/users b/test/t-20-bad_configs/c-05-no_addrs/domains/testserver/users
new file mode 100644
index 0000000..0ad775b
--- /dev/null
+++ b/test/t-20-bad_configs/c-05-no_addrs/domains/testserver/users
@@ -0,0 +1,26 @@
+users:  {
+  key:  "someone"
+  value:  {
+    scrypt:  {
+      logN:  14
+      r:  8
+      p:  1
+      keyLen:  32
+      salt:  "J\x01\xed7]\x02\n\xe9;z[\x8d˱\x10\xc1"
+      encrypted:  "\xa50宴\xcbb\xc1!r]K\xd1yI\xa2\x99\x8d\xdaQx\x8e69\xac\xf4$\x01\x11\x03\x8d\x10"
+    }
+  }
+}
+users:  {
+  key:  "user"
+  value:  {
+    scrypt:  {
+      logN:  14
+      r:  8
+      p:  1
+      keyLen:  32
+      salt:  "\n\xc6\x1c\x8f\xb2\x0c\x15p\x8d\xa1\xc3\x05U6\xdb\xc4"
+      encrypted:  "\xc3\xe6B2\x84W\x1a\nq{\x07\xe0\x9c\x854\n\xac\xbc\xb7\x9c\x86Kyk\x8dj\x16\x1a\x8c$*N"
+    }
+  }
+}
diff --git a/test/t-20-bad_configs/c-06-bad_maillog/.expected-error b/test/t-20-bad_configs/c-06-bad_maillog/.expected-error
new file mode 100644
index 0000000..5414931
--- /dev/null
+++ b/test/t-20-bad_configs/c-06-bad_maillog/.expected-error
@@ -0,0 +1 @@
+Error opening mail log: open /sys/bad-dir/mail_log: no such file or directory
diff --git a/test/t-20-bad_configs/c-06-bad_maillog/chasquid.conf b/test/t-20-bad_configs/c-06-bad_maillog/chasquid.conf
new file mode 100644
index 0000000..ece00e9
--- /dev/null
+++ b/test/t-20-bad_configs/c-06-bad_maillog/chasquid.conf
@@ -0,0 +1,11 @@
+smtp_address: ":1025"
+submission_address: ":1587"
+submission_over_tls_address: ":1465"
+
+mail_delivery_agent_bin: "test-mda"
+mail_delivery_agent_args: "%to%"
+
+data_dir: "../.data"
+
+# This is expected to be invalid, and impossible to mkdir.
+mail_log_path: "/sys/bad-dir/mail_log"
diff --git a/test/t-20-bad_configs/c-06-bad_maillog/domains/testserver/users b/test/t-20-bad_configs/c-06-bad_maillog/domains/testserver/users
new file mode 100644
index 0000000..0ad775b
--- /dev/null
+++ b/test/t-20-bad_configs/c-06-bad_maillog/domains/testserver/users
@@ -0,0 +1,26 @@
+users:  {
+  key:  "someone"
+  value:  {
+    scrypt:  {
+      logN:  14
+      r:  8
+      p:  1
+      keyLen:  32
+      salt:  "J\x01\xed7]\x02\n\xe9;z[\x8d˱\x10\xc1"
+      encrypted:  "\xa50宴\xcbb\xc1!r]K\xd1yI\xa2\x99\x8d\xdaQx\x8e69\xac\xf4$\x01\x11\x03\x8d\x10"
+    }
+  }
+}
+users:  {
+  key:  "user"
+  value:  {
+    scrypt:  {
+      logN:  14
+      r:  8
+      p:  1
+      keyLen:  32
+      salt:  "\n\xc6\x1c\x8f\xb2\x0c\x15p\x8d\xa1\xc3\x05U6\xdb\xc4"
+      encrypted:  "\xc3\xe6B2\x84W\x1a\nq{\x07\xe0\x9c\x854\n\xac\xbc\xb7\x9c\x86Kyk\x8dj\x16\x1a\x8c$*N"
+    }
+  }
+}
diff --git a/test/t-20-bad_configs/c-07-bad_domain_info/.expected-error b/test/t-20-bad_configs/c-07-bad_domain_info/.expected-error
new file mode 100644
index 0000000..05e09ff
--- /dev/null
+++ b/test/t-20-bad_configs/c-07-bad_domain_info/.expected-error
@@ -0,0 +1 @@
+Error opening domain info database: mkdir ../data-c-07-bad_domain_info/domaininfo: not a directory
diff --git a/test/t-20-bad_configs/c-07-bad_domain_info/chasquid.conf b/test/t-20-bad_configs/c-07-bad_domain_info/chasquid.conf
new file mode 100644
index 0000000..ce7a4b5
--- /dev/null
+++ b/test/t-20-bad_configs/c-07-bad_domain_info/chasquid.conf
@@ -0,0 +1,9 @@
+smtp_address: ":1025"
+submission_address: ":1587"
+submission_over_tls_address: ":1465"
+
+mail_delivery_agent_bin: "test-mda"
+mail_delivery_agent_args: "%to%"
+
+data_dir: "../data-c-07-bad_domain_info"
+mail_log_path: "../.logs/mail_log"
diff --git a/test/t-20-bad_configs/c-07-bad_domain_info/domains/testserver/users b/test/t-20-bad_configs/c-07-bad_domain_info/domains/testserver/users
new file mode 100644
index 0000000..0ad775b
--- /dev/null
+++ b/test/t-20-bad_configs/c-07-bad_domain_info/domains/testserver/users
@@ -0,0 +1,26 @@
+users:  {
+  key:  "someone"
+  value:  {
+    scrypt:  {
+      logN:  14
+      r:  8
+      p:  1
+      keyLen:  32
+      salt:  "J\x01\xed7]\x02\n\xe9;z[\x8d˱\x10\xc1"
+      encrypted:  "\xa50宴\xcbb\xc1!r]K\xd1yI\xa2\x99\x8d\xdaQx\x8e69\xac\xf4$\x01\x11\x03\x8d\x10"
+    }
+  }
+}
+users:  {
+  key:  "user"
+  value:  {
+    scrypt:  {
+      logN:  14
+      r:  8
+      p:  1
+      keyLen:  32
+      salt:  "\n\xc6\x1c\x8f\xb2\x0c\x15p\x8d\xa1\xc3\x05U6\xdb\xc4"
+      encrypted:  "\xc3\xe6B2\x84W\x1a\nq{\x07\xe0\x9c\x854\n\xac\xbc\xb7\x9c\x86Kyk\x8dj\x16\x1a\x8c$*N"
+    }
+  }
+}
diff --git a/test/t-20-bad_configs/c-08-bad_sts_cache/.expected-error b/test/t-20-bad_configs/c-08-bad_sts_cache/.expected-error
new file mode 100644
index 0000000..10a3137
--- /dev/null
+++ b/test/t-20-bad_configs/c-08-bad_sts_cache/.expected-error
@@ -0,0 +1 @@
+Failed to initialize STS cache: mkdir ../data-c-08-bad_sts_cache/sts-cache: not a directory
diff --git a/test/t-20-bad_configs/c-08-bad_sts_cache/chasquid.conf b/test/t-20-bad_configs/c-08-bad_sts_cache/chasquid.conf
new file mode 100644
index 0000000..be6f7d4
--- /dev/null
+++ b/test/t-20-bad_configs/c-08-bad_sts_cache/chasquid.conf
@@ -0,0 +1,9 @@
+smtp_address: ":1025"
+submission_address: ":1587"
+submission_over_tls_address: ":1465"
+
+mail_delivery_agent_bin: "test-mda"
+mail_delivery_agent_args: "%to%"
+
+data_dir: "../data-c-08-bad_sts_cache"
+mail_log_path: "../.logs/mail_log"
diff --git a/test/t-20-bad_configs/c-08-bad_sts_cache/domains/testserver/users b/test/t-20-bad_configs/c-08-bad_sts_cache/domains/testserver/users
new file mode 100644
index 0000000..0ad775b
--- /dev/null
+++ b/test/t-20-bad_configs/c-08-bad_sts_cache/domains/testserver/users
@@ -0,0 +1,26 @@
+users:  {
+  key:  "someone"
+  value:  {
+    scrypt:  {
+      logN:  14
+      r:  8
+      p:  1
+      keyLen:  32
+      salt:  "J\x01\xed7]\x02\n\xe9;z[\x8d˱\x10\xc1"
+      encrypted:  "\xa50宴\xcbb\xc1!r]K\xd1yI\xa2\x99\x8d\xdaQx\x8e69\xac\xf4$\x01\x11\x03\x8d\x10"
+    }
+  }
+}
+users:  {
+  key:  "user"
+  value:  {
+    scrypt:  {
+      logN:  14
+      r:  8
+      p:  1
+      keyLen:  32
+      salt:  "\n\xc6\x1c\x8f\xb2\x0c\x15p\x8d\xa1\xc3\x05U6\xdb\xc4"
+      encrypted:  "\xc3\xe6B2\x84W\x1a\nq{\x07\xe0\x9c\x854\n\xac\xbc\xb7\x9c\x86Kyk\x8dj\x16\x1a\x8c$*N"
+    }
+  }
+}
diff --git a/test/t-20-bad_configs/c-09-bad_queue_dir/.expected-error b/test/t-20-bad_configs/c-09-bad_queue_dir/.expected-error
new file mode 100644
index 0000000..f4b0e79
--- /dev/null
+++ b/test/t-20-bad_configs/c-09-bad_queue_dir/.expected-error
@@ -0,0 +1 @@
+Error initializing queue: mkdir ../data-c-09-bad_queue_dir/queue: not a directory
diff --git a/test/t-20-bad_configs/c-09-bad_queue_dir/chasquid.conf b/test/t-20-bad_configs/c-09-bad_queue_dir/chasquid.conf
new file mode 100644
index 0000000..f06216a
--- /dev/null
+++ b/test/t-20-bad_configs/c-09-bad_queue_dir/chasquid.conf
@@ -0,0 +1,9 @@
+smtp_address: ":1025"
+submission_address: ":1587"
+submission_over_tls_address: ":1465"
+
+mail_delivery_agent_bin: "test-mda"
+mail_delivery_agent_args: "%to%"
+
+data_dir: "../data-c-09-bad_queue_dir"
+mail_log_path: "../.logs/mail_log"
diff --git a/test/t-20-bad_configs/c-09-bad_queue_dir/domains/testserver/users b/test/t-20-bad_configs/c-09-bad_queue_dir/domains/testserver/users
new file mode 100644
index 0000000..0ad775b
--- /dev/null
+++ b/test/t-20-bad_configs/c-09-bad_queue_dir/domains/testserver/users
@@ -0,0 +1,26 @@
+users:  {
+  key:  "someone"
+  value:  {
+    scrypt:  {
+      logN:  14
+      r:  8
+      p:  1
+      keyLen:  32
+      salt:  "J\x01\xed7]\x02\n\xe9;z[\x8d˱\x10\xc1"
+      encrypted:  "\xa50宴\xcbb\xc1!r]K\xd1yI\xa2\x99\x8d\xdaQx\x8e69\xac\xf4$\x01\x11\x03\x8d\x10"
+    }
+  }
+}
+users:  {
+  key:  "user"
+  value:  {
+    scrypt:  {
+      logN:  14
+      r:  8
+      p:  1
+      keyLen:  32
+      salt:  "\n\xc6\x1c\x8f\xb2\x0c\x15p\x8d\xa1\xc3\x05U6\xdb\xc4"
+      encrypted:  "\xc3\xe6B2\x84W\x1a\nq{\x07\xe0\x9c\x854\n\xac\xbc\xb7\x9c\x86Kyk\x8dj\x16\x1a\x8c$*N"
+    }
+  }
+}
diff --git a/test/t-20-bad_configs/data-c-07-bad_domain_info/domaininfo b/test/t-20-bad_configs/data-c-07-bad_domain_info/domaininfo
new file mode 100644
index 0000000..2e72b83
--- /dev/null
+++ b/test/t-20-bad_configs/data-c-07-bad_domain_info/domaininfo
@@ -0,0 +1 @@
+This is a file, not a directory as expected
diff --git a/test/t-20-bad_configs/data-c-08-bad_sts_cache/sts-cache b/test/t-20-bad_configs/data-c-08-bad_sts_cache/sts-cache
new file mode 100644
index 0000000..2e72b83
--- /dev/null
+++ b/test/t-20-bad_configs/data-c-08-bad_sts_cache/sts-cache
@@ -0,0 +1 @@
+This is a file, not a directory as expected
diff --git a/test/t-20-bad_configs/data-c-09-bad_queue_dir/queue b/test/t-20-bad_configs/data-c-09-bad_queue_dir/queue
new file mode 100644
index 0000000..2e72b83
--- /dev/null
+++ b/test/t-20-bad_configs/data-c-09-bad_queue_dir/queue
@@ -0,0 +1 @@
+This is a file, not a directory as expected
diff --git a/test/t-20-bad_configs/run.sh b/test/t-20-bad_configs/run.sh
new file mode 100755
index 0000000..a31a194
--- /dev/null
+++ b/test/t-20-bad_configs/run.sh
@@ -0,0 +1,48 @@
+#!/bin/bash
+
+set -e
+. "$(dirname "$0")/../util/lib.sh"
+
+init
+check_hostaliases
+
+mkdir -p .logs
+
+if chasquid --config_dir=doesnotexist > .chasquid-doesnotexist.out 2>&1; then
+	fail "chasquid should not start without a config"
+fi
+
+# Create this empty directory. We can't use a .keep file because that defeats
+# the purpose of the test.
+mkdir -p c-04-no_cert_dirs/certs/
+
+# Generate certs for the tests that need them.
+for i in c-05-no_addrs c-06-bad_maillog c-07-bad_domain_info \
+	c-08-bad_sts_cache c-09-bad_queue_dir ;
+do
+	CONFDIR=$i/ generate_certs_for testserver
+done
+
+for i in c-*; do
+	if chasquid --config_dir="$i" > ".chasquid-$i.out" 2>&1; then
+		echo "$i failed; output:"
+		echo
+		cat ".chasquid-$i.out"
+		echo
+		fail "$i: chasquid should not start with this invalid config"
+	fi
+
+	# Test that they failed as expected, and not by chance/unrelated error.
+	if ! tail -n 1 ".chasquid-$i.out" \
+	   | grep -q -E "$(cat "$i/.expected-error")"; then
+		echo "$i failed"
+		echo "expected last line to match:"
+		echo "    '$(cat "$i/.expected-error")'"
+		echo "got last line:"
+		echo "    '$(tail -n 1 ".chasquid-$i.out")'"
+		echo
+		fail "$i: chasquid did not fail as expected"
+	fi
+done
+
+success