Skip to content

Commit 0ff40c8

Browse files
Merge pull request #253 from postmanlabs/feature/TRUST-1965-soap-wsdl-import-fix
Fix target namespace prefix not getting applied properly in request body for WSDL imports
2 parents e543eb6 + 8c2af66 commit 0ff40c8

File tree

3 files changed

+94
-3
lines changed

3 files changed

+94
-3
lines changed

lib/utils/SOAPBody.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@ class SOAPBody {
107107
*/
108108
processMessageParent(messageParent, messageJSObject, createdJSOBjectReference, visitedElements) {
109109
const messageParentName = generatePrefixedElementName(messageParent),
110+
needsNsDeclaration = messageParent.nsPrefix && messageParentName.startsWith(messageParent.nsPrefix + ':'),
110111
tnsKey = `${this.parserAttributePlaceHolder}xmlns` +
111-
(messageParent.attributeFormDefault && messageParent.nsPrefix ? `:${messageParent.nsPrefix}` : '');
112+
(needsNsDeclaration ? `:${messageParent.nsPrefix}` : '');
112113

113114
if (messageParent.isComplex) {
114115
messageJSObject[messageParentName] = {};
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
3+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
4+
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
5+
xmlns:tns="http://www.dataaccess.com/webservicesserver/"
6+
name="TextCasing"
7+
targetNamespace="http://www.dataaccess.com/webservicesserver/">
8+
9+
<types>
10+
<xs:schema elementFormDefault="qualified"
11+
targetNamespace="http://www.dataaccess.com/webservicesserver/">
12+
<xs:element name="TitleCaseWordsWithToken">
13+
<xs:complexType>
14+
<xs:sequence>
15+
<xs:element name="sText" type="xs:string"/>
16+
<xs:element name="sToken" type="xs:string"/>
17+
</xs:sequence>
18+
</xs:complexType>
19+
</xs:element>
20+
<xs:element name="TitleCaseWordsWithTokenResponse">
21+
<xs:complexType>
22+
<xs:sequence>
23+
<xs:element name="TitleCaseWordsWithTokenResult" type="xs:string"/>
24+
</xs:sequence>
25+
</xs:complexType>
26+
</xs:element>
27+
</xs:schema>
28+
</types>
29+
30+
<message name="TitleCaseWordsWithTokenSoapRequest">
31+
<part name="parameters" element="tns:TitleCaseWordsWithToken"/>
32+
</message>
33+
34+
<message name="TitleCaseWordsWithTokenSoapResponse">
35+
<part name="parameters" element="tns:TitleCaseWordsWithTokenResponse"/>
36+
</message>
37+
38+
<portType name="TextCasingSoapType">
39+
<operation name="TitleCaseWordsWithToken">
40+
<input message="tns:TitleCaseWordsWithTokenSoapRequest"/>
41+
<output message="tns:TitleCaseWordsWithTokenSoapResponse"/>
42+
</operation>
43+
</portType>
44+
45+
<binding name="TextCasingSoapBinding" type="tns:TextCasingSoapType">
46+
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
47+
<operation name="TitleCaseWordsWithToken">
48+
<soap:operation soapAction="" style="document"/>
49+
<input>
50+
<soap:body use="literal"/>
51+
</input>
52+
<output>
53+
<soap:body use="literal"/>
54+
</output>
55+
</operation>
56+
</binding>
57+
58+
<service name="TextCasing">
59+
<port name="TextCasingSoap" binding="tns:TextCasingSoapBinding">
60+
<soap:address location="{{TextCasingSoapBaseUrl}}/webservicesserver/TextCasing.wso"/>
61+
</port>
62+
</service>
63+
</definitions>

test/unit/SchemaPack.test.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,13 +389,13 @@ describe('SchemaPack convert unit test WSDL 1.1 with options', function () {
389389
expectedOutput = `<?xml version=\"1.0\" encoding=\"utf-8\"?>
390390
<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">
391391
<soap:Header>
392-
<tns:AuthHeader xmlns=\"http://localhost/App.asmx\" CultureName=\"string\">
392+
<tns:AuthHeader xmlns:tns=\"http://localhost/App.asmx\" CultureName=\"string\">
393393
<tns:UserName>string</tns:UserName>
394394
<tns:Password>string</tns:Password>
395395
</tns:AuthHeader>
396396
</soap:Header>
397397
<soap:Body>
398-
<tns:ChangePassword xmlns=\"http://localhost/App.asmx\">
398+
<tns:ChangePassword xmlns:tns=\"http://localhost/App.asmx\">
399399
<tns:userName>string</tns:userName>
400400
<tns:password>string</tns:password>
401401
<tns:oldPassword>string</tns:oldPassword>
@@ -412,6 +412,33 @@ describe('SchemaPack convert unit test WSDL 1.1 with options', function () {
412412
.to.equal(removeLineBreakTabsSpaces(expectedOutput));
413413
});
414414
});
415+
416+
it('[Github #13300] - Should add proper namespace prefix to body element in request', function() {
417+
let fileContent = fs.readFileSync(validWSDLs + '/targetNamespacePrefix.wsdl', 'utf8');
418+
419+
const schema = new SchemaPack({
420+
data: fileContent,
421+
type: 'string'
422+
}, {}),
423+
expectedOutput = `<?xml version="1.0" encoding="utf-8"?>
424+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
425+
<soap:Body>
426+
<tns:TitleCaseWordsWithToken xmlns:tns="http://www.dataaccess.com/webservicesserver/">
427+
<tns:sText>string</tns:sText>
428+
<tns:sToken>string</tns:sToken>
429+
</tns:TitleCaseWordsWithToken>
430+
</soap:Body>
431+
</soap:Envelope>`;
432+
433+
schema.convert((error, result) => {
434+
expect(error).to.be.null;
435+
expect(result).to.be.an('object');
436+
expect(result.output[0].data.item).to.have.lengthOf(1);
437+
expect(result.output[0].data.item[0].name).to.eql('TitleCaseWordsWithToken');
438+
expect(removeLineBreakTabsSpaces(result.output[0].data.item[0].request.body.raw))
439+
.to.equal(removeLineBreakTabsSpaces(expectedOutput));
440+
});
441+
});
415442
});
416443

417444
describe('SchemaPack convert unit test WSDL 2.0', function () {

0 commit comments

Comments
 (0)