Catalyst-Plugin-ErrorCatcher
view release on metacpan or search on metacpan
t/04.trace.t view on Meta::CPAN
like(
$ec_msg,
qr{Error: Vampire\n},
'Buffy staked the vampire'
);
}
# RT-64492 - check no session data in default report
TestApp->config->{stacktrace}{enable} = 1;
TestApp->config->{"Plugin::ErrorCatcher"}{enable} = 1;
{
ok( my ($res,$c) = ctx_request('http://localhost/foo/not_ok'), 'request ok' );
my $ec_msg;
eval{ $ec_msg = $c->_errorcatcher_msg };
ok( defined $ec_msg, 'parsed error message ok' );
foreach my $session_key (qw/__created __updated/) {
unlike(
$ec_msg,
qr{__created},
"no instances of '$session_key' in report"
);
}
}
# RT-72781 - show the parameters that were sent with the request and where the request came from
TestApp->config->{stacktrace}{enable} = 1;
TestApp->config->{"Plugin::ErrorCatcher"}{enable} = 1;
# test referer information is output
{
ok( my ($res,$c) = ctx_request('http://localhost/foo/referer'), 'request ok' );
my $ec_msg;
eval{ $ec_msg = $c->_errorcatcher_msg };
ok( defined $ec_msg, 'parsed error message ok' );
# we should have some referer information
_has_referer_ok($ec_msg);
}
# test output with QUERY params
{
# make a request with params
ok( my ($res,$c) =
ctx_request('http://localhost/foo/referer?one=man&went=to&mow=1&long_thingy=2'), 'request ok' );
my $ec_msg;
eval{ $ec_msg = $c->_errorcatcher_msg };
ok( defined $ec_msg, 'parsed error message ok' );
# we should have some referer information
_has_referer_ok($ec_msg);
# we should have the get header and lines with the key-value pairs
_has_QUERY_output($ec_msg);
# we should have keys and values for each query param
_has_keys_for_section('QUERY', [qw(one went long_thingy)], $ec_msg);
}
# test output with BODY params
{
# we still need to get to $c
ok ( my (undef,$c) = ctx_request('http://localhost/ok'), 'setup $c for BODY');
# make a request with BODY data
use HTTP::Request::Common;
my $response = request POST '/foo/referer', [
bar => 'baz',
something => 'else'
];
my $ec_msg;
eval{ $ec_msg = $c->_errorcatcher_msg };
ok( defined $ec_msg, 'parsed error message ok' );
# we should have some referer information
_has_referer_ok($ec_msg);
# we should have the get header and lines with the key-value pairs
_has_BODY_output($ec_msg);
# we should have keys and values for each query param
_has_keys_for_section('BODY', [qw(bar something)], $ec_msg);
}
# test output with both QUERY and BODY params
{
# we still need to get to $c; this appears to be the only way
ok ( my (undef,$c) = ctx_request('http://localhost/ok'), 'setup $c for BODY');
# make a request with BODY data
use HTTP::Request::Common;
my $response = request POST '/foo/referer?fruit=banana&animal=kangaroo', [
vampire => 'joe random',
slayer => 'kendra'
];
my $ec_msg;
eval{ $ec_msg = $c->_errorcatcher_msg };
ok( defined $ec_msg, 'parsed error message ok' );
# we should have some referer information
_has_referer_ok($ec_msg);
# QUERY
# we should have the get header and lines with the key-value pairs
_has_QUERY_output($ec_msg);
# we should have keys and values for each query param
_has_keys_for_section('QUERY', [qw(fruit animal)], $ec_msg);
# BODY
# we should have the get header and lines with the key-value pairs
_has_BODY_output($ec_msg);
# we should have keys and values for each query param
_has_keys_for_section('BODY', [qw(vampire slayer)], $ec_msg);
}
# test output with both QUERY and BODY params
# - test with a case where we don't set the referer
{
# we still need to get to $c; this appears to be the only way
ok ( my (undef,$c) = ctx_request('http://localhost/ok'), 'setup $c for POST');
# make a request with BODY data
use HTTP::Request::Common;
my $response = request POST '/foo/not_ok?fruit=banana&animal=kangaroo', [
vampire => 'joe random',
slayer => 'kendra'
];
my $ec_msg;
eval{ $ec_msg = $c->_errorcatcher_msg };
ok( defined $ec_msg, 'parsed error message ok' );
# we should have some referer information
_has_no_referer_ok($ec_msg);
# QUERY
# we should have the get header and lines with the key-value pairs
_has_QUERY_output($ec_msg);
# we should have keys and values for each query param
_has_keys_for_section('QUERY', [qw(fruit animal)], $ec_msg);
# BODY
# we should have the get header and lines with the key-value pairs
_has_BODY_output($ec_msg);
# we should have keys and values for each query param
_has_keys_for_section('BODY', [qw(vampire slayer)], $ec_msg);
}
# test output with long values in parameters
{
# we still need to get to $c; this appears to be the only way
ok ( my (undef,$c) = ctx_request('http://localhost/ok'), 'setup $c for POST');
# make a request with BODY data
use HTTP::Request::Common;
my $response = request POST '/foo/not_ok?integer=69&fruit=' . 'banana' x 10, [
long_text => 'kangaroo' x 8,
normal => 'short_thing',
evil => "two\nlines",
# pad out the file types we're fakng so we aren't short enough to just
# return
image_gif => 'GIF87a' . 'Z' x 100,
image_png => "\x89PNG" . 'Z' x 100,
pdf_file => '%PDF-' . 'Z' x 100,
];
my $ec_msg;
eval{ $ec_msg = $c->_errorcatcher_msg };
ok( defined $ec_msg, 'parsed error message ok' );
# we should have some referer information
_has_no_referer_ok($ec_msg);
# QUERY
# we should have the get header and lines with the key-value pairs
_has_QUERY_output($ec_msg);
# we should have keys and values for each query param
_has_keys_for_section('QUERY', [qw(fruit integer)], $ec_msg);
# BODY
# we should have the get header and lines with the key-value pairs
_has_BODY_output($ec_msg);
# we should have keys and values for each query param
_has_keys_for_section('BODY', [qw(image_gif image_png long_text pdf_file normal evil)], $ec_msg);
# check the values look sane
_has_value_for_key( 'BODY', 'image_gif', qr{image/gif}, $ec_msg);
_has_value_for_key( 'BODY', 'image_png', qr{image/x-png}, $ec_msg);
_has_value_for_key( 'BODY', 'pdf_file', qr{application/pdf}, $ec_msg);
_has_value_for_key( 'BODY', 'normal', qr{short_thing}, $ec_msg);
_has_value_for_key( 'BODY', 'long_text', qr{kangarookangarookangarookangarookangaroo\.\.\.\[truncated\]}, $ec_msg);
_has_value_for_key('QUERY', 'fruit', qr{bananabananabananabananabananabananabana\.\.\.\[truncated\]}, $ec_msg);
_has_value_for_key('QUERY', 'integer', qr{69}, $ec_msg);
_has_value_for_key('QUERY', 'evil', qr{two(?:\\r)?\\nlines}, $ec_msg);
}
# helper methods for RT-72781 testing
sub _has_referer_ok {
# we should have some referer information
like(
shift,
qr{\s+Referer:\s+http://garlic-weapons.tv},
'referer information exists'
);
}
sub _has_no_referer_ok {
# we should have some referer information
unlike(
shift,
qr{\s+Referer:\s+},
'referer information exists'
);
}
sub _has_QUERY_output {
_has_param_section('QUERY',@_);
( run in 0.818 second using v1.01-cache-2.11-cpan-39bf76dae61 )