plan
skip_all
=>
'Contributions are an author test. Set $ENV{TEST_AUTHOR} to a true value to run.'
unless
$ENV
{TEST_AUTHOR};
our
$host
;
our
@hosts
=
qw(localhost 127.0.0.1)
;
our
@spaces
=
qw(localhost/alex)
;
our
$dir
;
our
$base
;
our
@use
=
qw(Gopher)
;
my
$gopher_port
= Mojo::IOLoop::Server->generate_port;
my
$gophers_port
= Mojo::IOLoop::Server->generate_port;
our
@config
= (
<<"EOF");
package App::Phoebe::Gopher;
our \$gopher_port = $gopher_port;
our \$gophers_port = $gophers_port;
our \$gopher_host = "localhost";
EOF
require
'./t/test.pl'
;
sub
query_gopher {
my
$query
=
shift
;
my
$tls
=
shift
;
my
$socket
;
if
(
$tls
) {
$socket
= IO::Socket::SSL->new(
PeerHost
=>
$host
,
PeerPort
=>
$gophers_port
,
SSL_verify_mode
=> SSL_VERIFY_NONE)
or
die
"Cannot construct client socket: $@"
;
}
else
{
$socket
= IO::Socket::IP->new(
"$host:$gopher_port"
)
or
die
"Cannot construct client socket: $@"
;
}
$socket
->
print
(
"$query\r\n"
);
undef
$/;
return
<
$socket
>;
}
mkdir
(
"$dir/localhost"
);
mkdir
(
"$dir/localhost/page"
);
write_text(
"$dir/localhost/page/2021-02-05.gmi"
,
"yo"
);
mkdir
(
"$dir/localhost/alex"
);
mkdir
(
"$dir/localhost/alex/page"
);
write_text(
"$dir/localhost/alex/page/2021-02-05.gmi"
,
"lo"
);
my
$page
= query_gopher(
""
);
like(
$page
,
qr/^iWelcome to Phoebe/
m,
"Main menu"
);
like(
$page
,
qr/^iPhlog:/
m,
"Main menu (Blog section)"
);
like(
$page
,
qr/^02021-02-05\tpage\/
2021-02-05\tlocalhost\t
$gopher_port
$/m,
"Main menu (Blog link)"
);
like(
$page
,
qr(^1Index of all pages\tdo/index\tlocalhost\t$gopher_port$)
m,
"Page index link"
);
unlike(
$page
,
qr(=>)
,
"No Gemini link on the main menu"
);
$page
= query_gopher(
""
, 1);
like(
$page
,
qr/^iWelcome to Phoebe/
m,
"Main menu via TLS"
);
like(
$page
,
qr/^iPhlog:/
m,
"Main menu (Blog section) via TLS"
);
like(
$page
,
qr/^02021-02-05\tpage\/
2021-02-05\tlocalhost\t
$gophers_port
$/m,
"Main menu (Blog link) via TLS"
);
like(
$page
,
qr(^1Index of all pages\tdo/index\tlocalhost\t$gophers_port$)
m,
"Page index link via TLS"
);
$page
= query_gopher(
"page/2021-02-05"
);
like(
$page
,
qr(^2021-02-05$)
m,
"Page Title"
);
like(
$page
,
qr(^==========$)
m,
"Page Title Unterline"
);
like(
$page
,
qr(^yo$)
m,
"Page Text"
);
like(query_gopher(
"page/2021-02-05"
, 1),
qr(^yo$)
m,
"Page via TLS"
);
$page
= query_gopher(
"2021-02-05"
);
like(
$page
,
qr(^2021-02-05$)
m,
"Page Title"
);
my
$haiku
=
<<'EOT';
Through open windows
Hear the garbage truck's engine
Rattle in the heat
EOT
write_text(
"$dir/localhost/page/2021-06-28.gmi"
,
"```\n$haiku```\n"
);
$page
= query_gopher(
"2021-06-28"
);
like(
$page
,
qr(^2021-06-28\n==========\n$haiku*$)
,
"No empty lines"
);
$page
= query_gopher(
"alex/page/2021-02-05"
);
like(
$page
,
qr(^lo$)
m,
"Different Page Text in a Space"
);
like(query_gopher(
"alex/page/2021-02-05"
, 1),
qr(^lo$)
m,
"Different Page Text in a Space via TLS"
);
like(query_gopher(
"do/index"
),
qr/^02021-02-05\tpage\/
2021-02-05\tlocalhost\t
$gopher_port
$/m,
"Index"
);
like(query_gopher(
"do/index"
, 1),
qr/^02021-02-05\tpage\/
2021-02-05\tlocalhost\t
$gophers_port
$/m,
"Index via TLS"
);
like(query_gopher(
"do/match\t05"
),
qr/^02021-02-05\tpage\/
2021-02-05\tlocalhost\t
$gopher_port
$/m,
"Match"
);
like(query_gopher(
"do/match\t05"
, 1),
qr/^02021-02-05\tpage\/
2021-02-05\tlocalhost\t
$gophers_port
$/m,
"Match via TLS"
);
like(query_gopher(
"do/search\tyo"
),
qr/^02021-02-05\tpage\/
2021-02-05\tlocalhost\t
$gopher_port
$/m,
"Search"
);
like(query_gopher(
"do/search\tyo"
, 1),
qr/^02021-02-05\tpage\/
2021-02-05\tlocalhost\t
$gophers_port
$/m,
"Search via TLS"
);
$page
= query_gemini(
"$base/"
);
like(
$page
,
qr/Welcome to Phoebe/
,
"Main menu via Gemini"
);
like(
$page
,
qr/^Blog:/
m,
"Main menu (Blog section) via Gemini"
);
like(
$page
,
qr/^=> $base\/
page\/2021-02-05 2021-02-05/m,
"Main menu contains 2021-02-05 via Gemini"
);
done_testing();