]> Sergey Matveev's repositories - public-inbox.git/blob - xt/lei-onion-convert.t
treewide: update to v3 Tor onions
[public-inbox.git] / xt / lei-onion-convert.t
1 #!perl -w
2 # Copyright (C) 2021 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use strict; use v5.10; use PublicInbox::TestCommon;
5 use PublicInbox::MboxReader;
6 my $test_tor = $ENV{TEST_TOR};
7 plan skip_all => "TEST_TOR unset" unless $test_tor;
8 unless ($test_tor =~ m!\Asocks5h://!i) {
9         my $default = 'socks5h://127.0.0.1:9050';
10         diag "using $default (set TEST_TOR=socks5h://ADDR:PORT to override)";
11         $test_tor = $default;
12 }
13 my $onion = $ENV{TEST_ONION_HOST} //
14         '7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion';
15 my $ng = 'inbox.comp.mail.public-inbox.meta';
16 my $nntp_url = $ENV{TEST_NNTP_ONION_URL} // "nntp://$onion/$ng";
17 my $imap_url = $ENV{TEST_IMAP_ONION_URL} // "imap://$onion/$ng.0";
18 my @cnv = qw(lei convert -o mboxrd:/dev/stdout);
19 my @proxy_cli = ("--proxy=$test_tor");
20 my $proxy_cfg = "proxy=$test_tor";
21 test_lei(sub {
22         my $run = {};
23         for my $args ([$nntp_url, @proxy_cli], [$imap_url, @proxy_cli],
24                         [ $nntp_url, '-c', "nntp.$proxy_cfg" ],
25                         [ $imap_url, '-c', "imap.$proxy_cfg" ]) {
26                 pipe(my ($r, $w)) or xbail "pipe: $!";
27                 my $cmd = [@cnv, @$args];
28                 my $td = start_script($cmd, undef, { 1 => $w, run_mode => 0 });
29                 $args->[0] =~ s!\A(.+?://).*!$1...!;
30                 my $key = "@$args";
31                 ok($td, "$key running");
32                 $run->{$key} = { td => $td, r => $r };
33         }
34         while (my ($key, $x) = each %$run) {
35                 my ($td, $r) = delete(@$x{qw(td r)});
36                 eval {
37                         PublicInbox::MboxReader->mboxrd($r, sub {
38                                 my ($eml) = @_;
39                                 if ($key =~ m!\Anntps?://!i) {
40                                         for (qw(Xref Newsgroups Path)) {
41                                                 $eml->header_set($_);
42                                         }
43                                 }
44                                 push @{$x->{eml}}, $eml;
45                                 close $r;
46                                 $td->kill('-INT');
47                                 die "$key done\n";
48                         });
49                 };
50                 chomp(my $done = $@);
51                 like($done, qr/\Q$key\E done/, $done);
52                 $td->join;
53         }
54         my @keys = keys %$run;
55         my $first_key = shift @keys;
56         for my $key (@keys) {
57                 is_deeply($run->{$key}, $run->{$first_key},
58                         "`$key' matches `$first_key'");
59         }
60 });
61
62 done_testing;