diff options
author | Eric Wong <e@80x24.org> | 2019-07-03 01:05:10 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2019-07-03 01:12:18 +0000 |
commit | 0ab5c363a69702e586b7ef06be3ebff3e78656b7 (patch) | |
tree | 58b88dd6aeeb802272b457c0f13893eac08b94a6 /t/nntp_compress.t | |
parent | ddd8d0adec2bbac86bbca40900acae2c56740e82 (diff) | |
download | perl-libnet-0ab5c363a69702e586b7ef06be3ebff3e78656b7.tar.gz |
Net::NNTP: support COMPRESS DEFLATE (RFC8054) nntp-compress
NNTP compression reduces bandwidth use significantly and is supported in current versions of INN. It is specified in https://tools.ietf.org/html/rfc8054 Tested on news.gmane.org (running INN) with and without STARTTLS.
Diffstat (limited to 't/nntp_compress.t')
-rw-r--r-- | t/nntp_compress.t | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/t/nntp_compress.t b/t/nntp_compress.t new file mode 100644 index 0000000..7a0cc63 --- /dev/null +++ b/t/nntp_compress.t @@ -0,0 +1,55 @@ +#!perl +# integration test for NNTP COMPRESS usage +use 5.008001; +use strict; +use warnings; +use Test::More; +use Net::Config; +use Net::NNTP; +if (!eval { require Net::NNTP::Deflate }) { + plan skip_all => 'no DEFLATE support'; +} + +# tested on news.gmane.org, we can move it to nntp.lore.kernel.org if +# gmane goes away since nntp.lore.kernel.org will likely start support +# STARTTLS + COMPRESS soon +my $host = $ENV{NNTP_COMPRESS_SERVER}; +unless($host && $NetConfig{test_hosts}) { + plan skip_all => 'NNTP_COMPRESS_SERVER not set'; +} + +plan tests => 16; + +# git 2.22.0 release announcement +my $mid = '<xmqq36klozfu.fsf@gitster-ct.c.googlers.com>'; +my $orig; +{ + my $nntp = Net::NNTP->new($host); + ok($nntp, "opened connection to $host"); + is($nntp->compression, undef, '->compression not active by default'); + $orig = $nntp->article($mid); + ok($nntp->compress, '->compress successful'); + is($nntp->compression, 'DEFLATE', '->compression active'); + is_deeply($nntp->article($mid), $orig, 'got the same article after compress'); + + # check for misuse + is(eval { $nntp->starttls }, undef, '->starttls fails'); + like($@, qr/DEFLATE/, '$@ mentions compression on ->starttls'); + is(eval { $nntp->compress }, undef, '->compress fails again'); + like($@, qr/DEFLATE/, '$@ mentions compression on ->compress'); + ok($nntp->quit, 'QUIT OK'); +} + +SKIP: { + skip('no SSL support found in Net::NNTP', 6) if ! Net::NNTP->can_ssl; + my $nntp = Net::NNTP->new($host); + ok($nntp, "connected to $host again"); + $orig ||= $nntp->article($mid); + ok($nntp->starttls, '->starttls works before ->compress'); + ok($nntp->compress, '->compress works after ->starttls'); + my $date = $nntp->date; + like($date, qr/[0-9]+/, 'DATE works'); + is_deeply($nntp->article($mid), $orig, + 'got the same article with both compress and starttls'); + ok($nntp->quit, 'QUIT OK'); +} |