perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Philippe M. Chiasson" <go...@cpan.org>
Subject Re: [mp2 Patch] Add simple tests in modules/ for Apache::Session
Date Tue, 10 Jun 2003 06:30:01 GMT
On Tue, 2003-06-10 at 14:16, Stas Bekman wrote:
> Philippe M. Chiasson wrote:
> > Hi, after seeing a question asking about Apache::Session under mod_perl
> > 2.x, I've written this simple test case for it and it seems to be
> > working quite nicely under mp2, AFAICS
> 
> Did you plan on attaching something?

Hrm, well, of course I did !

Index: t/modules/session.t
===================================================================
RCS file: t/modules/session.t
diff -N t/modules/session.t
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ t/modules/session.t	10 Jun 2003 06:06:22 -0000
@@ -0,0 +1,48 @@
+use strict;
+use warnings FATAL => 'all';
+
+use Apache::Test;
+use Apache::TestRequest;
+use Apache::TestUtil;
+
+plan tests => 6, have 'Apache::Session';
+
+my $module = 'TestModules::session';
+my $location = '/' . Apache::TestRequest::module2path($module);
+
+my ($input, $session_id, $global_sid);
+my $global_input = $$;
+
+{
+    my $res = GET $location;
+    
+    eval $res->content;
+    
+    ok t_cmp("", $input, "New Session");
+    
+    ok t_cmp(qr{^[0-9a-f]{32}$}, $session_id, "New Session");
+    
+    $global_sid = $session_id;
+}
+
+{
+    my $res = GET "$location/$session_id?$global_input";
+    
+    eval $res->content;
+    
+    ok t_cmp($global_input, $input, "token reception");
+    
+    ok t_cmp($global_sid, $session_id, "Session ID");
+}
+
+{
+    my $res = GET "$location/$session_id";
+    
+    eval $res->content;
+    
+    ok t_cmp($global_input, $input, "token retrievaln");
+    
+    ok t_cmp($global_sid, $session_id, "Session ID");
+}
+
+GET "$location/$session_id?cleanup";
Index: t/response/TestModules/session.pm
===================================================================
RCS file: t/response/TestModules/session.pm
diff -N t/response/TestModules/session.pm
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ t/response/TestModules/session.pm	10 Jun 2003 06:06:22 -0000
@@ -0,0 +1,50 @@
+package TestModules::session;
+
+use strict;
+use warnings FATAL => 'all';
+
+use Apache::Const -compile => 'OK';
+
+use Apache::RequestRec ();
+use ModPerl::Util ();
+use Apache::Session::File;
+use File::Spec ();
+
+my $tmpdir = File::Spec->tmpdir();
+
+sub handler
+{
+    my $r = shift;
+
+    $r->status(200);
+    $r->content_type("text/plain");
+
+    my $session_id = $r->path_info();
+    $session_id =~ s/^\///;
+
+    $session_id = $session_id ? $session_id : undef;
+
+    ModPerl::Util::untaint($session_id);
+
+    my %session;
+
+    tie %session, 'Apache::Session::File', $session_id,
+      {Directory => $tmpdir, LockDirectory => $tmpdir, Transaction => 1};
+
+    $session{input} ||= $r->args() || "";
+
+    $r->print(<<"EOF");
+\$session_id="$session{_session_id}";
+\$input="$session{input}";
+EOF
+
+    if ($session{input} eq "cleanup")
+    {
+        tied(%session)->delete;
+    }
+    
+    Apache::OK;
+}
+
+1;
+__END__



> > In parallel to mp1, that has quite a few tests for 3rd party Apache::*
> > modules, should we try and move some of those tests over to mp2's test
> > suite as well ?
> 
> I think we should move them only if they aren't 3rd party tests. If they are 
> it's the best that those modules will include a test suite.

Yes, it does make sense, especially once Apache::Test has reached a
wider audience. I agree.

So guess this particular test should be ditched and Apache::Session
should use Apache::Test for it's test suite. I might have time to give
it a shot later on. Keep reading ;-)

Gozer out.

> __________________________________________________________________
> Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
> http://stason.org/     mod_perl Guide ---> http://perl.apache.org
> mailto:stas@stason.org http://use.perl.org http://apacheweek.com
> http://modperlbook.org http://apache.org   http://ticketmaster.com
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
> For additional commands, e-mail: dev-help@perl.apache.org
-- 
-- -----------------------------------------------------------------------------
Philippe M. Chiasson /gozer\@(cpan|ectoplasm)\.org/ 88C3A5A5 (122FF51B/C634E37B)
http://gozer.ectoplasm.org/    F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3 A5A5
Q: It is impossible to make anything foolproof because fools are so ingenious.
perl -e'$$=\${gozer};{$_=unpack(P7,pack(L,$$));/^JAm_pH\n$/&&print||$$++&&redo}'

Mime
View raw message