Session/Id.pm: add a method to validate GUIDs, change s/// to tr/// for efficiency. Session.pm: change open to use new Id.pm validation method Scratch.t: Change test from ok to is so that it tells you what the failing ID is. Id.t: Add validation tests in addition to uniqueness tests. Fix the uniqueness test so that it works. Add tests to check the new validation method
77 lines
1.9 KiB
Perl
77 lines
1.9 KiB
Perl
#-------------------------------------------------------------------
|
|
# WebGUI is Copyright 2001-2006 Plain Black Corporation.
|
|
#-------------------------------------------------------------------
|
|
# Please read the legal notices (docs/legal.txt) and the license
|
|
# (docs/license.txt) that came with this distribution before using
|
|
# this software.
|
|
#-------------------------------------------------------------------
|
|
# http://www.plainblack.com info@plainblack.com
|
|
#-------------------------------------------------------------------
|
|
|
|
use FindBin;
|
|
use strict;
|
|
use lib "$FindBin::Bin/../lib";
|
|
|
|
use WebGUI::Test;
|
|
use WebGUI::Session;
|
|
use WebGUI::Utility;
|
|
|
|
use Test::More;
|
|
|
|
my @testSets = (
|
|
{
|
|
comment => 'too short',
|
|
guid => 'tooShort',
|
|
valid => '',
|
|
},
|
|
{
|
|
comment => 'too long',
|
|
guid => '12345678901234567890123',
|
|
valid => '',
|
|
},
|
|
{
|
|
comment => 'contains white space',
|
|
guid => ' 23456 890123456789012',
|
|
valid => '',
|
|
},
|
|
{
|
|
comment => 'contains illegal punctuation',
|
|
guid => '12#4%67*901234&678901.',
|
|
valid => '',
|
|
},
|
|
{
|
|
comment => 'MD5 style',
|
|
guid => '==//abcdeZYXWV01234567',
|
|
valid => '',
|
|
},
|
|
{
|
|
comment => 'GUID style',
|
|
guid => '--__abcdeZYXWV0123456A',
|
|
valid => 1,
|
|
},
|
|
);
|
|
|
|
my $session = WebGUI::Test->session;
|
|
|
|
plan tests => scalar(@testSets) + 3;
|
|
|
|
# generate
|
|
my $generateId = $session->id->generate();
|
|
is(length($generateId), 22, "generate() - length of 22 characters");
|
|
my @uniqueIds;
|
|
my $isUnique = 1;
|
|
my $isValid = 1;
|
|
for (1..2000) {
|
|
last unless $isUnique;
|
|
my $id = $session->id->generate();
|
|
$isUnique = ($isUnique ? !isIn($id,@uniqueIds) : 0);
|
|
$isValid = ($isValid ? $session->id->valid($id) : 0);
|
|
push(@uniqueIds,$id);
|
|
}
|
|
ok($isUnique, "generate() - unique");
|
|
ok($isValid, "generate() - valid id generated");
|
|
|
|
foreach my $testSet (@testSets) {
|
|
is($session->id->valid($testSet->{guid}), $testSet->{valid}, $testSet->{comment});
|
|
}
|
|
|