git » chasquid » commit a85ba12

test: Remove nc.py

author Alberto Bertogli
2017-07-13 21:03:17 UTC
committer Alberto Bertogli
2017-07-13 21:05:45 UTC
parent 82a1e4597f1244ac39c10052408e2dd2b802a6dc

test: Remove nc.py

The nc.py script is only used in a single test, and for waiting for a
TCP port to be opened for listening.

This patch replaces it entirely, by using chamuyero for the test, and
bash for waiting on a TCP port.

test/t-05-null_address/run.sh +1 -1
test/t-05-null_address/sendmail +0 -13
test/t-05-null_address/sendmail.cmy +23 -0
test/util/lib.sh +1 -5
test/util/nc.py +0 -50

diff --git a/test/t-05-null_address/run.sh b/test/t-05-null_address/run.sh
index bcfeb2e..26bae14 100755
--- a/test/t-05-null_address/run.sh
+++ b/test/t-05-null_address/run.sh
@@ -14,7 +14,7 @@ wait_until_ready 1025
 
 
 # Send mail with an empty address (directly, unauthenticated).
-nc.py localhost 1025 < sendmail > /dev/null
+chamuyero sendmail.cmy > .logs/chamuyero 2>&1
 wait_for_file .mail/user@testserver
 mail_diff content .mail/user@testserver
 rm -f .mail/user@testserver
diff --git a/test/t-05-null_address/sendmail b/test/t-05-null_address/sendmail
deleted file mode 100644
index c743d92..0000000
--- a/test/t-05-null_address/sendmail
+++ /dev/null
@@ -1,13 +0,0 @@
-EHLO localhost
-MAIL FROM: <>
-RCPT TO: user@testserver
-DATA
-From: Mailer daemon <somewhere@horns.com>
-Subject: I've come to haunt you
-
-Muahahahaha
-
-
-.
-QUIT
-
diff --git a/test/t-05-null_address/sendmail.cmy b/test/t-05-null_address/sendmail.cmy
new file mode 100644
index 0000000..b413e8d
--- /dev/null
+++ b/test/t-05-null_address/sendmail.cmy
@@ -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
+
diff --git a/test/util/lib.sh b/test/util/lib.sh
index c5f5ed1..145f02d 100644
--- a/test/util/lib.sh
+++ b/test/util/lib.sh
@@ -61,10 +61,6 @@ function smtpc.py() {
 	${UTILDIR}/smtpc.py "$@"
 }
 
-function nc.py() {
-	${UTILDIR}/nc.py "$@"
-}
-
 function mail_diff() {
 	${UTILDIR}/mail_diff "$@"
 }
@@ -91,7 +87,7 @@ function fail() {
 function wait_until_ready() {
 	PORT=$1
 
-	while ! nc.py -z localhost $PORT; do
+	while ! bash -c "true < /dev/tcp/localhost/$PORT" 2>/dev/null ; do
 		sleep 0.1
 	done
 }
diff --git a/test/util/nc.py b/test/util/nc.py
deleted file mode 100755
index dbc7864..0000000
--- a/test/util/nc.py
+++ /dev/null
@@ -1,50 +0,0 @@
-#!/usr/bin/env python3
-#
-# Simple "netcat" implementation.
-# Unfortunately netcat/nc is not that portable, so this contains a simple
-# implementation which fits our needs.
-
-import argparse
-import threading
-import smtplib
-import socket
-import sys
-
-ap = argparse.ArgumentParser()
-ap.add_argument("-z", action='store_true', help="scan for listening daemons")
-ap.add_argument("host", help="host to connect to")
-ap.add_argument("port", type=int, help="port to connect to")
-args = ap.parse_args()
-
-address = (args.host, args.port)
-
-try:
-	sock = socket.create_connection(address)
-	fd = sock.makefile('rw', buffering=1, encoding="utf-8")
-except OSError:
-	# Exit quietly, like nc does.
-	sys.exit(1)
-
-if args.z:
-	sys.exit(0)
-
-
-# stdin -> socket in the background. Do a partial shutdown when done.
-def stdin_to_sock():
-	for line in sys.stdin:
-		fd.write(line)
-		fd.flush()
-
-	try:
-		sock.shutdown(socket.SHUT_WR)
-	except OSError:
-		pass
-
-t1 = threading.Thread(target=stdin_to_sock, daemon=True)
-t1.start()
-
-# socket -> stdout in the foreground; if the socket closes, exit.
-for line in fd:
-	sys.stdout.write(line)
-	sys.stdout.flush()
-