our
$base
;
our
@use
=
qw(WebEdit)
;
plan
skip_all
=>
'Contributions are an author test. Set $ENV{TEST_AUTHOR} to a true value to run.'
unless
$ENV
{TEST_AUTHOR};
require
'./t/test.pl'
;
our
$dir
;
our
$host
;
our
$port
;
my
$page
= query_web(
"GET /page/Hello HTTP/1.0\r\n"
.
"host: $host:$port"
);
like(
$page
,
qr/^HTTP\/
1.1 200 OK/,
"Page served via HTTP"
);
like(
$page
,
qr/This page does not yet exist/
,
"Empty page"
);
$page
= query_web(
"GET /do/edit/Hello HTTP/1.0\r\n"
.
"host: $host:$port"
);
like(
$page
,
qr/^HTTP\/
1.1 200 OK/,
"Edit page served via HTTP"
);
my
$haiku
=
<<EOT;
The laptop streaming
videos of floods and rain
but I hear sparrows
EOT
my
$content
=
"text="
. uri_escape_utf8(
"```\n$haiku```"
);
my
$length
=
length
(
$content
);
$page
= query_web(
"POST /do/edit/Hello HTTP/1.0\r\n"
.
"host: $host:$port\r\n"
.
"content-type: application/x-www-form-urlencoded\r\n"
.
"content-length: $length\r\n"
.
"\r\n"
.
$content
);
like(
$page
,
qr/^HTTP\/
1.1 400 Bad Request/,
"Token required"
);
like(
$page
,
qr/^Token required/
m,
"Token required error"
);
$content
=
"text="
. uri_escape_utf8(
"```\n$haiku```"
) .
"&token=lalala"
;
$length
=
length
(
$content
);
$page
= query_web(
"POST /do/edit/Hello HTTP/1.0\r\n"
.
"host: $host:$port\r\n"
.
"content-type: application/x-www-form-urlencoded\r\n"
.
"content-length: $length\r\n"
.
"\r\n"
.
$content
);
like(
$page
,
qr/^HTTP\/
1.1 400 Bad Request/,
"Wrong Token"
);
like(
$page
,
qr/^Wrong token/
m,
"Wrong token error"
);
$content
=
"text="
. uri_escape_utf8(
"```\n$haiku```"
) .
"&token=hello"
;
$length
=
length
(
$content
);
$page
= query_web(
"POST /do/edit/Hello HTTP/1.0\r\n"
.
"host: $host:$port\r\n"
.
"content-type: application/x-www-form-urlencoded\r\n"
.
"content-length: $length\r\n"
.
"\r\n"
.
$content
);
like(
$page
,
qr/^HTTP\/
1.1 302 Found/,
"Redirect after save"
);
like(query_web(
"GET /page/Hello HTTP/1.0\r\nhost: $host:$port"
),
qr/The laptop streaming/
,
"Page saved"
);
done_testing;