#!perl
my
$key
=
'robot_client'
;
my
$app
=
sub
{
my
$env
=
shift
;
my
$response
=
''
;
if
(
$env
->{
$key
} ) {
$response
=
"ROBOT CLIENT DETECTED"
;
}
else
{
$response
=
"REGULAR CLIENT DETECTED"
;
}
$response
.=
' | '
.
$env
->{
$key
};
return
[ 200, [
'Content-Type'
=>
'text/plain'
], [
$response
] ];
};
my
$app_with_plugin
= builder {
enable
'DetectRobots'
;
$app
;
};
foreach
my
$ua
( pmdr_ua_strings::browser_ua() ) {
test_psgi(
app
=>
$app_with_plugin
,
client
=>
sub
{
my
$cb
=
shift
;
$req
->header(
'User-Agent'
=>
$ua
);
my
$res
=
$cb
->(
$req
);
like
$res
->content,
qr/REGULAR CLIENT DETECTED/
,
$ua
;
}
);
}
foreach
my
$ua
( pmdr_ua_strings::common_bot_ua() ) {
test_psgi(
app
=>
$app_with_plugin
,
client
=>
sub
{
my
$cb
=
shift
;
$req
->header(
'User-Agent'
=>
$ua
);
my
$res
=
$cb
->(
$req
);
like
$res
->content,
qr/ROBOT CLIENT DETECTED/
,
$ua
;
}
);
}
foreach
my
$ua
( pmdr_ua_strings::other_bot_ua() ) {
test_psgi(
app
=>
$app_with_plugin
,
client
=>
sub
{
my
$cb
=
shift
;
$req
->header(
'User-Agent'
=>
$ua
);
my
$res
=
$cb
->(
$req
);
like
$res
->content,
qr/REGULAR CLIENT DETECTED/
,
$ua
;
}
);
}
done_testing;