mirror of
https://blitiri.com.ar/repos/chasquid
synced 2026-07-30 02:49:49 +00:00
test: Add a new integration test with minor dialogs
This patch adds a new integration test, which executes various small dialogs, to cover corner cases that are not well covered (according to our coverage report). For example, "EHLO" without domain, or invalid DATA. While we could do them via Go tests, this way is more realistic, and the tests are easier to write.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
|
||||
c tls_connect localhost:1465
|
||||
|
||||
c <~ 220
|
||||
c -> EHLO localhost
|
||||
c <... 250 HELP
|
||||
|
||||
c -> AUTH SOMETHINGELSE
|
||||
c <~ 534
|
||||
|
||||
c -> AUTH PLAIN
|
||||
c <~ 334
|
||||
c -> dXNlckB0ZXN0c2VydmVyAHlalala==
|
||||
c <~ 535 error decoding AUTH response
|
||||
|
||||
c -> AUTH PLAIN
|
||||
c <~ 334
|
||||
c -> dXNlckB0ZXN0c2VydmVyAHVzZXJAdGVzdHNlcnZlcgB3cm9uZ3Bhc3N3b3Jk
|
||||
c <~ 535 Incorrect user or password
|
||||
|
||||
c -> AUTH PLAIN
|
||||
c <~ 334
|
||||
c -> dXNlckB0ZXN0c2VydmVyAHVzZXJAdGVzdHNlcnZlcgBzZWNyZXRwYXNzd29yZA==
|
||||
c <~ 235
|
||||
|
||||
c -> AUTH PLAIN
|
||||
c <~ 503 You are already wearing that!
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
c tcp_connect localhost:1025
|
||||
|
||||
c <~ 220
|
||||
c -> EHLO localhost
|
||||
c <... 250 HELP
|
||||
c -> AUTH PLAIN
|
||||
c <- 503 You feel vulnerable
|
||||
@@ -0,0 +1,18 @@
|
||||
|
||||
c tls_connect localhost:1465
|
||||
|
||||
c <~ 220
|
||||
c -> EHLO localhost
|
||||
c <... 250 HELP
|
||||
|
||||
c -> AUTH PLAIN something
|
||||
c <~ 535
|
||||
c -> AUTH PLAIN something
|
||||
c <~ 535
|
||||
c -> AUTH PLAIN something
|
||||
c <~ 535
|
||||
c -> AUTH PLAIN something
|
||||
c <~ 535
|
||||
c -> AUTH PLAIN something
|
||||
c <~ 503 Too many attempts - go away
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
|
||||
c tcp_connect localhost:1025
|
||||
|
||||
c <~ 220
|
||||
|
||||
c -> DATA
|
||||
c <- 503 Invisible customers are not welcome!
|
||||
|
||||
c -> HELO localhost
|
||||
c <~ 250
|
||||
c -> DATA
|
||||
c <- 503 sender not yet given
|
||||
|
||||
c -> MAIL FROM:<a@b>
|
||||
c <~ 250
|
||||
c -> RCPT TO: user@testserver
|
||||
c <~ 250
|
||||
c -> DATA
|
||||
c <~ 354
|
||||
c -> From: Mailer daemon <somewhere@horns.com>
|
||||
c -> Subject: I've come to haunt you
|
||||
c -> Bad header
|
||||
c ->
|
||||
c -> Muahahahaha
|
||||
c ->
|
||||
c ->
|
||||
c -> .
|
||||
c <~ 554 error parsing message
|
||||
|
||||
c -> QUIT
|
||||
c <~ 221
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
c tcp_connect localhost:1025
|
||||
|
||||
c <~ 220
|
||||
c -> HELO localhost
|
||||
c <~ 250
|
||||
c -> MAIL LALA: <>
|
||||
c <- 500 unknown command
|
||||
|
||||
c -> MAIL FROM:
|
||||
c <~ 500
|
||||
|
||||
c -> MAIL FROM:<pepe>
|
||||
c <~ 501
|
||||
|
||||
c -> MAIL FROM:<a@xn--->
|
||||
c <- 501 malformed address (IDNA conversion failed)
|
||||
|
||||
c -> MAIL FROM:<aaaa5aaaaXaaaa5aaaaXaaaa5aaaaXaaaa5aaaaXaaaa5aaaaXaaaa5aaaaXaaaa5aaaaXaaaa5aaaaXaaaa5aaaaXaaaa5aaaaXaaaa5aaaaXaaaa5aaaaXaaaa5aaaaXaaaa5aaaaXaaaa5aaaaX@bbbb5bbbbXbbbb5bbbbXbbbb5bbbbXbbbb5bbbbXbbbb5bbbbXbbbb5bbbbXbbbb5bbbbXbbbb5bbbbXbbbb5bbbbXbbbb5bbbbXbbbb5bbbbXbbbb5bbbbXbbbb5bbbbXbbbb5bbbbXbbbb5bbbbX>
|
||||
c <- 501 address too long
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
c tcp_connect localhost:1025
|
||||
|
||||
c <~ 220
|
||||
c -> HELO localhost
|
||||
c <~ 250
|
||||
c -> MAIL FROM:<test@testy.com>
|
||||
c <~ 250
|
||||
|
||||
c -> RCPT LALA: <>
|
||||
c <- 500 unknown command
|
||||
|
||||
c -> RCPT TO:
|
||||
c <~ 500
|
||||
|
||||
c -> RCPT TO:<pepe>
|
||||
c <~ 501
|
||||
|
||||
c -> RCPT TO:<a@xn--->
|
||||
c <- 501 malformed address (IDNA conversion failed)
|
||||
|
||||
c -> RCPT TO:<henryⅣ@testserver>
|
||||
c <- 550 recipient invalid, please check the address for typos
|
||||
|
||||
c -> RCPT TO:<aaaa5aaaaXaaaa5aaaaXaaaa5aaaaXaaaa5aaaaXaaaa5aaaaXaaaa5aaaaXaaaa5aaaaXaaaa5aaaaXaaaa5aaaaXaaaa5aaaaXaaaa5aaaaXaaaa5aaaaXaaaa5aaaaXaaaa5aaaaXaaaa5aaaaX@bbbb5bbbbXbbbb5bbbbXbbbb5bbbbXbbbb5bbbbXbbbb5bbbbXbbbb5bbbbXbbbb5bbbbXbbbb5bbbbXbbbb5bbbbXbbbb5bbbbXbbbb5bbbbXbbbb5bbbbXbbbb5bbbbXbbbb5bbbbXbbbb5bbbbX>
|
||||
c <- 501 address too long
|
||||
@@ -0,0 +1,15 @@
|
||||
hostname: "testserver"
|
||||
|
||||
smtp_address: ":1025"
|
||||
submission_address: ":1587"
|
||||
submission_over_tls_address: ":1465"
|
||||
monitoring_address: ":1099"
|
||||
|
||||
mail_delivery_agent_bin: "test-mda"
|
||||
mail_delivery_agent_args: "%to%"
|
||||
|
||||
data_dir: "../.data"
|
||||
mail_log_path: "../.logs/mail_log"
|
||||
|
||||
suffix_separators: "+-"
|
||||
drop_characters: "._"
|
||||
@@ -0,0 +1,3 @@
|
||||
|
||||
fail: | false
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
c tcp_connect localhost:1025
|
||||
|
||||
c <~ 220
|
||||
c -> HELO
|
||||
c <~ 501
|
||||
c -> EHLO
|
||||
c <~ 501
|
||||
c -> HELO localhost
|
||||
c <~ 250
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
c tcp_connect localhost:1025
|
||||
|
||||
c <~ 220
|
||||
c -> HELO localhost
|
||||
c <~ 250
|
||||
c -> QUIT
|
||||
c <~ 221
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
testserver localhost
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
. $(dirname ${0})/../util/lib.sh
|
||||
|
||||
init
|
||||
|
||||
generate_certs_for testserver
|
||||
add_user user@testserver secretpassword
|
||||
|
||||
mkdir -p .logs
|
||||
chasquid -v=2 --logfile=.logs/chasquid.log --config_dir=config &
|
||||
wait_until_ready 1025
|
||||
|
||||
FAILED=0
|
||||
for i in *.cmy; do
|
||||
if ! chamuyero $i > .logs/$i.log 2>&1 ; then
|
||||
echo "test $i failed, see .logs/$i.log"
|
||||
FAILED=1
|
||||
fi
|
||||
done
|
||||
|
||||
if [ $FAILED == 1 ]; then
|
||||
fail
|
||||
fi
|
||||
success
|
||||
@@ -0,0 +1,23 @@
|
||||
|
||||
c tcp_connect localhost:1025
|
||||
|
||||
c <~ 220
|
||||
c -> EHLO localhost
|
||||
c <... 250 HELP
|
||||
c -> MAIL FROM: <>
|
||||
c <~ 250
|
||||
c -> RCPT TO: user@testserver
|
||||
c <~ 250
|
||||
c -> DATA
|
||||
c <~ 354
|
||||
c -> From: Mailer daemon <somewhere@horns.com>
|
||||
c -> Subject: I've come to haunt you
|
||||
c ->
|
||||
c -> Muahahahaha
|
||||
c ->
|
||||
c ->
|
||||
c -> .
|
||||
c <~ 250
|
||||
c -> QUIT
|
||||
c <~ 221
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
c tcp_connect localhost:1025
|
||||
|
||||
c <~ 220
|
||||
c -> EHLO localhost
|
||||
c <... 250 HELP
|
||||
c -> WHATISTHIS
|
||||
c <- 500 unknown command
|
||||
|
||||
@@ -12,6 +12,7 @@ interactive command-line tools.
|
||||
import argparse
|
||||
import os
|
||||
import re
|
||||
import ssl
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
@@ -97,6 +98,19 @@ class TCPSock (Sock):
|
||||
self.has_conn.set()
|
||||
|
||||
|
||||
class TLSSock (Sock):
|
||||
def __init__(self, addr):
|
||||
host, port = addr.rsplit(":", 1)
|
||||
Sock.__init__(self, (host, int(port)))
|
||||
plain_sock = socket.create_connection(self.addr)
|
||||
self.sock = ssl.wrap_socket(plain_sock)
|
||||
|
||||
def connect(self):
|
||||
self.connr = self.sock.makefile(mode="r")
|
||||
self.connw = self.sock.makefile(mode="w")
|
||||
self.has_conn.set()
|
||||
|
||||
|
||||
class Interpreter (object):
|
||||
"""Interpreter for chamuyero scripts."""
|
||||
def __init__(self):
|
||||
@@ -175,6 +189,11 @@ class Interpreter (object):
|
||||
sock.connect()
|
||||
self.procs[proc] = sock
|
||||
|
||||
elif op == "tls_connect":
|
||||
sock = TLSSock(params)
|
||||
sock.connect()
|
||||
self.procs[proc] = sock
|
||||
|
||||
# -> Send to a process stdin, with a \n at the end.
|
||||
# .> Send to a process stdin, no \n at the end.
|
||||
elif op == "->":
|
||||
|
||||
Reference in New Issue
Block a user