about summary refs log tree commit homepage
path: root/xt
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-05-01 06:21:13 +0000
committerEric Wong <e@80x24.org>2021-05-01 19:11:32 +0000
commite3196d9a2b15432e8a1f1a4a26d275b5a6d58b3b (patch)
tree859ce09f2a63e88ea3b9de505a03f4a44ec33e1e /xt
parentb2ae85ca49c6036adb818fed48f266b693c1812d (diff)
downloadpublic-inbox-e3196d9a2b15432e8a1f1a4a26d275b5a6d58b3b.tar.gz
These tests require a running Tor instance (defaulting to
127.0.0.1:9050) and Internet connectivity, but otherwise
work pretty well.
Diffstat (limited to 'xt')
-rw-r--r--xt/lei-onion-convert.t61
1 files changed, 61 insertions, 0 deletions
diff --git a/xt/lei-onion-convert.t b/xt/lei-onion-convert.t
new file mode 100644
index 00000000..d38b4b16
--- /dev/null
+++ b/xt/lei-onion-convert.t
@@ -0,0 +1,61 @@
+#!perl -w
+# Copyright (C) 2021 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+use strict; use v5.10; use PublicInbox::TestCommon;
+use PublicInbox::MboxReader;
+my $test_tor = $ENV{TEST_TOR};
+plan skip_all => "TEST_TOR unset" unless $test_tor;
+unless ($test_tor =~ m!\Asocks5h://!i) {
+        my $default = 'socks5h://127.0.0.1:9050';
+        diag "using $default (set TEST_TOR=socks5h://ADDR:PORT to override)";
+        $test_tor = $default;
+}
+my $onion = $ENV{TEST_ONION_HOST} //'ou63pmih66umazou.onion';
+my $ng = 'inbox.comp.mail.public-inbox.meta';
+my $nntp_url = $ENV{TEST_NNTP_ONION_URL} // "nntp://$onion/$ng";
+my $imap_url = $ENV{TEST_IMAP_ONION_URL} // "imap://$onion/$ng.0";
+my @cnv = qw(lei convert -o mboxrd:/dev/stdout);
+my @proxy_cli = ("--proxy=$test_tor");
+my $proxy_cfg = "proxy=$test_tor";
+test_lei(sub {
+        my $run = {};
+        for my $args ([$nntp_url, @proxy_cli], [$imap_url, @proxy_cli],
+                        [ $nntp_url, '-c', "nntp.$proxy_cfg" ],
+                        [ $imap_url, '-c', "imap.$proxy_cfg" ]) {
+                pipe(my ($r, $w)) or xbail "pipe: $!";
+                my $cmd = [@cnv, @$args];
+                my $td = start_script($cmd, undef, { 1 => $w, run_mode => 0 });
+                $args->[0] =~ s!\A(.+?://).*!$1...!;
+                my $key = "@$args";
+                ok($td, "$key running");
+                $run->{$key} = { td => $td, r => $r };
+        }
+        while (my ($key, $x) = each %$run) {
+                my ($td, $r) = delete(@$x{qw(td r)});
+                eval {
+                        PublicInbox::MboxReader->mboxrd($r, sub {
+                                my ($eml) = @_;
+                                if ($key =~ m!\Anntps?://!i) {
+                                        for (qw(Xref Newsgroups Path)) {
+                                                $eml->header_set($_);
+                                        }
+                                }
+                                push @{$x->{eml}}, $eml;
+                                close $r;
+                                $td->kill('-INT');
+                                die "$key done\n";
+                        });
+                };
+                chomp(my $done = $@);
+                like($done, qr/\Q$key\E done/, $done);
+                $td->join;
+        }
+        my @keys = keys %$run;
+        my $first_key = shift @keys;
+        for my $key (@keys) {
+                is_deeply($run->{$key}, $run->{$first_key},
+                        "`$key' matches `$first_key'");
+        }
+});
+
+done_testing;