WsdlToPhp / PackageGenerator

Generates a PHP SDK based on a WSDL, simple and powerful, WSDL to PHP
https://providr.io
MIT License
422 stars 73 forks source link

Problem receiving remote WSDL with Basic Auth #159

Closed pculka closed 4 years ago

pculka commented 5 years ago

Hi,

We found a little tiny bug that spans up to the SoapClient php ext and is being used in the packagegenerator Utils.php

When using Basic Authentication options to resolve a remote WSDL for package creation, we may use GeneratorOptions methods setBasicLogin and setBasicPassword. Now to fetch the .wsdl there is a method used in Utils::getStreamContextOptions, which merges used Authorization headers to be used to fetch all relevant data from remote host.

Now this method resolves first SoapClient streamContext options, but the problem is, that it includes a "\nConnection: Close" string at the end of the AuthorizationHeader. This gets recursively merged on line 114 and used afterwards as new stream context for file_get_contents on line 80. The problem is, that the Authorization header is invalid with the added "Connection: Close" string and therefore it can not fetch the requested .wsdl properly.

Not sure if you want to handle this in your lib, or it should be reported to php-soap ext team so they keep the streamContext header options clean...

mikaelcom commented 5 years ago

What you're talking about talks to me as I faced this issue for my unit tests. I loooked once if it was documented within the SoapClient changelog but I did not find anything.

So I think you're good to report an issue to the php-soap ext to be 100%of the origin of this issue. If you can report here the issue ticket, it would be great so I could be informed of its resolution (or not).

Thx

pculka commented 5 years ago

I have been thinking over this issue and the problem actually might be in your Base. I've made a PR to fix the issue: https://github.com/WsdlToPhp/PackageBase/pull/27

The problem is when you want to handle the headers as an array and not as a HTTP header field. HTTP Header field is mostly comprised of more lines, separated by a newline and that is correct within HTTP standard. "Connection" and "Authorization" are headers on its own. If you pass a request Connection: Close header, it does not trigger any problem. But passing a bad array as streamContext options results in an error. With my PR merged, the original issue should be resolved. I'm going to run the unit tests though.

jdreesen commented 4 years ago

I have the same problem and created a fix for it (based on the one from @pculka, thx!) in https://github.com/WsdlToPhp/PackageBase/pull/29.