[omd-commits] OMD Git: omd: tests: fixed cookie handling

git version control git at mathias-kettner.de
Tue Jul 5 09:24:00 CEST 2011


Module:   omd
Branch:   master
Commit:   96f984f179d3c35dfcb9eddae67c01a3c915ef80
URL:      http://omdistro.org/projects/omd/repository/revisions/96f984f179d3c35dfcb9eddae67c01a3c915ef80

Author:   Sven Nierlein <sven at nierlein.de>
Date:     Tue Jul  5 09:22:09 2011 +0200
Commiter: Sven Nierlein <sven at nierlein.de>
Date:     Tue Jul  5 09:22:09 2011 +0200

tests: fixed cookie handling

---

 t/TestUtils.pm |   24 +++++++++++++++---------
 1 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/t/TestUtils.pm b/t/TestUtils.pm
index d610860..650e1da 100644
--- a/t/TestUtils.pm
+++ b/t/TestUtils.pm
@@ -12,7 +12,8 @@ use Cwd;
 use Test::More;
 use Data::Dumper;
 use LWP::UserAgent;
-use File::Temp qw/ :POSIX /;
+use HTTP::Cookies::Netscape;
+use File::Temp qw/ tempfile /;
 use Test::Cmd;
 
 if($> != 0) {
@@ -198,11 +199,11 @@ sub remove_test_site {
 
   needs test hash
   {
-    url            => url to request
-    auth           => authentication (realm:user:pass)
-    code           => expected response code
-    like           => (list of) regular expressions which have to match content
-    unlike         => (list of) regular expressions which must not match content
+    url              => url to request
+    auth             => authentication (realm:user:pass)
+    code             => expected response code
+    like             => (list of) regular expressions which have to match content
+    unlike           => (list of) regular expressions which must not match content
     skip_html_lint   => flag to disable the html lint checking
     skip_link_check  => (list of) regular expressions to skip the link checks for
   }
@@ -503,14 +504,19 @@ sub _request {
     my $return = {};
     our $cookie_jar;
 
-    if(!defined $cookie_jar or !-f $cookie_jar) {
-        $cookie_jar = tmpnam();
+    if(!defined $cookie_jar) {
+        my($fh, $cookie_file) = tempfile(undef, UNLINK => 1);
+        unlink ($cookie_file);
+        $cookie_jar = HTTP::Cookies::Netscape->new(
+                                       file     => $cookie_file,
+                                       autosave => 1,
+                                       );
     }
 
     my $ua = LWP::UserAgent->new;
     $ua->timeout(30);
     $ua->env_proxy;
-    $ua->cookie_jar({ file => $cookie_jar });
+    $ua->cookie_jar($cookie_jar);
 
     if(defined $data->{'auth'}) {
         $data->{'url'} =~ m/(http|https):\/\/(.*?)(\/|:\d+)/;



More information about the omd-commits mailing list