Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I have a question concerning SOAP::Lite initialization.
I have a self-written module where the constructor accepts two parameters for the username & password and then sets a couple of variables at module scope:
my ($_username, $_password); sub new { my ($username, $password) = @_; $_username = $username; $_password = $password; my $self = {}; # ... bless $self; }
These two module variables are then used in the overloading of SOAP::Transport::HTTP::Client which is used in authentication:
sub SOAP::Transport::HTTP::Client::get_basic_credentials { return $_username => $_password; }
The reason for pushing this into the module is because it being used in a Test::More script & the SOAP's complexities are to be hidden in the module.
Typically, a new module instance is used for running a battery of tests. Execution is made of a number of tests which all authenticate fine using one module instance in one subroutine is followed by creating a new module instance using bad credentials before executing another series of tests which should all intentionally fail in yet a different subroutine.
At least, this is what I intended. I assumed that placing different module instances each in their own subroutines would take care of any lingering scoping issues. I thought I could reset authentication upon the creation of each new module instance.
What I am seeing in practice is if an instance of the module is created using a correct username/password pair, all tests associated with that instance succeed as expected. What is unexpected is if I then create a new instance of the module with a bad username/password pair, all associated tests still pass because authentication was successful.
If I then go back to the initial set of tests (originally intended to pass...), & set the username/password incorrectly, those tests all fail as expected. Creation of another module instance with bad credentials causes all subsequent tests to fail as is expected.
Am I correct to assume that the username/password is getting cached? If so, is there a way I can reinitialize SOAP::Lite such that I can use my module as intended toggling authentication as intended? Any suggestions would be greatly appreciated.
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: SOAP initialization?
by Anonymous Monk on Aug 02, 2012 at 07:56 UTC |