On 29.11.2011 11:44, Torsten Förtsch wrote:
> These calls to user_agent(reset=>1) are the actual reason for this mail. I
> think it is wrong to do that here. The user agent keeps a global state that
> is
> reset if user_agent() is called with reset=>1. set_client_cert() is called by
> prepare() which is called by GET, POST etc.
>
> According to the documentation for Apache::TestRequest the way to make the UA
> not to follow redirects is
>
> Apache::TestRequest::user_agent(reset => 1,
> requests_redirectable => 0);
>
> before calling GET.
>
> If now GET itself calls user_agent(reset=>1) via prepare() and
> set_client_cert() wouldn't that clobber the "requests_redirectable => 0"
> setting made by the user?
You're right, indeed - thanks for pointing this out. After further
testing and experiments, I think that the attached patch should take
care of this... does this look like an acceptable solution?
Kaspar
Index: Apache-Test/lib/Apache/TestRequest.pm
===================================================================
--- Apache-Test/lib/Apache/TestRequest.pm (revision 1207758)
+++ Apache-Test/lib/Apache/TestRequest.pm (working copy)
@@ -626,20 +626,27 @@ sub set_client_cert {
my $dir = join '/', $vars->{sslca}, $vars->{sslcaorg};
if ($name) {
- $ENV{HTTPS_CERT_FILE} = "$dir/certs/$name.crt";
- $ENV{HTTPS_KEY_FILE} = "$dir/keys/$name.pem";
+ my ($cert, $key) = ("$dir/certs/$name.crt", "$dir/keys/$name.pem");
+ @ENV{qw/HTTPS_CERT_FILE HTTPS_KEY_FILE/} = ($cert, $key);
if ($LWP::VERSION >= 6.0) {
- # LWP 6 no longer honors HTTPS_{CERT,KEY}_FILE
- user_agent(reset => 1,
- ssl_opts => { SSL_cert_file => "$dir/certs/$name.crt",
- SSL_key_file => "$dir/keys/$name.pem" });
+ # IO::Socket:SSL doesn't look at environment variables
+ if ($UA) {
+ $UA->ssl_opts(SSL_cert_file => $cert);
+ $UA->ssl_opts(SSL_key_file => $key);
+ } else {
+ user_agent(ssl_opts => { SSL_cert_file => $cert,
+ SSL_key_file => $key });
+ }
}
}
else {
for (qw(CERT KEY)) {
delete $ENV{"HTTPS_${_}_FILE"};
}
- user_agent(reset => 1) if $LWP::VERSION >= 6.0;
+ if ($LWP::VERSION >= 6.0 and $UA) {
+ $UA->ssl_opts(SSL_cert_file => undef);
+ $UA->ssl_opts(SSL_key_file => undef);
+ }
}
}