Permalink
Browse files

Fix POP3 test failures

Fake pop server can now specify a port to run on
  • Loading branch information...
1 parent 73093a3 commit cd4ed6130a56746e31972c35951bd382e375b69a @Synchro committed Aug 5, 2013
Showing with 42 additions and 13 deletions.
  1. +18 −4 class.pop3.php
  2. +4 −4 test/fakepopserver.sh
  3. +18 −4 test/phpmailerTest.php
  4. +2 −1 test/runfakepopserver.sh
View
@@ -147,12 +147,19 @@ public function __construct()
* @param bool $tval
* @param string $username
* @param string $password
+ * @param int $debug_level
* @return bool
*/
- public static function popBeforeSmtp($host, $port = false, $tval = false, $username = '', $password = '')
- {
+ public static function popBeforeSmtp(
+ $host,
+ $port = false,
+ $tval = false,
+ $username = '',
+ $password = '',
+ $debug_level = 0
+ ) {
$pop = new POP3;
- return $pop->authorise($host, $port, $tval, $username, $password);
+ return $pop->authorise($host, $port, $tval, $username, $password, $debug_level);
}
/**
@@ -330,7 +337,11 @@ public function disconnect()
*/
private function getResponse($size = 128)
{
- return fgets($this->pop_conn, $size);
+ $r = fgets($this->pop_conn, $size);
+ if ($this->do_debug >= 1) {
+ echo "Server -> Client: $r";
+ }
+ return $r;
}
/**
@@ -342,6 +353,9 @@ private function getResponse($size = 128)
private function sendString($string)
{
if ($this->pop_conn) {
+ if ($this->do_debug >= 2) { //Show client messages when debug >= 2
+ echo "Client -> Server: $string";
+ }
return fwrite($this->pop_conn, $string, strlen($string));
}
return 0;
View
@@ -20,7 +20,7 @@ LOGFILE=${LOGFOLDER}/fakepop.log
LOGGING=1
DEBUG=1
-TIMEOUT=10
+TIMEOUT=60
POP_USER=
POP_PASSWRD=test
@@ -78,10 +78,10 @@ while [ ${BREAK} -eq 0 ] ; do
;;
PASS)
if [ "${POP_PASSWRD}" == "${ARGS}" ] ; then
- ANSWER="+OK Logged in.\r\n"
+ ANSWER="+OK Logged in."
AUTH=1
else
- ANSWER="-ERR Login failed\r\n"
+ ANSWER="-ERR Login failed."
fi
;;
LIST)
@@ -117,7 +117,7 @@ while [ ${BREAK} -eq 0 ] ; do
;;
esac
else
- echo "+OK Connection timed out\r\n"
+ echo "+OK Connection timed out"
break
fi
done
View
@@ -1280,30 +1280,44 @@ public function testLineBreaks()
/**
* Use a fake POP3 server to test POP-before-SMTP auth
+ * With a known-good login
*/
- public function testPopBeforeSmtp()
+ public function testPopBeforeSmtpGood()
{
//Start a fake POP server
$pid = shell_exec('nohup ./runfakepopserver.sh >/dev/null 2>/dev/null & printf "%u" $!');
$this->pids[] = $pid;
+ sleep(2);
//Test a known-good login
$this->assertTrue(
- POP3::popBeforeSmtp('localhost', 1100, 10, 'user', 'test'),
+ POP3::popBeforeSmtp('localhost', 1100, 10, 'user', 'test', 0),
'POP before SMTP failed'
);
//Kill the fake server
shell_exec('kill -TERM '.escapeshellarg($pid));
+ sleep(2);
+ }
- $pid = shell_exec('nohup ./runfakepopserver.sh >/dev/null 2>/dev/null & printf "%u" $!');
+ /**
+ * Use a fake POP3 server to test POP-before-SMTP auth
+ * With a known-bad login
+ */
+ public function testPopBeforeSmtpBad()
+ {
+ //Start a fake POP server on a different port
+ //so we don't inadvertently connect to the previous instance
+ $pid = shell_exec('nohup ./runfakepopserver.sh 1101 >/dev/null 2>/dev/null & printf "%u" $!');
$this->pids[] = $pid;
+ sleep(2);
//Test a known-bad login
$this->assertFalse(
- POP3::popBeforeSmtp('localhost', 1100, 10, 'user', 'xxx'),
+ POP3::popBeforeSmtp('localhost', 1101, 10, 'user', 'xxx', 0),
'POP before SMTP should have failed'
);
shell_exec('kill -TERM '.escapeshellarg($pid));
+ sleep(2);
}
/**
View
@@ -3,7 +3,8 @@
# Run the fake pop server from bash
# Idea from http://blog.ale-re.net/2007/09/ipersimple-remote-shell-with-netcat.html
# Defaults to port 1100 so it can be run by unpriv users and not clash with a real server
+# Optionally, pass in in a port number as the first arg
mkfifo fifo
-nc -l 1100 <fifo |bash ./fakepopserver.sh >fifo
+nc -l ${1:-1100} <fifo |bash ./fakepopserver.sh >fifo
rm fifo

0 comments on commit cd4ed61

Please sign in to comment.