summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/README32
-rwxr-xr-xtest/create_mails.sh56
-rwxr-xr-xtest/run_test.sh55
-rw-r--r--test/test-config40
4 files changed, 183 insertions, 0 deletions
diff --git a/test/README b/test/README
new file mode 100644
index 0000000..595c31f
--- /dev/null
+++ b/test/README
@@ -0,0 +1,32 @@
+
+Pre-requisites
+--------------
+
+* SMTP server
+* POP3 server
+* bash (required for TCP redirects)
+
+
+create_mails.sh
+---------------
+
+This creates the test emails on the local system. Edit to set the test
+username.
+
+
+run_test.sh
+-----------
+
+Runs the simple confidence tests.
+
+
+test-config
+-----------
+
+The test configuration. Edit to set the test username and password.
+
+
+Notes
+-----
+
+These tests are *really* basic.
diff --git a/test/create_mails.sh b/test/create_mails.sh
new file mode 100755
index 0000000..15da45c
--- /dev/null
+++ b/test/create_mails.sh
@@ -0,0 +1,56 @@
+#!/bin/bash
+
+# Set this to the local user who will recieve the test emails.
+# It's recommended that this user is a simple non-login user
+# specifically for email testing.
+#
+UNAME=kbstest
+
+# Check the environment
+#
+if [ ! -x ../src/kbs ] ; then
+ echo kbs not built!
+ exit
+fi
+
+if [ "`netstat -a | egrep LISTEN | egrep smtp`" = "" ] ; then
+ echo No SMTP server
+ exit
+fi
+
+function email()
+{
+ cat << ENDMAIL > /dev/tcp/localhost/25
+HELO localhost
+MAIL FROM: $1
+RCPT TO: $UNAME
+DATA
+To: $2
+Subject: $3
+Content-Type: $4
+
+Test $5
+
+.
+QUIT
+ENDMAIL
+
+ echo Created email from $1 to $2
+}
+
+# Send the test emails
+#
+email "trusted@google.com" "uname@hostname" "" "text/plain" 1
+email "bad_user@microsoft.com" "uname@hostname" "good" "text/plain" 2
+email "trusted@google.com" "uname@hostname" "good" "text/plain" 3
+email "trusted@google.com" "uname@hostname" "bad" "text/plain" 4
+email "good_user@freebsd.org" "uname@hostname" "bad" "text/plain" 5
+email "good_user@freebsd.org" "uname@hostname" "bad" "text/html" 6
+email "good_user@google.com" "uname@hostname" "good" "text/plain" 7
+email "bad_user@google.com" "uname@hostname" "good" "text/html" 8
+email "bad_user@google.com" "uname@hostname" "bad" "text/plain" 9
+email "bad_user@google.com" "uname@hostname" "bad" "text/html" 10
+email "bad_user@google.com" "uname@hostname" "b_a_d" "text/plain" 11
+email "bad_user_uname@google.com" "baduname@hostname" "good" "text/plain" 12
+email "bad_user_hname@google.com" "uname@badhostname" "good" "text/plain" 13
+email "bad_user2@google.com" "uname@hostname" "good" "text/plain" 14
diff --git a/test/run_test.sh b/test/run_test.sh
new file mode 100755
index 0000000..de78860
--- /dev/null
+++ b/test/run_test.sh
@@ -0,0 +1,55 @@
+#!/bin/bash
+
+# Check the environment
+#
+if [ ! -x ../src/kbs ] ; then
+ echo kbs not built!
+ exit
+fi
+
+rm -f log
+
+../src/kbs test-config
+
+OK=1
+
+function fail()
+{
+ echo "BAD: " $*
+ OK=0
+}
+
+function good()
+{
+ echo GOOD: $*
+}
+
+if [ "`wc -l log | awk '{print $1}'`" != 8 ] ; then
+ fail Incorrect number of lines in log file - expected 8
+else
+ good Correct number of lines in log file - expected 8
+fi
+
+for i in trusted@ freebsd.org good_user ; do
+ if [ "`egrep $i log`" != "" ] ; then
+ fail Item $i incorrectly deleted
+ else
+ good Item $i correctly not deleted
+ fi
+done
+
+for i in bad_user@ microsoft.com bad_user2@ bad_user_uname@ bad_user_hname@ ; do
+ if [ "`egrep $i log`" == "" ] ; then
+ fail Item $i incorrectly not deleted
+ else
+ good Item $i correctly deleted
+ fi
+done
+
+if [ $OK == 1 ] ; then
+ echo '**** TEST OK'
+else
+ echo '**** TEST FAILED'
+fi
+
+rm -f log
diff --git a/test/test-config b/test/test-config
new file mode 100644
index 0000000..84fc6cc
--- /dev/null
+++ b/test/test-config
@@ -0,0 +1,40 @@
+set hostname localhost
+
+# These need setting correctly for the user defined in create_mails.sh
+#
+set username kbstest
+set password kbstest
+
+set casesense off
+set verbose off
+set showmatch on
+set dejunk on
+set testmode off
+set blockhtml on
+set log log
+
+trusted_users
+{
+ trusted@google.com
+}
+
+trusted_domains
+{
+ freebsd.org
+}
+
+blacklist
+{
+ microsoft.com
+}
+
+domain "."
+{
+ default allow
+
+ block_user bad_user2
+
+ allow_to "^UNAME\@HOSTNAME$"
+
+ block_subject "^bad$"
+}