[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[PATCH] Add test suit for HttpSession getId, isNew, getMaxInactiveInterval()
From: Sergey Jukov <sergey@total-knowledge.com>
---
ChangeLog | 4 +++
Makefile.adon | 2 +
session/Makefile.adon | 1 +
session/sessionGetMaxTime.pl | 58 ++++++++++++++++++++++++++++++++++++++++
session/sessionGetSession.pl | 57 +++++++++++++++++++++++++++++++++++++++
session/sessionGetSessionId.pl | 54 +++++++++++++++++++++++++++++++++++++
tests/output.pl | 14 ++++++++++
7 files changed, 190 insertions(+), 0 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index b25c28c..bed96db 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Sergey Jukov <sergey@total-knowledge.com> Fri, 29 Sep 2006 10:30:00 -0800
+- Add testing suit for HttpSession functions getId(), isNew(),
+ getMaxInactiveInterval().
+
Sergey Jukov <sergey@total-knowledge.com> Wed, 20 Sep 2006 14:40:00 -0800
- Add testing getId(), getCreationTime(), getLastAccessedTime(),
setMaxInactiveInterval(), getMaxInactiveInterval(), isNew() and
diff --git a/Makefile.adon b/Makefile.adon
index c6d485f..566a91e 100644
--- a/Makefile.adon
+++ b/Makefile.adon
@@ -1,2 +1,4 @@
ADON_SUBDIRS := csp-store hello attributes reset utils fileupload redirect cookies session headers sharedata params BooksODBC database index
EXTRA_DIST := README engine.xml
+export CPPSERV_TEST_HOST ?= sergey
+export CPPSERV_TEST_URLBASE ?= http://localhost/~sergey/csp
diff --git a/session/Makefile.adon b/session/Makefile.adon
index a9b3298..eda641f 100644
--- a/session/Makefile.adon
+++ b/session/Makefile.adon
@@ -1,3 +1,4 @@
noinst_LTLIBRARIES := SessionServlet
SessionServlet_SOURCES := session.cpp
noinst_HEADERS := session.h
+check_SCRIPTS:=sessionGetSessionId.pl sessionGetSession.pl sessionGetMaxTime.pl
diff --git a/session/sessionGetMaxTime.pl b/session/sessionGetMaxTime.pl
new file mode 100755
index 0000000..00f0339
--- /dev/null
+++ b/session/sessionGetMaxTime.pl
@@ -0,0 +1,58 @@
+#!/usr/bin/perl
+
+# This script sessionGetMaxTime.pl tests work of
+# HttpSession::getMaxInactiveInterval() function.
+
+use LWP::UserAgent;
+use HTTP::Cookies;
+do "tests/output.pl";
+
+my $test = "HttpSession::getMaxInactiveInterval()";
+my $servletName = "SessionServlet";
+my $urlbase = $ENV{CPPSERV_TEST_URLBASE};
+my $url = $urlbase."/".$servletName;
+my $timeInterval;
+my $sessionCheck = "";
+my $counter = 0;
+my $file = "tests/lwp_cookies.dat";
+
+# Run 4 times, sleep at least 30 seconds for the new session
+OUT: while($counter < 31) {
+ sleep $counter;
+ my $ua = LWP::UserAgent->new;
+ my $req = HTTP::Request->new(POST => $url);
+ $req->content_type('application/x-www-form-urlencoded');
+ my $cookie_jar = HTTP::Cookies->new(
+ file => $file,
+ autosave => 1,
+ ignore_discard => 1,
+ );
+ if(-e $file) {
+ $ua->cookie_jar($cookie_jar);
+ my $cookieString = $cookie_jar->as_string;
+ $cookieString =~ /Set-Cookie[\d]*: (.+)=(.+); path=\"(.*)\"; domain=(.*?);/;
+ # Hack, change cookie version from 1 to 0.
+ $cookie_jar->set_cookie("0","$1","$2","$3","$4");
+ }
+ my $res = $ua->request($req);
+ if ($res->is_success) {
+ my $line = $res->content;
+ $line =~ s/\n+//g;
+ $line =~ /<PRE>(.*)You hit.*Maximum time interval:\s(.+)\sseconds/;
+ $sessionCheck = $1;
+ $timeInterval = $2;
+ } else {
+ die &test_die($url, $res->status_line);
+ }
+ if(($sessionCheck eq "New session!") && $counter != 0) {
+ last OUT;
+ }
+ $counter += 10;
+}
+
+# Compare results.
+if($timeInterval == $counter) {
+ print &test_ok($test);
+} else {
+ print &test_not_ok($test);
+}
diff --git a/session/sessionGetSession.pl b/session/sessionGetSession.pl
new file mode 100755
index 0000000..688ec9f
--- /dev/null
+++ b/session/sessionGetSession.pl
@@ -0,0 +1,57 @@
+#!/usr/bin/perl
+
+# This script sessionGetSession.pl tests work of
+# HttpSession::isNew() function.
+
+use LWP::UserAgent;
+use HTTP::Cookies;
+do "tests/output.pl";
+
+my $test = "HttpSession::isNew()";
+my $servletName = "SessionServlet";
+my $urlbase = $ENV{CPPSERV_TEST_URLBASE};
+my $url = $urlbase."/".$servletName;
+my @sessions;
+my @strings;
+my $counter = 0;
+my $file = "tests/lwp_cookies.dat";
+
+# Run 3 times, sleep at least 30 seconds for the new session.
+while($counter < 3) {
+ my $ua = LWP::UserAgent->new;
+ my $req = HTTP::Request->new(POST => $url);
+ $req->content_type('application/x-www-form-urlencoded');
+ my $cookie_jar = HTTP::Cookies->new(
+ file => $file,
+ autosave => 1,
+ ignore_discard => 1,
+ );
+ if(-e $file) {
+ $ua->cookie_jar($cookie_jar);
+ my $cookieString = $cookie_jar->as_string;
+ $cookieString =~ /Set-Cookie[\d]*: (.+)=(.+); path=\"(.*)\"; domain=(.*?);/;
+ # Hack, change cookie version from 1 to 0.
+ $cookie_jar->set_cookie("0","$1","$2","$3","$4");
+ }
+ my $res = $ua->request($req);
+ if ($res->is_success) {
+ my $line = $res->content;
+ $line =~ s/\n+//g;
+ $line =~ /<PRE>(.*)You hit.*SessionID:\s(.+)Creation/;
+ $strings[$counter] = $1;
+ $sessions[$counter] = $2;
+ } else {
+ die &test_die($url, $res->status_line);
+ }
+ $counter++;
+ if($counter == 2){
+ sleep 31;
+ }
+}
+
+# Compare results.
+if(($sessions[0] eq $sessions[1]) && ($strings[1] eq "Old session") && ($sessions[1] ne $sessions[2]) && ($strings[2] eq "New session!")) {
+ print &test_ok($test);
+} else {
+ print &test_not_ok($test);
+}
diff --git a/session/sessionGetSessionId.pl b/session/sessionGetSessionId.pl
new file mode 100755
index 0000000..d7fdb18
--- /dev/null
+++ b/session/sessionGetSessionId.pl
@@ -0,0 +1,54 @@
+#!/usr/bin/perl
+
+# This script sessionGetSessionId.pl tests work of
+# HttpSession::getId() function.
+
+use LWP::UserAgent;
+use HTTP::Cookies;
+do "tests/output.pl";
+
+my $test = "HttpSession::getId()";
+my $servletName = "SessionServlet";
+my $urlbase = $ENV{CPPSERV_TEST_URLBASE};
+my $url = $urlbase."/".$servletName;
+my $cookieSessionId = "";
+my $webSessionId = "";
+my $counter = 0;
+my $file = "tests/lwp_cookies.dat";
+
+# Run several times to make sure cookie is saved.
+while($counter < 3) {
+ my $ua = LWP::UserAgent->new;
+ my $req = HTTP::Request->new(POST => $url);
+ $req->content_type('application/x-www-form-urlencoded');
+ my $cookie_jar = HTTP::Cookies->new(
+ file => $file,
+ autosave => 1,
+ ignore_discard => 1,
+ );
+ if(-e $file) {
+ $ua->cookie_jar($cookie_jar);
+ my $cookieString = $cookie_jar->as_string;
+ $cookieString =~ /Set-Cookie[\d]*: (.+)=(.+); path=\"(.*)\"; domain=(.*?);/;
+ $cookieSessionId=$2;
+ # Hack, change cookie version from 1 to 0.
+ $cookie_jar->set_cookie("0","$1","$cookieSessionId","$3","$4");
+ }
+ my $res = $ua->request($req);
+ if ($res->is_success) {
+ my $line = $res->content;
+ $line =~ s/\n+//g;
+ $line =~ /SessionID:\s(.+)Creation/;
+ $webSessionId = $1;
+ } else {
+ die &test_die($url, $res->status_line);
+ }
+ $counter++;
+}
+
+# Compare results.
+if($cookieSessionId eq $webSessionId) {
+ print &test_ok($test);
+} else {
+ print &test_not_ok($test);
+}
diff --git a/tests/output.pl b/tests/output.pl
new file mode 100755
index 0000000..e820d94
--- /dev/null
+++ b/tests/output.pl
@@ -0,0 +1,14 @@
+#!/usr/bin/perl
+
+# This script output.pl prints formatted output
+# for test suit.
+
+sub test_ok {
+ return $_[0]." OK\n";
+}
+sub test_not_ok {
+ return "Check ".$_[0]." failed. NOT OK\n";
+}
+sub test_die {
+ return "Cannot get ".$_[0].": ".$_[1]." NOT OK\n";
+}
--
1.4.2