961617765e
Add validation of the value of the KohaOpacRecentSearches. In particular, this patch avoids the generation of an internal server error when the OPAC is presented with an old cookie that uses the old Storable-based serialization. This patch also moves parsing of the cookie value into a new routine in C4::Auth, ParseSearchHistoryCookie, and adds a test case. To test (in conjunction with the previous patch): Exercise the OPAC search history functionality, after turning on the EnableOpacSearchHistory syspref: - As an anonymous user, conduct a variety of searches, including ones that include non-ASCII characters - Check the search history and verify that all searches are listed - Apply this patch and the previous one. - Do *not* clear the KohaOpacRecentSearches cookie - Check the search history and verify that no searches are listed any more - As an anonymous user, conduct a variety of searches, including ones that include non-ASCII characters - Check the search history and verify that all searches are listed - Log into the OPAC - Verify that current and past searches are listed in search history. Signed-off-by: Galen Charlton <gmc@esilibrary.com>
43 lines
1.2 KiB
Perl
43 lines
1.2 KiB
Perl
#!/usr/bin/perl
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
use Test::More tests => 3;
|
|
|
|
use_ok('C4::Auth', qw/ParseSearchHistoryCookie/);
|
|
|
|
my $valid_cookie = "%5B%7B%22time%22%3A1374978877%2C%22query_cgi%22%3A%22idx%3D%26q%3Dhistory%26branch_group_limit%3D%22%2C%22total%22%3A2%2C%22query_desc%22%3A%22kw%2Cwrdl%3A%20history%2C%20%22%7D%5D";
|
|
my $expected_recent_searches = [
|
|
{
|
|
'time' => 1374978877,
|
|
'query_cgi' => 'idx=&q=history&branch_group_limit=',
|
|
'total' => 2,
|
|
'query_desc' => 'kw,wrdl: history, '
|
|
}
|
|
];
|
|
|
|
my $input = CookieSimulator->new($valid_cookie);
|
|
my @recent_searches = ParseSearchHistoryCookie($input);
|
|
is_deeply(\@recent_searches, $expected_recent_searches, 'parsed valid search history cookie value');
|
|
|
|
# simulate bit of a Storable-based search history cookie
|
|
my $invalid_cookie = "%04%08%0812345";
|
|
$input = CookieSimulator->new($invalid_cookie);
|
|
@recent_searches = ParseSearchHistoryCookie($input);
|
|
is_deeply(\@recent_searches, [], 'got back empty search history list if given invalid cookie');
|
|
|
|
package CookieSimulator;
|
|
|
|
sub new {
|
|
my ($class, $str) = @_;
|
|
my $val = [ $str ];
|
|
return bless $val, $class;
|
|
}
|
|
|
|
sub cookie {
|
|
my $self = shift;
|
|
return $self->[0];
|
|
}
|
|
|
|
1;
|