X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fimap.t;h=af59ef69386372ff824df970ca69733403f55f86;hb=cfae078171fc1453be0795e4ba5f0252627ebba3;hp=c435d365543c66a49c224469f8c74c70f110aab3;hpb=303d84f31df8d03a74677fd345c539a7ffa0580f;p=public-inbox.git diff --git a/t/imap.t b/t/imap.t index c435d365..af59ef69 100644 --- a/t/imap.t +++ b/t/imap.t @@ -1,17 +1,65 @@ #!perl -w # Copyright (C) 2020 all contributors # License: AGPL-3.0+ +# unit tests (no network) for IMAP, see t/imapd.t for end-to-end tests use strict; use Test::More; use PublicInbox::IMAP; +use PublicInbox::IMAPD; +use PublicInbox::TestCommon; +require_mods(qw(DBD::SQLite)); +require_git 2.6; + +my ($tmpdir, $for_destroy) = tmpdir(); +my $cfgfile = "$tmpdir/config"; +{ + open my $fh, '>', $cfgfile or BAIL_OUT $!; + print $fh <new; + my @w; + local $SIG{__WARN__} = sub { push @w, @_ }; + $imapd->refresh_groups; + my $self = { imapd => $imapd }; + is(scalar(@w), 1, 'got a warning for upper-case'); + like($w[0], qr/IGNORE\.THIS/, 'warned about upper-case'); + my $res = PublicInbox::IMAP::cmd_list($self, 'tag', 'x', '%'); + is(scalar($$res =~ tr/\n/\n/), 2, 'only one result'); + like($$res, qr/ x\r\ntag OK/, 'saw expected'); + $res = PublicInbox::IMAP::cmd_list($self, 'tag', 'x.', '%'); + is(scalar($$res =~ tr/\n/\n/), 3, 'only one result'); + is(scalar(my @x = ($$res =~ m/ x\.[zy]\r\n/g)), 2, 'match expected'); + + $res = PublicInbox::IMAP::cmd_list($self, 't', 'x.(?{die "RCE"})', '%'); + like($$res, qr/\At OK /, 'refname does not match attempted RCE'); + $res = PublicInbox::IMAP::cmd_list($self, 't', '', '(?{die "RCE"})%'); + like($$res, qr/\At OK /, 'wildcard does not match attempted RCE'); +} + { my $partial_prepare = \&PublicInbox::IMAP::partial_prepare; my $x = {}; - my $r = $partial_prepare->($x, [], my $p = 'BODY.PEEK[9]'); + my $r = $partial_prepare->($x, [], my $p = 'BODY[9]'); ok($r, $p); - $r = $partial_prepare->($x, [], $p = 'BODY.PEEK[9]<5>'); + $r = $partial_prepare->($x, [], $p = 'BODY[9]<5>'); ok($r, $p); - $r = $partial_prepare->($x, [], $p = 'BODY.PEEK[9]<5.1>'); + $r = $partial_prepare->($x, [], $p = 'BODY[9]<5.1>'); ok($r, $p); $r = $partial_prepare->($x, [], $p = 'BODY[1.1]'); ok($r, $p); @@ -26,17 +74,21 @@ use PublicInbox::IMAP; my $partial_body = \&PublicInbox::IMAP::partial_body; my $partial_hdr_get = \&PublicInbox::IMAP::partial_hdr_get; my $partial_hdr_not = \&PublicInbox::IMAP::partial_hdr_not; + my $hdrs_regexp = \&PublicInbox::IMAP::hdrs_regexp; is_deeply($x, { - 'BODY.PEEK[9]' => [ $partial_body, 9, undef, undef, undef ], - 'BODY.PEEK[9]<5>' => [ $partial_body, 9, undef, 5, undef ], - 'BODY.PEEK[9]<5.1>' => [ $partial_body, 9, undef, 5, 1 ], + 'BODY[9]' => [ $partial_body, 9, undef, undef, undef ], + 'BODY[9]<5>' => [ $partial_body, 9, undef, 5, undef ], + 'BODY[9]<5.1>' => [ $partial_body, 9, undef, 5, 1 ], 'BODY[1.1]' => [ $partial_body, '1.1', undef, undef, undef ], 'BODY[HEADER.FIELDS (DATE FROM)]' => [ $partial_hdr_get, - undef, 'DATE FROM', undef, undef ], + undef, $hdrs_regexp->('DATE FROM'), + undef, undef ], 'BODY[HEADER.FIELDS.NOT (TO)]' => [ $partial_hdr_not, - undef, 'TO', undef, undef ], + undef, $hdrs_regexp->('TO'), + undef, undef ], 'BODY[1.1.HEADER.FIELDS (TO)]' => [ $partial_hdr_get, - '1.1', 'TO', undef, undef ], + '1.1', $hdrs_regexp->('TO'), + undef, undef ], }, 'structure matches expected'); }