Debian Codegraph @

cassandane/Cassandane/Cyrus/Nntp.pm

raw
1 #!/usr/bin/perl
2 #
3 # Copyright (c) 2011-2017 FastMail Pty Ltd. All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
7 # are met:
8 #
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 #
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in
14 # the documentation and/or other materials provided with the
15 # distribution.
16 #
17 # 3. The name "Fastmail Pty Ltd" must not be used to
18 # endorse or promote products derived from this software without
19 # prior written permission. For permission or any legal
20 # details, please contact
21 # FastMail Pty Ltd
22 # PO Box 234
23 # Collins St West 8007
24 # Victoria
25 # Australia
26 #
27 # 4. Redistributions of any form whatsoever must retain the following
28 # acknowledgment:
29 # "This product includes software developed by Fastmail Pty. Ltd."
30 #
31 # FASTMAIL PTY LTD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
32 # INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
33 # EVENT SHALL OPERA SOFTWARE AUSTRALIA BE LIABLE FOR ANY SPECIAL, INDIRECT
34 # OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
35 # USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
36 # TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
37 # OF THIS SOFTWARE.
38 #
39
40 package Cassandane::Cyrus::Nntp;
41 use strict;
42 use warnings;
43 use DateTime;
44 use News::NNTPClient;
45
46 use lib '.';
47 use base qw(Cassandane::Cyrus::TestCase);
48 use Cassandane::Util::Log;
49 use Cassandane::Util::Words;
50
51 sub new
52 {
53 my ($class, @args) = @_;
54
55 my $self = $class->SUPER::new({ gen => 0, services => ['nntp'] }, @args);
56
57 $self->needs('component', 'nttpd');
58 return $self;
59 }
60
61 sub set_up
62 {
63 my ($self) = @_;
64 $self->SUPER::set_up();
65
66 my $svc = $self->{instance}->get_service('nntp');
67 if (defined $svc)
68 {
69 my $debug = get_verbose() ? 2 : 0;
70 $self->{client} = new News::NNTPClient($svc->host(),
71 $svc->port(),
72 $debug);
73 $self->{client}->authinfo('cassandane', 'testpw');
74 }
75 }
76
77 sub tear_down
78 {
79 my ($self) = @_;
80
81 if (defined $self->{client})
82 {
83 $self->{client}->quit();
84 $self->{client} = undef;
85 }
86
87 $self->SUPER::tear_down();
88 }
89
90 my $stack_slosh = 256;
91
92 sub test_cve_2011_3208_list_newsgroups
93 {
94 my ($self) = @_;
95
96 my $client = $self->{client};
97 my $wildmat = '';
98 while (length $wildmat < 1024+$stack_slosh)
99 {
100 $wildmat .= ($wildmat eq '' ? '' : '.');
101 $wildmat .= random_word();
102 $client->list('newsgroups', $wildmat);
103 $self->assert_num_equals(215, $client->code());
104 $self->assert($client->message() =~ m/List of newsgroups follows/i);
105 }
106 }
107
108 sub test_cve_2011_3208_list_active
109 {
110 my ($self) = @_;
111
112 my $client = $self->{client};
113 my $wildmat = '';
114 while (length $wildmat < 1024+$stack_slosh)
115 {
116 $wildmat .= ($wildmat eq '' ? '' : '.');
117 $wildmat .= random_word();
118 $client->list('active', $wildmat);
119 $self->assert_num_equals(215, $client->code());
120 $self->assert($client->message() =~ m/List of newsgroups follows/i);
121 }
122 }
123
124 # The NEWNEWS command is disabled by default.
125 Cassandane::Cyrus::TestCase::magic(AllowNewNews => sub {
126 shift->config_set(allownewnews => 1);
127 });
128
129 sub test_cve_2011_3208_newnews
130 :AllowNewNews
131 {
132 my ($self) = @_;
133
134 my $client = $self->{client};
135 my $wildmat = '';
136 my $since = time() - 3600;
137 while (length $wildmat < 1024+$stack_slosh)
138 {
139 $wildmat .= ($wildmat eq '' ? '' : '.');
140 $wildmat .= random_word();
141 $client->newnews($wildmat, $since);
142 $self->assert_num_equals(230, $client->code());
143 $self->assert($client->message() =~ m/List of new articles follows/i);
144 }
145 }
146
147 1;