@@ -706,4 +706,154 @@ describe('SOAP Server with Options', function () {
706706 } ) ;
707707 } ) ;
708708 } ) ;
709+
710+ it ( 'should return soapenv as envelope key when it is set to soapenv' , function ( done ) {
711+ var responseData =
712+ '<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://example.com/stockquote.wsdl" xmlns:xsd1="http://example.com/stockquote.xsd"><soapenv:Body><xsd1:TradePrice xmlns:xsd1="http://example.com/stockquote.xsd"><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns3:UpdateProfileResponse xmlns:ns3="http://www.bigdatacollect.or/Name/Types" xmlns="http://www.bigdatacollect.or/Common/Types"><ns3:Result resultStatusFlag="SUCCESS"><IDs><UniqueID source="TESTSOURCE">100</UniqueID></IDs></ns3:Result></ns3:UpdateProfileResponse></S:Body></S:Envelope></xsd1:TradePrice></soapenv:Body></soapenv:Envelope>' ;
713+ test . server . listen ( 15099 , null , null , function ( ) {
714+ test . soapServer = soap . listen (
715+ test . server ,
716+ {
717+ path : '/stockquote' ,
718+ services : test . service ,
719+ xml : test . wsdl ,
720+ uri : __dirname + '/wsdl/strict/' ,
721+ useEmptyTag : true ,
722+ escapeXML : false ,
723+ envelopeKey : 'soapenv' ,
724+ } ,
725+ test . service ,
726+ test . wsdl ,
727+ ) ;
728+ test . baseUrl = 'http://' + test . server . address ( ) . address + ':' + test . server . address ( ) . port ;
729+
730+ // windows return 0.0.0.0 as address and that is not valid to use in a request
731+ if ( test . server . address ( ) . address === '0.0.0.0' || test . server . address ( ) . address === '::' ) {
732+ test . baseUrl = 'http://127.0.0.1:' + test . server . address ( ) . port ;
733+ }
734+
735+ soap . createClient ( test . baseUrl + '/stockquote?wsdl' , function ( err , client ) {
736+ assert . ifError ( err ) ;
737+ client . GetLastTradePrice ( { tickerSymbol : 'xml response' } , function ( err , response , body ) {
738+ assert . ifError ( err ) ;
739+ assert . strictEqual ( body , responseData ) ;
740+ done ( ) ;
741+ } ) ;
742+ } ) ;
743+ } ) ;
744+ } ) ;
745+
746+ it ( 'should return soap as envelope key by default' , function ( done ) {
747+ var responseData =
748+ '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://example.com/stockquote.wsdl" xmlns:xsd1="http://example.com/stockquote.xsd"><soap:Body><xsd1:TradePrice xmlns:xsd1="http://example.com/stockquote.xsd"><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns3:UpdateProfileResponse xmlns:ns3="http://www.bigdatacollect.or/Name/Types" xmlns="http://www.bigdatacollect.or/Common/Types"><ns3:Result resultStatusFlag="SUCCESS"><IDs><UniqueID source="TESTSOURCE">100</UniqueID></IDs></ns3:Result></ns3:UpdateProfileResponse></S:Body></S:Envelope></xsd1:TradePrice></soap:Body></soap:Envelope>' ;
749+ test . server . listen ( 15099 , null , null , function ( ) {
750+ test . soapServer = soap . listen (
751+ test . server ,
752+ {
753+ path : '/stockquote' ,
754+ services : test . service ,
755+ xml : test . wsdl ,
756+ uri : __dirname + '/wsdl/strict/' ,
757+ useEmptyTag : true ,
758+ escapeXML : false ,
759+ } ,
760+ test . service ,
761+ test . wsdl ,
762+ ) ;
763+ test . baseUrl = 'http://' + test . server . address ( ) . address + ':' + test . server . address ( ) . port ;
764+
765+ // windows return 0.0.0.0 as address and that is not valid to use in a request
766+ if ( test . server . address ( ) . address === '0.0.0.0' || test . server . address ( ) . address === '::' ) {
767+ test . baseUrl = 'http://127.0.0.1:' + test . server . address ( ) . port ;
768+ }
769+
770+ soap . createClient ( test . baseUrl + '/stockquote?wsdl' , { envelopeKey : 'soapenv' } , function ( err , client ) {
771+ assert . ifError ( err ) ;
772+ client . GetLastTradePrice ( { tickerSymbol : 'xml response' } , function ( err , response , body ) {
773+ console . log ( response ) ;
774+ assert . ifError ( err ) ;
775+ assert . strictEqual ( body , responseData ) ;
776+ done ( ) ;
777+ } ) ;
778+ } ) ;
779+ } ) ;
780+ } ) ;
781+
782+ it ( 'should return soapenv:Fault in soapenv as envelope key when it is set to soapenv' , function ( done ) {
783+ test . server . listen ( 15099 , null , null , function ( ) {
784+ test . soapServer = soap . listen (
785+ test . server ,
786+ {
787+ path : '/stockquote' ,
788+ services : test . service ,
789+ xml : test . wsdl ,
790+ uri : __dirname + '/wsdl/strict/' ,
791+ useEmptyTag : true ,
792+ envelopeKey : 'soapenv' ,
793+ } ,
794+ test . service ,
795+ test . wsdl ,
796+ ) ;
797+ test . baseUrl = 'http://' + test . server . address ( ) . address + ':' + test . server . address ( ) . port ;
798+
799+ // windows return 0.0.0.0 as address and that is not valid to use in a request
800+ if ( test . server . address ( ) . address === '0.0.0.0' || test . server . address ( ) . address === '::' ) {
801+ test . baseUrl = 'http://127.0.0.1:' + test . server . address ( ) . port ;
802+ }
803+
804+ axios
805+ . post (
806+ test . baseUrl + '/stockquote' ,
807+ '<soapenv:Envelope' + ' xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"' + ' xmlns:soap="http://service.applicationsnet.com/soap/">' + ' <soapenv:Header/>' + ' <soapenv:Body/>' + '</soapenv:Envelope>' ,
808+ )
809+ . then ( ( res ) => {
810+ // should not go this path, will fail by timeout
811+ } )
812+ . catch ( ( err ) => {
813+ assert . equal ( err . response . status , 500 ) ;
814+ assert . ok ( err . response . data . indexOf ( 'soapenv:Envelope' ) !== - 1 ) ;
815+ assert . ok ( err . response . data . indexOf ( 'soapenv:Fault' ) !== - 1 ) ;
816+ done ( ) ;
817+ } ) ;
818+ } ) ;
819+ } ) ;
820+
821+ it ( 'should return soap:Fault in soap as envelope key by default' , function ( done ) {
822+ test . server . listen ( 15099 , null , null , function ( ) {
823+ test . soapServer = soap . listen (
824+ test . server ,
825+ {
826+ path : '/stockquote' ,
827+ services : test . service ,
828+ xml : test . wsdl ,
829+ uri : __dirname + '/wsdl/strict/' ,
830+ useEmptyTag : true ,
831+ forceSoap12Headers : true ,
832+ } ,
833+ test . service ,
834+ test . wsdl ,
835+ ) ;
836+ test . baseUrl = 'http://' + test . server . address ( ) . address + ':' + test . server . address ( ) . port ;
837+
838+ // windows return 0.0.0.0 as address and that is not valid to use in a request
839+ if ( test . server . address ( ) . address === '0.0.0.0' || test . server . address ( ) . address === '::' ) {
840+ test . baseUrl = 'http://127.0.0.1:' + test . server . address ( ) . port ;
841+ }
842+
843+ axios
844+ . post (
845+ test . baseUrl + '/stockquote' ,
846+ '<soapenv:Envelope' + ' xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"' + ' xmlns:soap="http://service.applicationsnet.com/soap/">' + ' <soapenv:Header/>' + ' <soapenv:Body/>' + '</soapenv:Envelope>' ,
847+ )
848+ . then ( ( res ) => {
849+ // should not go this path, will fail by timeout
850+ } )
851+ . catch ( ( err ) => {
852+ assert . equal ( err . response . status , 500 ) ;
853+ assert . ok ( err . response . data . indexOf ( 'soap:Envelope' ) !== - 1 ) ;
854+ assert . ok ( err . response . data . indexOf ( 'soap:Fault' ) !== - 1 ) ;
855+ done ( ) ;
856+ } ) ;
857+ } ) ;
858+ } ) ;
709859} ) ;
0 commit comments