Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/vpulim/node-soap into nam…
Browse files Browse the repository at this point in the history
…espace-redefined-in-element
  • Loading branch information
lah8789 committed Oct 7, 2021
2 parents cfb4497 + 927b3cb commit 8fe8cee
Show file tree
Hide file tree
Showing 26 changed files with 831 additions and 548 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: PR Build
on: pull_request
jobs:
code-quality:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: lts/*
- run: npm ci
- run: npm run lint
- run: npm run cover


23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

14 changes: 14 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
0.42.0 / 2021-08-23
===================
* [FIX] check method style if exists instead of binding style (#1153)
* [FIX] update dependency vuln in xmldom via xml-cryoto/xmldom update (#1157)
* [FIX] update 7 vulnerabilities in the dependency chain (#1156)
* [FIX] SOAP faults are no longer being passed back in the error callback/promise rejection (#1155)

0.41.0 / 2021-08-20
===================
* [ENHANCEMENT] Support for soap attachments in response. (#1148)
* [FIX] Correctly add the https agent to axios (#1154)
* [FIX] prefer SOAPAction header over the body name to get the actual method name (#1152)
* [MAINTENANCE] Moving to github actions

0.40.0 / 2021-07-06
===================
* [DOC] Update Readme.md (#1150)
Expand Down
5 changes: 5 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Security Policy

## Reporting a Vulnerability

Please report security issues to <email>
786 changes: 377 additions & 409 deletions package-lock.json

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"name": "soap",
"version": "0.40.0",
"version": "0.42.0",
"description": "A minimal node SOAP client",
"engines": {
"node": ">=10.0.0"
},
"author": "Vinay Pulim <[email protected]>",
"dependencies": {
"axios": "^0.21.1",
"axios-ntlm": "^1.1.6",
"axios-ntlm": "^1.1.7",
"content-type-parser": "^1.0.2",
"debug": "^4.3.1",
"debug": "^4.3.2",
"formidable": "^1.2.2",
"get-stream": "^6.0.1",
"httpntlm": "^1.5.2",
"httpntlm": "^1.7.7",
"lodash": "^4.17.21",
"sax": ">=0.6",
"strip-bom": "^3.0.0",
"uuid": "^8.3.2",
"xml-crypto": "^2.1.0"
"xml-crypto": "^2.1.3"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -47,23 +47,23 @@
],
"license": "MIT",
"devDependencies": {
"@types/debug": "^4.1.2",
"@types/express": "^4.16.1",
"@types/lodash": "^4.14.169",
"@types/debug": "^4.1.7",
"@types/express": "^4.17.13",
"@types/lodash": "^4.14.172",
"@types/node": "^11.15.54",
"@types/request": "^2.48.1",
"@types/sax": "^1.0.1",
"@types/uuid": "^8.3.0",
"@types/request": "^2.48.7",
"@types/sax": "^1.2.3",
"@types/uuid": "^8.3.1",
"body-parser": "^1.15.2",
"colors": "^1.3.3",
"coveralls": "^3.0.5",
"coveralls": "^3.1.1",
"diff": "^4.0.1",
"doctoc": "^1.4.0",
"doctoc": "^2.0.1",
"duplexer": "~0.1.1",
"express": "^4.16.4",
"finalhandler": "^1.1.1",
"glob": "^7.1.7",
"jshint": "^2.10.1",
"jshint": "^2.13.1",
"mocha": "^6.1.4",
"nyc": "^14.1.1",
"readable-stream": "~2.0.2",
Expand All @@ -74,7 +74,7 @@
"source-map-support": "^0.5.10",
"timekeeper": "^2.1.2",
"tslint": "^5.18.0",
"typedoc": "^0.20.36",
"typescript": "^3.3.3333"
"typedoc": "^0.20.37",
"typescript": "^3.9.10"
}
}
3 changes: 2 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,11 +549,12 @@ export class Client extends EventEmitter {
return;
}

const startTime = Date.now();
return this.httpClient.request(location, xml, (err, response, body) => {
this.lastResponse = body;
if (response) {
this.lastResponseHeaders = response.headers;
this.lastElapsedTime = response.headers.date;
this.lastElapsedTime = Date.now() - startTime;
this.lastResponseAttachments = response.mtomResponseAttachments;
// Added mostly for testability, but possibly useful for debugging
this.lastRequestHeaders = response.config && response.config.headers;
Expand Down
2 changes: 2 additions & 0 deletions src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ export class HttpClient implements IHttpClient {
url: curl.href,
method: method,
headers: headers,
validateStatus: null,
transformResponse: (data) => data,
};

if (exoptions.forceMTOM || attachments.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/security/ClientSSLSecurity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@ export class ClientSSLSecurity implements ISecurity {
httpsAgent = new https.Agent(options);
}

options.agent = httpsAgent;
options.httpsAgent = httpsAgent;
}
}
2 changes: 1 addition & 1 deletion src/security/ClientSSLSecurityPFX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ export class ClientSSLSecurityPFX implements ISecurity {
options.passphrase = this.passphrase;
}
_.merge(options, this.defaults);
options.agent = new https.Agent(options);
options.httpsAgent = new https.Agent(options);
}
}
65 changes: 40 additions & 25 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,13 @@ export class Server extends EventEmitter {
}
}

private _getSoapAction(req: Request) {
const soapAction: string = req.headers.soapaction as string;
return (soapAction.indexOf('"') === 0)
? soapAction.slice(1, -1)
: soapAction;
}

private _process(input, req: Request, res: Response, cb: (result: any, statusCode?: number) => any) {
const pathname = url.parse(req.url).pathname.replace(/\/$/, '');
const obj = this.wsdl.xmlToObject(input);
Expand Down Expand Up @@ -349,38 +356,37 @@ export class Server extends EventEmitter {
}

try {
if (binding.style === 'rpc') {
methodName = (Object.keys(body)[0] === 'attributes' ? Object.keys(body)[1] : Object.keys(body)[0]);
const soapAction = this._getSoapAction(req);
const messageElemName = (Object.keys(body)[0] === 'attributes' ? Object.keys(body)[1] : Object.keys(body)[0]);
const pair = binding.topElements[messageElemName];
if (soapAction) {
methodName = this._getMethodNameBySoapAction(binding, soapAction);
} else {
methodName = pair ? pair.methodName : messageElemName;
}
/** Style can be defined in method. If method has no style then look in binding */
const style = binding.methods[methodName].style || binding.style;

this.emit('request', obj, methodName);
if (headers) {
this.emit('headers', headers, methodName);
}
this.emit('request', obj, methodName);
if (headers) {
this.emit('headers', headers, methodName);
}

if (style === 'rpc') {
this._executeMethod({
serviceName: serviceName,
portName: portName,
methodName: methodName,
outputName: methodName + 'Response',
args: body[methodName],
outputName: messageElemName + 'Response',
args: body[messageElemName],
headers: headers,
style: 'rpc',
}, req, res, callback);
} else {
const messageElemName = (Object.keys(body)[0] === 'attributes' ? Object.keys(body)[1] : Object.keys(body)[0]);
const pair = binding.topElements[messageElemName];

this.emit('request', obj, pair.methodName);
if (headers) {
this.emit('headers', headers, pair.methodName);
}

methodName = pair.methodName;

this._executeMethod({
serviceName: serviceName,
portName: portName,
methodName: pair.methodName,
methodName: methodName,
outputName: pair.outputName,
args: body[messageElemName],
headers: headers,
Expand Down Expand Up @@ -410,7 +416,7 @@ export class Server extends EventEmitter {
return this._sendError({
Code: {
Value: 'SOAP-ENV:Server',
Subcode: { value: 'InternalServerError' },
Subcode: { Value: 'InternalServerError' },
},
Reason: { Text: authResult.toString() },
statusCode: 500,
Expand All @@ -429,7 +435,7 @@ export class Server extends EventEmitter {
return this._sendError({
Code: {
Value: 'SOAP-ENV:Server',
Subcode: { value: 'InternalServerError' },
Subcode: { Value: 'InternalServerError' },
},
Reason: { Text: error.toString() },
statusCode: 500,
Expand All @@ -439,7 +445,7 @@ export class Server extends EventEmitter {
return this._sendError({
Code: {
Value: 'SOAP-ENV:Client',
Subcode: { value: 'AuthenticationFailure' },
Subcode: { Value: 'AuthenticationFailure' },
},
Reason: { Text: 'Invalid username or password' },
statusCode: 401,
Expand All @@ -464,6 +470,14 @@ export class Server extends EventEmitter {
}
}

private _getMethodNameBySoapAction(binding: BindingElement, soapAction: string) {
for (const methodName in binding.methods) {
if (binding.methods[methodName].soapAction === soapAction) {
return methodName;
}
}
}

private _executeMethod(
options: IExecuteMethodOptions,
req: Request,
Expand All @@ -477,6 +491,7 @@ export class Server extends EventEmitter {
let headers;
const serviceName = options.serviceName;
const portName = options.portName;
const binding = this.wsdl.definitions.services[serviceName].ports[portName].binding;
const methodName = options.methodName;
const outputName = options.outputName;
const args = options.args;
Expand Down Expand Up @@ -512,7 +527,7 @@ export class Server extends EventEmitter {
return this._sendError({
Code: {
Value: 'SOAP-ENV:Server',
Subcode: { value: 'InternalServerError' },
Subcode: { Value: 'InternalServerError' },
},
Reason: { Text: error.toString() },
statusCode: 500,
Expand All @@ -523,13 +538,13 @@ export class Server extends EventEmitter {
if (style === 'rpc') {
body = this.wsdl.objectToRpcXML(outputName, result, '', this.wsdl.definitions.$targetNamespace);
} else {
const element = this.wsdl.definitions.services[serviceName].ports[portName].binding.methods[methodName].output;
const element = binding.methods[methodName].output;
body = this.wsdl.objectToDocumentXML(outputName, result, element.targetNSAlias, element.targetNamespace);
}
callback(this._envelope(body, headers, includeTimestamp));
};

if (!this.wsdl.definitions.services[serviceName].ports[portName].binding.methods[methodName].output) {
if (!binding.methods[methodName].output) {
// no output defined = one-way operation so return empty response
handled = true;
body = '';
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export interface ISoapFault11 {
// Role, Node, Detail. Should be added when soap module implements them
// https://www.w3.org/TR/soap12/#soapfault
export interface ISoapFault12 {
Code: { Value: string; Subcode?: { value: string; }; };
Code: { Value: string; Subcode?: { Value: string; }; };
Reason: { Text: string; };
statusCode?: number;
}
Expand Down
2 changes: 1 addition & 1 deletion src/wsdl/elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ export class TypesElement extends Element {
public addChild(child) {
assert(child instanceof SchemaElement);

const targetNamespace = child.$targetNamespace;
const targetNamespace = child.$targetNamespace || child.includes[0]?.namespace;

if (!this.schemas.hasOwnProperty(targetNamespace)) {
this.schemas[targetNamespace] = child;
Expand Down
Loading

0 comments on commit 8fe8cee

Please sign in to comment.