Browse Source

Fix #154 ? - experimental usage revealed this doesn't quite work

with custom authenticators.  So here's hoping adding in a cookie jar
is "good enough".
George S. Baugh 9 years ago
parent
commit
e6ece00ba4
2 changed files with 5 additions and 2 deletions
  1. 1 0
      Changes
  2. 4 2
      lib/TestRail/API.pm

+ 1 - 0
Changes

@@ -2,6 +2,7 @@ Revision history for Perl module TestRail::API
 
 
 0.045 2019-05-11 TEODESIAN
 0.045 2019-05-11 TEODESIAN
     - Add getReports and runReport methods to TestRail::API
     - Add getReports and runReport methods to TestRail::API
+    - Use a cookie jar when doing requests to use testrail sessions if enabled for the API
 
 
 0.044 2018-10-9 TEODESIAN
 0.044 2018-10-9 TEODESIAN
     - Add getCaseFields and addCaseField methods to TestRail::API
     - Add getCaseFields and addCaseField methods to TestRail::API

+ 4 - 2
lib/TestRail/API.pm

@@ -52,6 +52,7 @@ use Type::Params qw( compile );
 use JSON::MaybeXS 1.001000 ();
 use JSON::MaybeXS 1.001000 ();
 use HTTP::Request;
 use HTTP::Request;
 use LWP::UserAgent;
 use LWP::UserAgent;
+use HTTP::CookieJar::LWP;
 use Data::Validate::URI qw{is_uri};
 use Data::Validate::URI qw{is_uri};
 use List::Util 1.33;
 use List::Util 1.33;
 use Encode ();
 use Encode ();
@@ -109,8 +110,9 @@ sub new {
         tr_fields        => undef,
         tr_fields        => undef,
         default_request  => undef,
         default_request  => undef,
         global_limit     => 250, #Discovered by experimentation
         global_limit     => 250, #Discovered by experimentation
-        browser          => new LWP::UserAgent(
+        browser          => LWP::UserAgent->new(
             keep_alive => 10,
             keep_alive => 10,
+            cookie_jar => HTTP::CookieJar::LWP->new(),
         ),
         ),
         do_post_redirect => $do_post_redirect,
         do_post_redirect => $do_post_redirect,
         max_tries        => $max_tries // 1,
         max_tries        => $max_tries // 1,
@@ -131,7 +133,7 @@ sub new {
         unless grep {$_ eq $self->{'encoding-nonaliased'}} (Encode->encodings(":all"));
         unless grep {$_ eq $self->{'encoding-nonaliased'}} (Encode->encodings(":all"));
 
 
     #Create default request to pass on to LWP::UserAgent
     #Create default request to pass on to LWP::UserAgent
-    $self->{'default_request'} = new HTTP::Request();
+    $self->{'default_request'} = HTTP::Request->new();
     $self->{'default_request'}->authorization_basic($user,$pass);
     $self->{'default_request'}->authorization_basic($user,$pass);
 
 
     bless( $self, $class );
     bless( $self, $class );