diff options
author | Eric Wong <e@80x24.org> | 2015-09-18 01:37:53 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2015-09-18 21:23:53 +0000 |
commit | 761736a312a103ba522abac52a604564f9e788ce (patch) | |
tree | 283a952c417d4be4573e1e26a9b546e0b1fdadf6 /t/nntp.t | |
parent | 62ee3cb36dd08f17e444e96dc80108464ee10cba (diff) | |
download | public-inbox-761736a312a103ba522abac52a604564f9e788ce.tar.gz |
Implementing NEWNEWS, XHDR, XOVER efficiently will require additional caching on top of msgmap. This seems to work with lynx and slrnpull, haven't tried clients. DO NOT run in production, yet, denial-of-service vulnerabilities await!
Diffstat (limited to 't/nntp.t')
-rw-r--r-- | t/nntp.t | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/t/nntp.t b/t/nntp.t new file mode 100644 index 00000000..82918ff5 --- /dev/null +++ b/t/nntp.t @@ -0,0 +1,64 @@ +# Copyright (C) 2015 all contributors <meta@public-inbox.org> +# License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt) +use strict; +use warnings; +use Test::More; +use Data::Dumper; + +use_ok 'PublicInbox::NNTP'; + +{ + sub quote_str { + my (undef, $s) = split(/ = /, Dumper($_[0]), 2); + $s =~ s/;\n//; + $s; + } + + sub wm_prepare { + my ($wm) = @_; + my $orig = qq{'$wm'}; + PublicInbox::NNTP::wildmat2re($_[0]); + my $new = quote_str($_[0]); + ($orig, $new); + } + + sub wildmat_like { + my ($str, $wm) = @_; + my ($orig, $new) = wm_prepare($wm); + like($str, $wm, "$orig matches '$str' using $new"); + } + + sub wildmat_unlike { + my ($str, $wm, $check_ex) = @_; + if ($check_ex) { + use re 'eval'; + my $re = qr/$wm/; + like($str, $re, "normal re with $wm matches, but ..."); + } + my ($orig, $new) = wm_prepare($wm); + unlike($str, $wm, "$orig does not match '$str' using $new"); + } + + wildmat_like('[foo]', '[\[foo\]]'); + wildmat_like('any', '*'); + wildmat_unlike('bar.foo.bar', 'foo.*'); + + # no code execution + wildmat_unlike('HI', '(?{"HI"})', 1); + wildmat_unlike('HI', '[(?{"HI"})]', 1); +} + +{ + sub ngpat_like { + my ($str, $pat) = @_; + my $orig = $pat; + PublicInbox::NNTP::ngpat2re($pat); + like($str, $pat, "'$orig' matches '$str' using $pat"); + } + + ngpat_like('any', '*'); + ngpat_like('a.s.r', 'a.t,a.s.r'); + ngpat_like('a.s.r', 'a.t,a.s.*'); +} + +done_testing(); |