Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

soap

Package Overview
Dependencies
Maintainers
1
Versions
97
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

soap - npm Package Compare versions

Comparing version 0.0.3 to 0.0.7

51

lib/client.js

@@ -6,9 +6,15 @@ /*

var http = require('./http');
var http = require('./http'),
assert = require('assert');
var Client = function(wsdl) {
this.wsdl = wsdl;
this._initializeServices();
this._initializeServices(null);
}
Client.prototype.setEndpoint = function(endpoint) {
this.endpoint = endpoint;
this._initializeServices(endpoint);
}
Client.prototype.describe = function() {

@@ -22,15 +28,15 @@ return this.wsdl.describeServices();

Client.prototype._initializeServices = function() {
Client.prototype._initializeServices = function(endpoint) {
var definitions = this.wsdl.definitions,
services = definitions.services;
for (var name in services) {
this[name] = this._defineService(services[name]);
this[name] = this._defineService(services[name], endpoint);
}
}
Client.prototype._defineService = function(service) {
Client.prototype._defineService = function(service, endpoint) {
var ports = service.ports,
def = {};
for (var name in ports) {
def[name] = this._definePort(ports[name]);
def[name] = this._definePort(ports[name], endpoint ? endpoint : ports[name].location);
}

@@ -40,4 +46,4 @@ return def;

Client.prototype._definePort = function(port) {
var location = port.location,
Client.prototype._definePort = function(port, endpoint) {
var location = endpoint,
binding = port.binding,

@@ -71,5 +77,7 @@ methods = binding.methods,

output = method.output,
style = method.style,
defs = this.wsdl.definitions,
ns = defs.$targetNamespace,
args = {},
encoding = '';
message = '';
xml = null,

@@ -81,4 +89,4 @@ headers = {

options = {};
// Allow the security object a change to add headers
// Allow the security object to add headers
if (self.security && self.security.addHeaders)

@@ -89,6 +97,15 @@ self.security.addHeaders(headers);

args[input.element.$name] = arguments;
if (input.element) {
assert.ok(style == 'document', 'invalid message definition for rpc style binding');
message = self.wsdl.objectToDocumentXML(input.element.$name, arguments);
}
else {
assert.ok(style == 'rpc', 'invalid message definition for document style binding');
message = self.wsdl.objectToRpcXML(name, arguments);
encoding = 'soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" ';
}
xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope " +
"xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
encoding +
"xmlns:ns0=\""+ns+"\">" +

@@ -99,7 +116,7 @@ "<soap:Header>" +

"<soap:Body>" +
self.wsdl.objectToXML(args) +
message +
"</soap:Body>" +
"</soap:Envelope>";
http.request(location, xml, function(err, response) {
http.request(location, xml, function(err, response, body) {
if (err) {

@@ -110,3 +127,3 @@ callback(err);

try {
var obj = self.wsdl.xmlToObject(response.body);
var obj = self.wsdl.xmlToObject(body);
callback(null, obj[output.$name]);

@@ -121,2 +138,2 @@ }

exports.Client = Client;
exports.Client = Client;

@@ -6,9 +6,5 @@ /*

var http = require('http'),
https = require('https'),
url = require('url'),
compress = null;
var url = require('url'),
req = require('request');
try { compress = require("compress"); } catch(e) {}
var VERSION = "0.0.1";

@@ -26,3 +22,3 @@

"Accept" : "text/html,application/xhtml+xml,application/xml",
"Accept-Encoding": compress ? "gzip,deflate" : "none",
"Accept-Encoding": "none",
"Accept-Charset": "utf-8",

@@ -42,8 +38,5 @@ "Connection": "close",

var options = {
host: host,
port: port,
uri: curl,
method: method,
path: path,
headers: headers,
agent: false
headers: headers
};

@@ -54,23 +47,8 @@

var request = (secure ? https : http).request(options);
request.on('response', function(res) {
var chunks = [], gunzip;
if (compress && res.headers["content-encoding"] == "gzip") {
gunzip = new compress.Gunzip;
gunzip.init();
var request = req(options, function (error, res, body) {
if (error) {
callback(error);
} else {
callback(null, res, body);
}
res.setEncoding(res.headers["content-encoding"] == "gzip" ? "binary" : "utf8");
res.on('data', function(chunk) {
if (gunzip) chunk = gunzip.inflate(chunk, "binary");
chunks.push(chunk);
});
res.on('end', function() {
res.body = chunks.join('');
if (gunzip) {
gunzip.end();
gunzip = null
}
callback(null, res);
});
res.on('error', callback);
});

@@ -80,1 +58,2 @@ request.on('error', callback);

}

@@ -10,3 +10,4 @@ /*

http = require('./http'),
fs = require('fs');
fs = require('fs'),
crypto = require('crypto');

@@ -33,3 +34,3 @@ var _wsdlCache = {};

else {
http.request(url, null, function(err, response) {
http.request(url, null /* options */, function(err, response, body) {
if (err) {

@@ -39,3 +40,3 @@ callback(err);

else if (response && response.statusCode == 200){
wsdl = new WSDL(response.body);
wsdl = new WSDL(body);
_wsdlCache[url] = wsdl;

@@ -62,2 +63,15 @@ callback(null, wsdl);

function BasicAuthSecurity(username, password) {
this._username = username;
this._password = password;
}
BasicAuthSecurity.prototype.addHeaders = function (headers) {
headers['Authorization'] = "Basic " + new Buffer((this._username + ':' + this._password) || '').toString('base64');
}
BasicAuthSecurity.prototype.toXML = function() {
return "";
}
function WSSecurity(username, password) {

@@ -69,6 +83,39 @@ this._username = username;

WSSecurity.prototype.toXML = function() {
return "<wsse:Security xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">" +
"<wsse:UsernameToken>" +
// avoid dependency on date formatting libraries
function getDate(d) {
function pad(n){return n<10 ? '0'+n : n}
return d.getUTCFullYear()+'-'
+ pad(d.getUTCMonth()+1)+'-'
+ pad(d.getUTCDate())+'T'
+ pad(d.getUTCHours())+':'
+ pad(d.getUTCMinutes())+':'
+ pad(d.getUTCSeconds())+'Z';
}
var now = new Date();
var created = getDate( now );
var expires = getDate( new Date(now.getTime() + (1000 * 600)) );
// nonce = base64 ( sha1 ( created + random ) )
var nHash = crypto.createHash('sha1');
nHash.update(created + Math.random());
var nonce = nHash.digest('base64');
// digest = base64 ( sha1 ( nonce + created + password ) )
var pwHash = crypto.createHash('sha1');
var rawNonce = new Buffer(nonce || '', 'base64').toString('utf8');
pwHash.update( rawNonce + created + this._password );
var passwordDigest = pwHash.digest('base64');
return "<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\">" +
"<wsu:Timestamp wsu:Id=\"Timestamp-"+created+"\">" +
"<wsu:Created>"+created+"</wsu:Created>" +
"<wsu:Expires>"+expires+"</wsu:Expires>" +
"</wsu:Timestamp>" +
"<wsse:UsernameToken xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" wsu:Id=\"SecurityToken-"+created+"\">" +
"<wsse:Username>"+this._username+"</wsse:Username>" +
//TODO:FIXME: reenable password hash
//"<wsse:Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest\">"+passwordDigest+"</wsse:Password>" +
"<wsse:Password>"+this._password+"</wsse:Password>" +
"<wsse:Nonce EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\">"+nonce+"</wsse:Nonce>" +
"<wsu:Created>"+created+"</wsu:Created>" +
"</wsse:UsernameToken>" +

@@ -78,4 +125,6 @@ "</wsse:Security>"

exports.BasicAuthSecurity = BasicAuthSecurity;
exports.WSSecurity = WSSecurity;
exports.createClient = createClient;
exports.listen = listen;

@@ -18,3 +18,3 @@ /*

function splitNSName(nsName) {
var i = nsName.indexOf(':');
var i = (nsName != null) ? nsName.indexOf(':') : -1;
return i < 0 ? {namespace:null,name:nsName} : {namespace:nsName.substring(0, i), name:nsName.substring(i+1)};

@@ -191,2 +191,3 @@ }

this.element = null;
this.parts = {};
}

@@ -200,7 +201,21 @@ inherits(MessageElement, Element);

assert(part.name === 'part', 'Expected part element');
var name = splitNSName(part.$element).name;
this.element = definitions.types[name];
if (part.$element) {
var name = splitNSName(part.$element).name;
this.element = definitions.types[name];
}
else {
// rpc encoding
for (var i=0, child; child = this.children[i]; i++) {
assert(part.name === 'part', 'Expected part element');
this.parts[part.$name] = part.$type;
}
}
}
MessageElement.prototype.description = function(definitions) {
return this.element && this.element.description(definitions);
if (this.element) {
return this.element && this.element.description(definitions);
}
var desc = {};
desc[this.$name] = this.parts;
return desc;
}

@@ -269,2 +284,3 @@

this.transport = null;
this.style = null;
this.methods = {};

@@ -283,2 +299,3 @@ }

this.transport = child.$transport;
this.style = child.$style;
}

@@ -288,6 +305,10 @@ }

var type = splitNSName(this.$type).name,
portType = definitions.portTypes[type];
portType = definitions.portTypes[type],
style = this.style;
portType.postProcess(definitions);
this.methods = portType.methods;
for (var name in this.methods) {
this.methods[name].style = style;
}
}

@@ -430,2 +451,7 @@ BindingElement.prototype.description = function(definitions) {

Envelope: {
Header: {
Security: {
UsernameToken: {
Username: 'string',
Password: 'string' }}},
Body: {

@@ -447,3 +473,3 @@ Fault: { faultcode: 'string', faultstring: 'string', detail: 'string' }}}},

}
if (topSchema && topSchema[name+'[]']) name = name + '[]';

@@ -508,2 +534,29 @@ stack.push({name: name, object: obj, schema: topSchema && topSchema[name]});

WSDL.prototype.objectToDocumentXML = function(name, params) {
var args = {};
args[name] = params;
return this.objectToXML(args);
}
WSDL.prototype.objectToRpcXML = function(name, params, namespace) {
var self = this,
parts = [],
namespace = namespace || 'ns0',
xmlns = xmlns || '',
nsAttrName = '_xmlns';
parts.push(['<',namespace,':',name,xmlns,'>'].join(''));
for (var key in params) {
if (key != nsAttrName) {
var value = params[key];
parts.push(['<',key,'>'].join(''));
parts.push(xmlEscape(value));
parts.push(['</',key,'>'].join(''));
}
}
parts.push(['</',namespace,':',name,'>'].join(''));
return parts.join('');
}
WSDL.prototype.objectToXML = function(obj, namespace, name, xmlns) {

@@ -510,0 +563,0 @@ var self = this,

{
"name": "soap",
"version": "0.0.3",
"version": "0.0.7",
"description": "A minimal node SOAP client",

@@ -9,3 +9,3 @@ "engines": { "node": ">=0.4.0" },

"node-expat": ">= 1.3.0",
"compress": ">= 0.1.9"
"request": ">= 2.0.0"
},

@@ -12,0 +12,0 @@ "repository" : {

@@ -5,3 +5,2 @@ This module lets you connect to web services using SOAP. It also provides a server that allows you to run your own SOAP services.

* Only the *document* style is supported (no rpc support yet)
* Only a few XSD Schema types are supported

@@ -8,0 +7,0 @@ * Only WS-Security is supported using UsernameToken and PasswordText encoding

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc