GroupText.t: fix number of tests

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
This commit is contained in:
Colin Kuskie 2006-07-15 01:54:49 +00:00
parent 41bdf0e28d
commit f3a1f0f9f2
6 changed files with 65 additions and 8 deletions

View file

@ -370,7 +370,7 @@ sub open {
bless $self , $class;
$self->{_request} = Apache2::Request->new($request) if (defined $request);
my $sessionId = shift || $self->http->getCookies->{"wgSession"} || $self->id->generate;
$sessionId = $self->id->generate if ($sessionId !~ m/^[A-Za-z0-9\+\/=]{22}$/);
$sessionId = $self->id->generate unless $self->id->valid($sessionId);
my $noFuss = shift;
$self->{_var} = WebGUI::Session::Var->new($self,$sessionId, $noFuss);
$self->errorHandler->warn("You've disabled cache in your config file and that can cause many problems on a production site.") if ($config->get("disableCache"));

View file

@ -68,8 +68,7 @@ sub generate {
my($s,$us)=gettimeofday();
my($v)=sprintf("%09d%06d%10d%06d%255s",rand(999999999),$us,$s,$$,$self->session->config->getFilename);
my $id = Digest::MD5::md5_base64($v);
$id =~ s/\+/_/g;
$id =~ s/\//-/g;
$id =~ tr{+/}{_-};
return $id;
}
@ -105,6 +104,19 @@ sub session {
return $self->{_session};
}
#-------------------------------------------------------------------
=head2 valid ( $idString )
Returns true if $idString is a valid WebGUI guid.
=cut
sub valid {
my ($self, $idString) = @_;
return $idString =~ m/^[A-Za-z0-9_-]{22}$/;
}
1;