How to replace soap xml tag value dynamically using cypress - soap

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2003/06/secext">
<wsse:UsernameToken>
<wsse:Username>abc</wsse:Username>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
In this xml I want to replace the value of wsse:Username to "XYZ" from abc dynamically using cypress ? How to do it ?

Related

Netsuite get list of files inside a folder using soap webservice

I am actually trying to get a list of files(or their internalId's) inside a folder using soap webservice from netsuite file cabinet
I am using the following request to make a search request
<soapenv:Header>
<urn:tokenPassport>
<urn1:account xmlns:urn1="urn:core_2020_2.platform.webservices.netsuite.com">*****</urn1:account>
<urn1:consumerKey xmlns:urn1="urn:core_2020_2.platform.webservices.netsuite.com">*****</urn1:consumerKey>
<urn1:token xmlns:urn1="urn:core_2020_2.platform.webservices.netsuite.com">*****</urn1:token>
<urn1:nonce xmlns:urn1="urn:core_2020_2.platform.webservices.netsuite.com">*****</urn1:nonce>
<urn1:timestamp xmlns:urn1="urn:core_2020_2.platform.webservices.netsuite.com">*****</urn1:timestamp>
<urn1:signature algorithm="HMAC-SHA256" xmlns:urn1="urn:core_2020_2.platform.webservices.netsuite.com">*****</urn1:signature>
</urn:tokenPassport>
</soapenv:Header>
<soapenv:Body>
<search xmlns="urn:messages_2020_2.platform.webservices.netsuite.com">
<searchRecord type="FileSearchBasic" xmlns="urn:common_2020_2.platform.webservices.netsuite.com">
<folder type="SearchMultiSelectField" internalId="2760"/>
</searchRecord>
</search>
</soapenv:Body>
However its giving error following error
<faultcode>soapenv:Server.userException</faultcode>
<faultstring>org.xml.sax.SAXException: {urn:core_2020_2.platform.webservices.netsuite.com}SearchRecord is an abstract type and cannot be instantiated</faultstring>
after a lot of research I was able to make a successful soap request to get list of files inside a folder, following is the request body
<soap:Body>
<platformMsgs:search>
<platformMsgs:searchRecord xmlns:s0="urn:filecabinet_2020_2.documents.webservices.netsuite.com" xsi:type="s0:FolderSearchAdvanced">
<s0:criteria>
<s0:basic>
<internalId operator="anyOf">
<searchValue internalId="2760" type="folder" />
</internalId>
</s0:basic>
</s0:criteria>
<s0:columns>
<s0:basic>
<internalId/>
<name/>
</s0:basic>
<fileJoin>
<internalId/>
<name/>
<modified/>
<documentSize/>
</fileJoin>
</s0:columns>
</platformMsgs:searchRecord>
</platformMsgs:search>
</soap:Body>

SharePoint 2010 get all the files and folders recursively

Post: http://******.com/_vti_bin/SiteData.asmx
SOAPAction:
http://schemas.microsoft.com/sharepoint/soap/GetListCollection
request:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetListCollection xmlns="http://schemas.microsoft.com/sharepoint/soap/" />
</soap:Body>
</soap:Envelope>
Using above i get a list of all the top level folders/lists available
After getting all the top level folders using the same information i want to get all the lower level folders and their files using soap requests.
What i have tried is:
Post: http://******.com/_vti_bin/Lists.asmx
Soapaction:
http://schemas.microsoft.com/sharepoint/soap/GetListItems
Request:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<listName>test1</listName>
<QueryOptions>
<IncludeMandatoryColumns>TRUE</IncludeMandatoryColumns>
<ViewAttributes Scope="RecursiveAll"/>
<DateInUtc>TRUE</DateInUtc>
</QueryOptions>
</GetListItems>
</soap:Body>
</soap:Envelope>
which should have returned all the folders and sub folders inside listname test1.
But again it returned only top level files and folders.
What expected is: to return all the files and folders recursively under list test1
Thanks in advance

SOAP request - what is digested for a signature?

A quick question bothering me for months now..
When one is sending a SOAP request (using SoapUI or not) and signing it with private key. WHAT exactly is digested for the signature?
Whichever part of the referenced object in the request I take for sha1 digestion I get a different value than the one SoapUI generates. Tried googling arround but couldn't find a decent article clearly explaining what part of the ref'ed object is digested for signature.
pc-04 ~ $ nc -l 0.0.0.0 5588
POST / HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "urn:[_renamed_]:v1/sendMessage"
Content-Length: 2418
Host: localhost:5588
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:[_renamed_]:schema:v1">
<soapenv:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><ds:Signature Id="SIG-927771137712DBCACC150572539981324" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><ec:InclusiveNamespaces PrefixList="soapenv urn" xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"/></ds:CanonicalizationMethod><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><ds:Reference URI="#id-927771137712DBCACC150572539981023"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><ec:InclusiveNamespaces PrefixList="urn" xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"/></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue>40g3y73kx2NLAk+RtE7A6XYQfq0=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>RNusKNwPvnzII/DZo2nkK8i/xDkq5bSjoZ+vW+BBv7jwoatosim7wjm5JiZGHjfGo1wnJNTA1nTn
/U6sjQZZvtNSuDKHcaY5FphluMYkn5fKSt8JvDsqH+dgNr3w6GMFshDimoIjG3/Opt0rUw7Mgi/x
cUYx95VqYPX20/SQ5MY=</ds:SignatureValue><ds:KeyInfo Id="KI-927771137712DBCACC150572539981021"><wsse:SecurityTokenReference wsu:Id="STR-927771137712DBCACC150572539981022"><ds:X509Data><ds:X509IssuerSerial><ds:X509IssuerName>1.2.840.113549.1.9.1=#161c72696361726461732e62756369756e6173406e6f7274616c2e636f6d,CN=[_renamed_],O=[_renamed_] UAB,L=[_renamed_],ST=[_renamed_],C=LT</ds:X509IssuerName><ds:X509SerialNumber>10598525849934796037</ds:X509SerialNumber></ds:X509IssuerSerial></ds:X509Data></wsse:SecurityTokenReference></ds:KeyInfo></ds:Signature></wsse:Security>
<urn:requestHeader>
<!--Optional:-->
<headtag1>
<inbox>?</inbox>
</headtag1>
</urn:requestHeader>
</soapenv:Header>
<soapenv:Body wsu:Id="id-927771137712DBCACC150572539981023" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<urn:message>
<name>Andrew</name>
<lname>Hopkins</lname>
<username>andhop335</username>
</urn:message>
</soapenv:Body>
</soapenv:Envelope>pc-04 ~ $
pc-04 ~ $
How does SoapUI get that digest?
pc-045 ~ $ echo 40g3y73kx2NLAk+RtE7A6XYQfq0= | base64 -d | xxd -p
e34837cbbde4c7634b024f91b44ec0e976107ead
The question is unanswered for some days but I am sticking at some other problems with that.
So, the digest is calculated over the part (object) in your xml which is referenced by attribute in the reference object:
<ds:Reference URI="#id-927771137712DBCACC150572539981023">
The object to sign is so referenced by "id-927771137712DBCACC150572539981023" (without the #):
<soapenv:Body wsu:Id="id-927771137712DBCACC150572539981023" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
In this case, the content of soapenv:Body has to be digested AFTER canonilization, it has been processed (transformed) by c14n, which is stated in:
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
For further Infos take a look here:
https://www.w3.org/TR/xmldsig-core/#sec-ReferenceProcessingModel
https://www.w3.org/TR/2001/NOTE-SOAP-dsig-20010206/#XML-Signature
https://www.w3.org/TR/xmldsig-core/#sec-TransformAlg

Perl - SOAP::Lite request not setting xmlns:soap with correct value on Axis2

I've just created a webservice client in Perl using SOAP::Lite.
I manage to invoke a method of my webservice quite easily, but for some unknown reasons, it works sometimes, and sometimes it won't work.
Here's my perl client code :
my $client = SOAP::Lite->uri("http://loa.webservice")
->service("http://localhost:8888/LogAnalyzerWS/services/DataReceiver?wsdl");
my $res;
do {
sleep(2);
print ("ok \n");
$res = $client->sendData($data);
}while(!defined $res);
print $res, "\n";
I tried to add a while loop to resend the data if the result is undefined, but it won't work.
After some analysis of SOAP::Lite trace log file, I found that during the request, one parameter changes.
Here's the correct xml soap request :
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ax21="http://metier.loa/xsd" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:ns="http://webservice.loa" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<ns:sendData>
<element xsi:type="xs:base64Binary">PD94bWwgdmVyc2lvbj0</element>
</ns:sendData>
</soap:Body>
</soap:Envelope>
And the correct answer :
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns:sendDataResponse xmlns:ns="http://webservice.loa">
<ns:return>1</ns:return>
</ns:sendDataResponse>
</soapenv:Body>
</soapenv:Envelope>
And here's the faulty xml request :
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ax21="http://metier.loa/xsd" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:ns="http://webservice.loa" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<ns:sendData>
<element xsi:type="xs:base64Binary">PD94bWwgdmVyc2lvbj0</element>
</ns:sendData>
</soap:Body>
</soap:Envelope>
With the answer :
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:Action>http://www.w3.org/2005/08/addressing/soap/fault</wsa:Action>
</soapenv:Header>
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:VersionMismatch</faultcode>
<faultstring>Only SOAP 1.1 or SOAP 1.2 messages are supported in the system</faultstring>
<detail />
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
As you can see, xmlns:soap hasn't got the same value in the correct and the faulty request : for the correct one, it is :
"http://schemas.xmlsoap.org/soap/envelope/"
And for the faulty one, it is :
"http://schemas.xmlsoap.org/wsdl/soap/"
Any ideas why SOAP::Lite is changing this parameter on it's own ?
The problem comes from the way namespaces are handled in SOAP::Lite.
See this issue on RT cpan. Axis 2 was generating a wsdl which was then parsed by SOAP::Lite, and the value of xmlns:soap from the hash, set by the SOAP::Lite::Serializer, was wrongly being modified by the parsing of the wsdl.
To solve this problem, use this at the very begining of your code (before setting the wsdl in SOAP::Lite) :
$SOAP::Constants::PREFIX_ENV = 'SOAP-ENV';
Also one can use method envprefix:
$client->envprefix('SOAP-ENV');
This code works for me:
use SOAP::Lite +trace => [ qw(debug) ]; # to get all logging without transport messages
my $service = SOAP::Lite->service('https://www.cbr.ru/DailyInfoWebServ/DailyInfo.asmx?WSDL');
$service->soapversion('1.1');
$service->readable(1);
$service->envprefix('SOAP-ENV');
$service->bodyattr({ xmlns => 'http://web.cbr.ru/' });
my $result = $service->GetCursOnDate('2021-02-05T00:00:00');

Datapower Soap Envelope Header Values from Request

I am having a WS Proxy in Datapower . Both the client and the backends are HTTP . My request contains a soap header that has values like :
wsa:Action
wsa:MessageID
wsa:ReplyTo
timestamp
The backend doesnt require all these values , so they are stripped of before sending a cnverted request to the backend and obviously these are not there in the response which I get back from backend. Now when I send a response back to the client from Datapower , I need all these values back in the response soap headers . A
newly created timestamp which expires after 5 mins .
Action
MessageID
ReplyTo
Is there any way to put them back. I dont want to do it from xslt , as I beleive there is some inbuilt support from Datapower to handle this .
I would just store the entire SOAP-header node-set in a context variable and replace it in the response rule. Unless, of course the back-end adds or modifies specific values. In that case, you can pick and choose what to restore.
Please find below code tp remove header and to move it to context variable .
Further you can use that context variable values to place it back.
XSl1 : To save username and password into context variable`
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dp="http://www.datapower.com/extensions"
xmlns:dpconfig="http://www.datapower.com/param/config"
extension-element-prefixes="dp date dpconfig" exclude-result-prefixes=" dp dpconfig ">
<xsl:template match="/">
<xsl:variable name = "User">
<xsl:value-of select="/*[local-name()='Envelope']/*[local-name()='Header']/*[local-name()='Security']/*[local-name()='UsernameToken']/*[local-name()='Username']/text()"/>
</xsl:variable>
<xsl:variable name = "PWD">
<xsl:value-of select="/*[local-name()='Envelope']/*[local-name()='Header']/*[local-name()='Security']/*[local-name()='UsernameToken']/*[local-name()='Password']/text()"/>
</xsl:variable>
<xsl:message dp:priority="debug">
User name : <xsl:value-of select="$User"/>
<xsl:message dp:priority="debug">
Password : <xsl:value-of select="$PWD"/>
</xsl:message>
<dp:set-variable name="'var://context/Test/User'" value ="string($User)"/>
<dp:set-variable name="'var://context/Test/Pws'" value ="string($PWD)"/>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >
<soapenv:Header>
</soapenv:Header>
<soapenv:Body>
<xsl:copy-of select="/*[local-name()='Envelope']/*[local-name()='Body']/*" />
</soapenv:Body>
</soapenv:Envelope>
</xsl:template>
</xsl:stylesheet>
XSl2 :To add back the Username and Password back into SOAP .
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dp="http://www.datapower.com/extensions"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:dpconfig="http://www.datapower.com/param/config"
extension-element-prefixes="dp dpconfig soapenv" exclude-result-prefixes="dp dpconfig">
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match = "*[local-name() = 'Header']">
<soapenv:Header xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soap:appid xmlns:soap="http://na.az.com/soaplatform">?</soap:appid>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>
<xsl:value-of select="dp:variable('var://context/Test/User')"/>
</wsse:Username>
<wsse:Password>
<xsl:value-of select="dp:variable('var://context/Test/Pws')"/>
</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
</xsl:template>
</xsl:stylesheet>