]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Improve rlm_imap tests
authorNick Porter <nick@portercomputing.co.uk>
Tue, 7 Mar 2023 14:59:39 +0000 (14:59 +0000)
committerNick Porter <nick@portercomputing.co.uk>
Wed, 8 Mar 2023 17:39:29 +0000 (17:39 +0000)
.github/actions/ci-tests/action.yml
.github/workflows/ci.yml
scripts/ci/imap-setup.sh
src/tests/modules/imap/auth_plaintext.unlang
src/tests/modules/imap/imap_bad_tls/module.conf
src/tests/modules/imap/imap_opt_tls/module.conf
src/tests/modules/imap/imap_tls/auth_tls.unlang
src/tests/modules/imap/imap_tls/module.conf

index adc0d18db9b97af0b9721ede235efd5473ac0514..13f2ce32684dba7a9c25791e0e6205e95457c90e 100644 (file)
@@ -48,7 +48,7 @@ inputs:
     default: 1430
   imap_test_server_ssl_port:
     description: IMAP server IMAPS port
-    default: 1431
+    default: 1432
 
   use_docker:
     desription: True if running in a Docker container
index 54a224704c8bd70970ee4d5546907691f54df1e0..761074e6229ba002b4869d31b592fd5a208a8d0d 100644 (file)
@@ -176,7 +176,7 @@ jobs:
           rest_test_ssl_port: 8443
           imap_test_server: 127.0.0.1
           imap_test_server_port: 1430
-          imap_test_server_ssl_port: 1431
+          imap_test_server_ssl_port: 1432
 
       - name: Run fuzzer
         uses: ./.github/actions/fuzzer
index f78a5864969843886e565feef01ae8efeb252b87..b3f39dcc38bc8efe75c7b936298ffccaf1b752f4 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/sh -e
+#!/bin/bash
 
 #
 # ### This is a script to setup a dovecot imap server for testing rlm_imap
@@ -32,9 +32,6 @@ LOGINFOPATH="${LOGDIR}/dovecot-info.log"
 # Used for creating `imap-stop.sh`
 CIDIR="${BASEDIR}/scripts/ci"
 
-# When running on Docker, USER is not set
-USER=${USER:-root}
-
 #
 # Create all the necessary files
 #
@@ -72,24 +69,12 @@ openssl rsa -in "${BASEDIR}/raddb/certs/rsa/server.key" -passin 'pass:whatever'
 #
 # Add users to the password file
 #
-
-# Generate passwords for the users
-USER1P=$(doveadm -o stats_writer_socket_path= pw -p test1 -s CRYPT)
-USER2P=$(doveadm -o stats_writer_socket_path= pw -p test2 -s CRYPT)
-USER3P=$(doveadm -o stats_writer_socket_path= pw -p test3 -s CRYPT)
-
-# Add user password combinations
-echo "\
-user1:${USER1P}:::::: 
-" >"${PASSPATH}"
-
-echo "\
-user2:${USER2P}:::::: 
-" >>"${PASSPATH}"
-
-echo "\
-user3:${USER3P}:::::: 
-" >>"${PASSPATH}"
+rm -f ${PASSPATH}
+for i in {1..3}; do
+       PASS=$(doveadm -o stats_writer_socket_path= pw -p test${i} -s CRYPT)
+       echo "user${i}:${PASS}:::::: 
+" >> "${PASSPATH}"
+done
 
 #
 # Configure instance specific dovecot information
index d881c68ca5020c0032969e10307fffecb16ba3ab..30317273f197f6472258158b9eea18f7bfc6cf5a 100644 (file)
@@ -6,12 +6,113 @@ imap.authenticate {
 #  Module failure is likely a timeout
 #  Avoid false negatives by aborting test
 #
-if (fail) {
-    test_pass
-    handled
+if !(ok) {
+    if (&Module-Failure-Message[*] == "imap: curl request failed: Timeout was reached (28)") {
+        test_pass
+        handled
+    }
+    test_fail
+}
+
+#
+#  Check for module failing with missing attributes
+#
+&request -= &User-Password[*]
+
+imap.authenticate {
+    fail = 1
+    invalid = 2
+}
+
+if !(invalid) {
+    test_fail
+}
+
+&User-Password := 'test2'
+&request -= &User-Name[*]
+
+imap.authenticate {
+    fail = 1
+    invalid = 2
+}
+
+if !(invalid) {
+    test_fail
+}
+
+#
+#  Now do multiple authentications of different users
+#
+
+&User-Name := 'user2'
+imap.authenticate {
+    fail = 1
+}
+
+if !(ok) {
+    if (&Module-Failure-Message[*] == "imap: curl request failed: Timeout was reached (28)") {
+        test_pass
+        handled
+    }
+    test_fail
+}
+
+&User-Name := 'user3'
+&User-Password := 'test3'
+imap.authenticate {
+    fail = 1
+}
+
+if !(ok) {
+    if (&Module-Failure-Message[*] == "imap: curl request failed: Timeout was reached (28)") {
+        test_pass
+        handled
+    }
+    test_fail
+}
+
+#
+#  And repeat all three
+#
+&User-Name := 'user1'
+&User-Password := 'test1'
+imap.authenticate {
+    fail = 1
+}
+
+if !(ok) {
+    if (&Module-Failure-Message[*] == "imap: curl request failed: Timeout was reached (28)") {
+        test_pass
+        handled
+    }
+    test_fail
+}
+
+&User-Name := 'user2'
+&User-Password := 'test2'
+imap.authenticate {
+    fail = 1
+}
+
+if !(ok) {
+    if (&Module-Failure-Message[*] == "imap: curl request failed: Timeout was reached (28)") {
+        test_pass
+        handled
+    }
+    test_fail
+}
+
+&User-Name := 'user3'
+&User-Password := 'test3'
+imap.authenticate {
+    fail = 1
 }
 
 if !(ok) {
+    if (&Module-Failure-Message[*] == "imap: curl request failed: Timeout was reached (28)") {
+        test_pass
+        handled
+    }
     test_fail
 }
 
index 229e5941cb57e0fdc937d2de96736dba808a4b58..d3c99d474b0154c67d4e148fd3dcb90de6aa44ac 100644 (file)
@@ -1,7 +1,7 @@
 #IMAP unit test config
 
 imap imap_bad_tls {
-       uri             = "$ENV{IMAP_TEST_SERVER}:$ENV{IMAP_TEST_SERVER_SSL_PORT}"
+       uri             = "imaps://$ENV{IMAP_TEST_SERVER}:$ENV{IMAP_TEST_SERVER_SSL_PORT}"
        timeout         = 5
 
        tls {
index 05ff3f7e2a0bbb2d441bf960886858becf91f54a..3c756e52c4031d378fbf6233f980557084869d23 100644 (file)
@@ -1,7 +1,7 @@
 #IMAP unit test config
 
 imap imap_try_tls {
-       uri             = "$ENV{IMAP_TEST_SERVER}:$ENV{IMAP_TEST_SERVER_SSL_PORT}"
+       uri             = "imaps://$ENV{IMAP_TEST_SERVER}:$ENV{IMAP_TEST_SERVER_SSL_PORT}"
        timeout         = 10s
 
        tls {
index 1ae11f57d0d9f539d6200077065fdaa2578e88f6..e970125fbb025df7a0dd67ae564f7eeb1274098b 100644 (file)
@@ -7,12 +7,11 @@ imap_tls.authenticate {
 #  Module failure is likely a timeout
 #  Avoid false negatives by aborting test
 #
-if (fail) {
-    test_pass
-    handled
-}
-
 if !(ok) {
+    if (&Module-Failure-Message[*] == "imap: curl request failed: Timeout was reached (28)") {
+        test_pass
+        handled
+    }
     test_fail
 }
 
index 9182da1bec4764c0aa8067cc142151b3072dfaf1..f501f91652c3799e7dbc8f9320083542ebcab3b3 100644 (file)
@@ -1,7 +1,7 @@
 #IMAP unit test config
 
 imap imap_tls {
-       uri             = "$ENV{IMAP_TEST_SERVER}:$ENV{IMAP_TEST_SERVER_SSL_PORT}"
+       uri             = "imaps://$ENV{IMAP_TEST_SERVER}:$ENV{IMAP_TEST_SERVER_SSL_PORT}"
        timeout         = 5s
 
        tls {