annotate lib/Test/Nginx/POP3.pm @ 539:3fcad5e66735

Tests: whitespace fixes in mail modules.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 01 Apr 2015 17:59:53 +0300
parents e6817a00ba00
children 481d705b8610
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
59
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
1 package Test::Nginx::POP3;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
2
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
3 # (C) Maxim Dounin
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
4
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
5 # Module for nginx pop3 tests.
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
6
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
7 ###############################################################################
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
8
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
9 use warnings;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
10 use strict;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
11
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
12 use Test::More qw//;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
13 use IO::Socket;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
14 use Socket qw/ CRLF /;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
15
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
16 use Test::Nginx;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
17
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
18 use base qw/ IO::Socket::INET /;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
19
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
20 sub new {
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
21 my $class = shift;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
22
526
e6817a00ba00 Tests: remove stray "return" from mail modules.
Maxim Dounin <mdounin@mdounin.ru>
parents: 339
diff changeset
23 my $self = $class->SUPER::new(
59
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
24 Proto => "tcp",
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
25 PeerAddr => "127.0.0.1:8110",
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
26 @_
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
27 )
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
28 or die "Can't connect to nginx: $!\n";
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
29
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
30 $self->autoflush(1);
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
31
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
32 return $self;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
33 }
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
34
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
35 sub send {
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
36 my ($self, $cmd) = @_;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
37 log_out($cmd);
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
38 $self->print($cmd . CRLF);
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
39 }
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
40
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
41 sub read {
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
42 my ($self) = @_;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
43 eval {
209
5137f27935b4 Tests: log timeouts in IMAP/POP3/SMTP.
Maxim Dounin <mdounin@mdounin.ru>
parents: 162
diff changeset
44 local $SIG{ALRM} = sub { die "timeout\n" };
339
9d0a2fa47ac6 Tests: change http timeout to 5s, imap/pop3/smtp to 3s.
Maxim Dounin <mdounin@mdounin.ru>
parents: 243
diff changeset
45 alarm(3);
59
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
46 while (<$self>) {
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
47 log_in($_);
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
48 # XXX
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
49 next if m/^\d\d\d-/;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
50 last;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
51 }
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
52 alarm(0);
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
53 };
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
54 alarm(0);
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
55 if ($@) {
209
5137f27935b4 Tests: log timeouts in IMAP/POP3/SMTP.
Maxim Dounin <mdounin@mdounin.ru>
parents: 162
diff changeset
56 log_in("died: $@");
59
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
57 return undef;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
58 }
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
59 return $_;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
60 }
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
61
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
62 sub check {
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
63 my ($self, $regex, $name) = @_;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
64 Test::More->builder->like($self->read(), $regex, $name);
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
65 }
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
66
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
67 sub ok {
243
de7338227832 Tests: removed trailing spaces.
Homutov Vladimir <vl@nginx.com>
parents: 209
diff changeset
68 my $self = shift;
59
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
69 Test::More->builder->like($self->read(), qr/^\+OK/, @_);
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
70 }
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
71
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
72 ###############################################################################
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
73
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
74 sub pop3_test_daemon {
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
75 my $server = IO::Socket::INET->new(
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
76 Proto => 'tcp',
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
77 LocalAddr => '127.0.0.1:8111',
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
78 Listen => 5,
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
79 Reuse => 1
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
80 )
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
81 or die "Can't create listening socket: $!\n";
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
82
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
83 while (my $client = $server->accept()) {
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
84 $client->autoflush(1);
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
85 print $client "+OK fake pop3 server ready" . CRLF;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
86
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
87 while (<$client>) {
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
88 if (/^quit/i) {
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
89 print $client '+OK quit ok' . CRLF;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
90 } elsif (/^user test\@example.com/i) {
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
91 print $client '+OK user ok' . CRLF;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
92 } elsif (/^pass secret/i) {
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
93 print $client '+OK pass ok' . CRLF;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
94 } else {
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
95 print $client "-ERR unknown command" . CRLF;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
96 }
539
3fcad5e66735 Tests: whitespace fixes in mail modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 526
diff changeset
97 }
59
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
98
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
99 close $client;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
100 }
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
101 }
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
102
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
103 ###############################################################################
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
104
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
105 1;
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
106
bc3351f157ef Tests: add basic pop3 and imap tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
107 ###############################################################################