Mercurial > hg > nginx-tests
comparison lib/Test/Nginx/SMTP.pm @ 26:0880e0fafde4
Tests: implement smtp test backend and use it.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 02 Oct 2008 16:18:11 +0400 |
parents | d4b74207a627 |
children | daa295331acd |
comparison
equal
deleted
inserted
replaced
25:fbda19df2fc4 | 26:0880e0fafde4 |
---|---|
21 my $class = shift; | 21 my $class = shift; |
22 | 22 |
23 my $self = return $class->SUPER::new( | 23 my $self = return $class->SUPER::new( |
24 Proto => "tcp", | 24 Proto => "tcp", |
25 PeerAddr => "localhost", | 25 PeerAddr => "localhost", |
26 PeerPort => 10025, | 26 PeerPort => 8025, |
27 @_ | 27 @_ |
28 ) | 28 ) |
29 or die "Can't connect to nginx: $!\n"; | 29 or die "Can't connect to nginx: $!\n"; |
30 | 30 |
31 $self->autoflush(1); | 31 $self->autoflush(1); |
68 $self->check(qr/^2\d\d /, @_); | 68 $self->check(qr/^2\d\d /, @_); |
69 } | 69 } |
70 | 70 |
71 ############################################################################### | 71 ############################################################################### |
72 | 72 |
73 sub smtp_test_daemon { | |
74 my $server = IO::Socket::INET->new( | |
75 Proto => 'tcp', | |
76 LocalPort => 8026, | |
77 Listen => 5, | |
78 Reuse => 1 | |
79 ) | |
80 or die "Can't create listening socket: $!\n"; | |
81 | |
82 while (my $client = $server->accept()) { | |
83 $client->autoflush(1); | |
84 print $client "220 fake esmtp server ready" . CRLF; | |
85 | |
86 while (<$client>) { | |
87 if (/^quit/i) { | |
88 print $client '221 quit ok' . CRLF; | |
89 } elsif (/^(ehlo|helo)/i) { | |
90 print $client '250 hello ok' . CRLF; | |
91 } elsif (/^rset/i) { | |
92 print $client '250 rset ok' . CRLF; | |
93 } elsif (/^mail from:[^@]+$/i) { | |
94 print $client '500 mail from error' . CRLF; | |
95 } elsif (/^mail from:/i) { | |
96 print $client '250 mail from ok' . CRLF; | |
97 } elsif (/^rcpt to:[^@]+$/i) { | |
98 print $client '500 rcpt to error' . CRLF; | |
99 } elsif (/^rcpt to:/i) { | |
100 print $client '250 rcpt to ok' . CRLF; | |
101 } else { | |
102 print $client "500 unknown command" . CRLF; | |
103 } | |
104 } | |
105 | |
106 close $client; | |
107 } | |
108 } | |
109 | |
110 ############################################################################### | |
111 | |
73 1; | 112 1; |
74 | 113 |
75 ############################################################################### | 114 ############################################################################### |