Skip to content

Commit

Permalink
Moved the EJS templates to strings
Browse files Browse the repository at this point in the history
Moved the EJS templates to strings so they coudl be imported as modules
Reason, is having a issue with this in AWS Lambda, where all
dependencies are compiled into one file.
Fix lint errors in:
 - lib/wsdl.js
 - test/request-response-samples/Dummy__should_handle_inline_types/wsdl_options.js
New line added to end of Package.json
  • Loading branch information
Lorne Currie committed Dec 5, 2018
1 parent 9541e14 commit 7eb9ec4
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 31 deletions.
8 changes: 5 additions & 3 deletions lib/security/WSSecurityCert.js
Expand Up @@ -6,7 +6,9 @@ var ejs = require('ejs');
var SignedXml = require('xml-crypto').SignedXml;
var uuid4 = require('uuid/v4');
var wsseSecurityHeaderTemplate;
var wsseSecurityHeaderTemplateXml = require('./templates/wsse-security-header');
var wsseSecurityTokenTemplate;
var wsseSecurityTokenTemplateXml = require('./templates/wsse-security-token');

function addMinutes(date, minutes) {
return new Date(date.getTime() + minutes * 60000);
Expand Down Expand Up @@ -52,7 +54,7 @@ function WSSecurityCert(privatePEM, publicP12PEM, password, options) {
this.signer.keyInfoProvider = {};
this.signer.keyInfoProvider.getKeyInfo = function (key) {
if (!wsseSecurityTokenTemplate) {
wsseSecurityTokenTemplate = ejs.compile(fs.readFileSync(path.join(__dirname, 'templates', 'wsse-security-token.ejs')).toString());
wsseSecurityTokenTemplate = ejs.compile(wsseSecurityTokenTemplateXml);
}

return wsseSecurityTokenTemplate({ x509Id: _this.x509Id });
Expand All @@ -62,9 +64,9 @@ function WSSecurityCert(privatePEM, publicP12PEM, password, options) {
WSSecurityCert.prototype.postProcess = function (xml, envelopeKey) {
this.created = generateCreated();
this.expires = generateExpires();

if (!wsseSecurityHeaderTemplate) {
wsseSecurityHeaderTemplate = ejs.compile(fs.readFileSync(path.join(__dirname, 'templates', 'wsse-security-header.ejs')).toString());
wsseSecurityHeaderTemplate = ejs.compile(wsseSecurityHeaderTemplateXml);
}

var secHeader = wsseSecurityHeaderTemplate({
Expand Down
12 changes: 0 additions & 12 deletions lib/security/templates/wsse-security-header.ejs

This file was deleted.

14 changes: 14 additions & 0 deletions lib/security/templates/wsse-security-header.js
@@ -0,0 +1,14 @@
var 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"',
'soap:mustUnderstand="1">',
'<wsse:BinarySecurityToken ',
'EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ',
'ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" ',
'wsu:Id="<%= id%>"><%= binaryToken%></wsse:BinarySecurityToken><% if (hasTimeStamp === true) { %>',
'<Timestamp xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" Id="_1">',
'<Created><%= created%></Created>',
'<Expires><%= expires%></Expires>',
'</Timestamp> <% } %>',
'</wsse:Security>'].join('\n');

module.exports = header;
3 changes: 0 additions & 3 deletions lib/security/templates/wsse-security-token.ejs

This file was deleted.

5 changes: 5 additions & 0 deletions lib/security/templates/wsse-security-token.js
@@ -0,0 +1,5 @@
var token = ['<wsse:SecurityTokenReference>',
'<wsse:Reference URI="#<%= x509Id%>" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/>',
'</wsse:SecurityTokenReference>'].join('\n');

module.exports = token;
13 changes: 7 additions & 6 deletions lib/wsdl.js
Expand Up @@ -65,9 +65,9 @@ function splitQName(nsName) {
};
}

const [topLevelName] = nsName.split('|');
var topLevelName = nsName.split('|')[0];

const prefixOffset = topLevelName.indexOf(':');
var prefixOffset = topLevelName.indexOf(':');

return {
prefix: topLevelName.substring(0, prefixOffset) || TNS_PREFIX,
Expand Down Expand Up @@ -1746,10 +1746,11 @@ WSDL.prototype.objectToXML = function(obj, name, nsPrefix, nsURI, isFirst, xmlns
}

var i, n;
var nonSubNameSpace, nameWithNsRegex;
// start building out XML string.
if (Array.isArray(obj)) {
var nonSubNameSpace = '';
var nameWithNsRegex = /^([^:]+):([^:]+)$/.exec(name);
nonSubNameSpace = '';
nameWithNsRegex = /^([^:]+):([^:]+)$/.exec(name);
if (nameWithNsRegex) {
nonSubNameSpace = nameWithNsRegex[1];
name = nameWithNsRegex[2];
Expand Down Expand Up @@ -1805,10 +1806,10 @@ WSDL.prototype.objectToXML = function(obj, name, nsPrefix, nsURI, isFirst, xmlns
var attr = self.processAttributes(child, nsContext);

var value = '';
var nonSubNameSpace = '';
nonSubNameSpace = '';
var emptyNonSubNameSpace = false;

var nameWithNsRegex = /^([^:]+):([^:]+)$/.exec(name);
nameWithNsRegex = /^([^:]+):([^:]+)$/.exec(name);
if (nameWithNsRegex) {
nonSubNameSpace = nameWithNsRegex[1] + ':';
name = nameWithNsRegex[2];
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -60,4 +60,4 @@
"sinon": "^1.17.5",
"timekeeper": "~0.0.4"
}
}
}
@@ -1,13 +1,16 @@
exports.customDeserializer = {
DateTime: (text) => new Date(text),
TimeHourMinute: (text) => {
"use strict";
var customDeserializer = {
DateTime: function (text) { return new Date(text); },
TimeHourMinute: function (text) {
// Return number of minutes since midnight
const results = text.split(':').map(t => parseInt(t, 10));
var results = text.split(':').map(function (t) { return parseInt(t, 10); });
return results[0] * 60 + results[1];
},
NestedSimpleType: (text) => {
NestedSimpleType: function (text) {
// Return number of minutes since midnight
const results = text.split(':').map(t => parseInt(t, 10));
var results = text.split(':').map(function (t) { return parseInt(t, 10); });
return results[0] * 60 + results[1];
}
};

module.exports = customDeserializer;

0 comments on commit 7eb9ec4

Please sign in to comment.