public-inbox.git  about / heads / tags
an "archives first" approach to mailing lists
blob d3afbbb9a365ade9849a3e75f635982ad4ba8258 2485 bytes (raw)
$ git show HEAD:xt/lei-onion-convert.t	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
 
#!perl -w
# Copyright (C) all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
use v5.12; use PublicInbox::TestCommon;
use PublicInbox::MboxReader;
use autodie qw(pipe close);
my $test_tor = $ENV{TEST_TOR};
plan skip_all => "TEST_TOR unset" unless $test_tor;
require_mods qw(IO::Socket::Socks IO::Socket::SSL Mail::IMAPClient Net::NNTP);
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} //
	'7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.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 {
	# ensure TLS + SOCKS works
	ok !lei(qw(ls-mail-source imaps://mews.public-inbox.org/
		-c), "imap.$proxy_cfg"),
		'imaps fails on wrong hostname w/ Tor';
	ok !lei(qw(ls-mail-source nntps://mews.public-inbox.org/
		-c), "nntp.$proxy_cfg"),
		'nntps fails on wrong hostname w/ Tor';

	lei_ok qw(ls-mail-source imaps://news.public-inbox.org/
		-c), "imap.$proxy_cfg";
	lei_ok qw(ls-mail-source nntps://news.public-inbox.org/
		-c), "nntp.$proxy_cfg";

	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, my $w);
		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;

git clone https://public-inbox.org/public-inbox.git
git clone http://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/public-inbox.git