Skip to content

Commit cdf28fa

Browse files
authored
Lint code (#288)
1 parent f9657b5 commit cdf28fa

8 files changed

+49
-47
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"extends": ["eslint:recommended", "prettier"],
1212
"rules": {
13-
"no-console": "warn",
13+
"no-console": "error",
1414
"no-unused-vars": "warn",
1515
"no-prototype-builtins": "warn"
1616
}

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"canonicalize",
55
"canonicalized",
66
"codecov",
7+
"feide",
8+
"reserialization",
79
"wsfederation",
810
"wssecurity"
911
]

lib/enveloped-signature.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ EnvelopedSignature.prototype.process = function (node, options) {
1818
var signatures = xpath.select(".//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']", node);
1919
for (var h in signatures) {
2020
if (!signatures.hasOwnProperty(h)) continue;
21-
var signature = signatures[h];
22-
var signatureValue = utils.findFirst(signature, ".//*[local-name(.)='SignatureValue']/text()").data;
21+
var nodeSignature = signatures[h];
22+
var signatureValue = utils.findFirst(nodeSignature, ".//*[local-name(.)='SignatureValue']/text()").data;
2323
if (expectedSignatureValue === signatureValue) {
24-
signature.parentNode.removeChild(signature);
24+
nodeSignature.parentNode.removeChild(nodeSignature);
2525
}
2626
}
2727
return node;

lib/signed-xml.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ SignedXml.findAncestorNs = findAncestorNs;
340340

341341
SignedXml.prototype.checkSignature = function(xml, callback) {
342342
if (callback != null && typeof callback !== 'function') {
343-
throw new Error("Last paramater must be a callback function")
343+
throw new Error("Last parameter must be a callback function")
344344
}
345345

346346
this.validationErrors = []
@@ -358,11 +358,11 @@ SignedXml.prototype.checkSignature = function(xml, callback) {
358358

359359
this.signingKey = this.keyInfoProvider.getKey(this.keyInfo)
360360
if (!this.signingKey) {
361-
var err = new Error("key info provider could not resolve key info " + this.keyInfo)
361+
var err2 = new Error("key info provider could not resolve key info " + this.keyInfo)
362362
if (!callback) {
363-
throw err
363+
throw err2
364364
} else {
365-
callback(err)
365+
callback(err2)
366366
return
367367
}
368368
}
@@ -379,13 +379,13 @@ SignedXml.prototype.checkSignature = function(xml, callback) {
379379
}
380380

381381
if (!callback) {
382-
//Syncronous flow
382+
// Synchronous flow
383383
if (!this.validateSignatureValue(doc)) {
384384
return false
385385
}
386386
return true
387387
} else {
388-
//Asyncronous flow
388+
// Asynchronous flow
389389
this.validateSignatureValue(doc, function (err, isValidSignature) {
390390
if (err) {
391391
this.validationErrors.push("invalid signature: the signature value " +
@@ -513,7 +513,7 @@ SignedXml.prototype.validateReferences = function(doc) {
513513
}
514514

515515
if (elem.length==0) {
516-
this.validationErrors.push("invalid signature: the signature refernces an element with uri "+
516+
this.validationErrors.push("invalid signature: the signature references an element with uri "+
517517
ref.uri + " but could not find such element in the xml")
518518
return false
519519
}
@@ -681,7 +681,7 @@ SignedXml.prototype.addReference = function(xpath, transforms, digestAlgorithm,
681681
}
682682

683683
/**
684-
* Compute the signature of the given xml (usign the already defined settings)
684+
* Compute the signature of the given xml (using the already defined settings)
685685
*
686686
* Options:
687687
*
@@ -701,7 +701,7 @@ SignedXml.prototype.computeSignature = function(xml, opts, callback) {
701701
}
702702

703703
if (callback != null && typeof callback !== 'function') {
704-
throw new Error("Last paramater must be a callback function")
704+
throw new Error("Last parameter must be a callback function")
705705
}
706706

707707
var doc = new Dom().parseFromString(xml),
@@ -775,17 +775,17 @@ SignedXml.prototype.computeSignature = function(xml, opts, callback) {
775775
// A trick to remove the namespaces that already exist in the xml
776776
// This only works if the prefix and namespace match with those in te xml
777777
var dummySignatureWrapper = "<Dummy " + existingPrefixesString + ">" + signatureXml + "</Dummy>"
778-
var xml = new Dom().parseFromString(dummySignatureWrapper)
779-
var signatureDoc = xml.documentElement.firstChild;
778+
var nodeXml = new Dom().parseFromString(dummySignatureWrapper)
779+
var signatureDoc = nodeXml.documentElement.firstChild;
780780

781781
var referenceNode = xpath.select(location.reference, doc);
782782

783783
if (!referenceNode || referenceNode.length === 0) {
784-
var err = new Error("the following xpath cannot be used because it was not found: " + location.reference);
784+
var err2 = new Error("the following xpath cannot be used because it was not found: " + location.reference);
785785
if (!callback) {
786-
throw err
786+
throw err2
787787
} else {
788-
callback(err, null)
788+
callback(err2, null)
789789
return
790790
}
791791
}
@@ -805,11 +805,11 @@ SignedXml.prototype.computeSignature = function(xml, opts, callback) {
805805
this.signatureNode = signatureDoc
806806
var signedInfoNode = utils.findChilds(this.signatureNode, "SignedInfo")
807807
if (signedInfoNode.length == 0) {
808-
var err = new Error("could not find SignedInfo element in the message")
808+
var err3 = new Error("could not find SignedInfo element in the message")
809809
if (!callback) {
810-
throw err
810+
throw err3
811811
} else {
812-
callback(err)
812+
callback(err3)
813813
return
814814
}
815815
}
@@ -934,8 +934,8 @@ SignedXml.prototype.getCanonXml = function(transforms, node, options) {
934934
var transform = this.findCanonicalizationAlgorithm(transforms[t])
935935
canonXml = transform.process(canonXml, options);
936936
//TODO: currently transform.process may return either Node or String value (enveloped transformation returns Node, exclusive-canonicalization returns String).
937-
//This eitehr needs to be more explicit in the API, or all should return the same.
938-
//exclusive-canonicalization returns String since it builds the Xml by hand. If it had used xmldom it would inccorectly minimize empty tags
937+
//This either needs to be more explicit in the API, or all should return the same.
938+
//exclusive-canonicalization returns String since it builds the Xml by hand. If it had used xmldom it would incorrectly minimize empty tags
939939
//to <x/> instead of <x></x> and also incorrectly handle some delicate line break issues.
940940
//enveloped transformation returns Node since if it would return String consider this case:
941941
//<x xmlns:p='ns'><p:y/></x>

test/c14nWithComments-unit-tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ module.exports = {
185185
},
186186

187187

188-
"Exclusive canonicalization preserves white space bewteen elements": function (test) {
188+
"Exclusive canonicalization preserves white space between elements": function (test) {
189189
compare(test,
190190
"<root><child><inner>123</inner>\n</child></root>",
191191
"//*[local-name(.)='child']",

test/canonicalization-unit-tests.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ module.exports = {
195195

196196
"Exclusive canonicalization works on xml with element values with special characters": function (test) {
197197
compare(test,
198+
// eslint-disable-next-line no-useless-escape
198199
"<root><child><innerEncoded>&amp;&lt;>&quot;11&#xD;</innerEncoded><innerUnencoded>&>\"11\r\</innerUnencoded></child></root>",
199200
"//*[local-name(.)='child']",
200201
"<child><innerEncoded>&amp;&lt;&gt;\"11&#xD;</innerEncoded><innerUnencoded>&amp;&gt;\"11\n</innerUnencoded></child>")

test/signature-integration-tests.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ module.exports = {
151151
sig.computeSignature(xml)
152152

153153
var signed = sig.getSignedXml();
154-
console.log(signed);
155154

156155
var doc = new Dom().parseFromString(signed);
157156

test/signature-unit-tests.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var select = require('xpath').select
77

88
module.exports = {
99

10-
"signer adds increasing id atributes to elements": function (test) {
10+
"signer adds increasing id attributes to elements": function (test) {
1111
verifyAddsId(test, "wssecurity", "equal")
1212
verifyAddsId(test, null, "different")
1313
test.done();
@@ -131,14 +131,14 @@ module.exports = {
131131
"signer creates signature with correct structure": function(test) {
132132

133133
function DummyKeyInfo() {
134-
this.getKeyInfo = function(key) {
134+
this.getKeyInfo = function() {
135135
return "dummy key info"
136136
}
137137
}
138138

139139
function DummyDigest() {
140140

141-
this.getHash = function(xml) {
141+
this.getHash = function() {
142142
return "dummy digest"
143143
}
144144

@@ -149,7 +149,7 @@ module.exports = {
149149

150150
function DummySignatureAlgorithm() {
151151

152-
this.getSignature = function(xml, signingKey) {
152+
this.getSignature = function() {
153153
return "dummy signature"
154154
}
155155

@@ -160,7 +160,7 @@ module.exports = {
160160
}
161161

162162
function DummyTransformation() {
163-
this.process = function(node) {
163+
this.process = function() {
164164
return "< x/>"
165165
}
166166

@@ -170,7 +170,7 @@ module.exports = {
170170
}
171171

172172
function DummyCanonicalization() {
173-
this.process = function(node) {
173+
this.process = function() {
174174
return "< x/>"
175175
}
176176

@@ -283,14 +283,14 @@ module.exports = {
283283
var prefix = 'ds';
284284

285285
function DummyKeyInfo() {
286-
this.getKeyInfo = function(key) {
286+
this.getKeyInfo = function() {
287287
return "<ds:dummy>dummy key info</ds:dummy>"
288288
}
289289
}
290290

291291
function DummyDigest() {
292292

293-
this.getHash = function(xml) {
293+
this.getHash = function() {
294294
return "dummy digest"
295295
}
296296

@@ -301,7 +301,7 @@ module.exports = {
301301

302302
function DummySignatureAlgorithm() {
303303

304-
this.getSignature = function(xml, signingKey) {
304+
this.getSignature = function( ) {
305305
return "dummy signature"
306306
}
307307

@@ -312,7 +312,7 @@ module.exports = {
312312
}
313313

314314
function DummyTransformation() {
315-
this.process = function(node) {
315+
this.process = function() {
316316
return "< x/>"
317317
}
318318

@@ -322,7 +322,7 @@ module.exports = {
322322
}
323323

324324
function DummyCanonicalization() {
325-
this.process = function(node) {
325+
this.process = function() {
326326
return "< x/>"
327327
}
328328

@@ -505,7 +505,7 @@ module.exports = {
505505
sig.addReference("//*[local-name(.)='y']")
506506
sig.addReference("//*[local-name(.)='w']")
507507

508-
sig.computeSignature(xml, function(err) {
508+
sig.computeSignature(xml, function() {
509509
var signedXml = sig.getSignedXml()
510510
var expected = "<root><x xmlns=\"ns\" Id=\"_0\"/><y attr=\"value\" Id=\"_1\"/><z><w Id=\"_2\"/></z>" +
511511
"<Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\">" +
@@ -613,10 +613,10 @@ module.exports = {
613613

614614
"signer adds existing prefixes": function(test) {
615615
function AssertionKeyInfo(assertionId) {
616-
this.getKeyInfo = function(key, prefix) {
616+
this.getKeyInfo = function() {
617617
return '<wsse:SecurityTokenReference wsse11:TokenType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1" wsu:Id="0" ' +
618618
'xmlns:wsse11="http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd"> ' +
619-
'<wsse:KeyIdentifier ValueType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.0#SAMLAssertionID">'+assertionId+'</wsse:KeyIdentifier>'
619+
'<wsse:KeyIdentifier ValueType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.0#SAMLAssertionID">'+assertionId+'</wsse:KeyIdentifier>' +
620620
'</wsse:SecurityTokenReference>';
621621
};
622622
}
@@ -648,7 +648,7 @@ module.exports = {
648648
wsu: "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
649649
}
650650
});
651-
result = sig.getSignedXml();
651+
var result = sig.getSignedXml();
652652
test.equal((result.match(/xmlns:wsu=/g) || []).length, 1)
653653
test.equal((result.match(/xmlns:wsse=/g) || []).length, 1)
654654
test.done();
@@ -825,7 +825,7 @@ function verifySignature(xml, mode) {
825825
sig.keyInfoProvider = new FileKeyInfo("./test/static/client_public.pem")
826826
sig.loadSignature(node)
827827
var res = sig.checkSignature(xml)
828-
console.log(sig.validationErrors)
828+
829829
return res;
830830
}
831831

@@ -835,10 +835,10 @@ function verifyDoesNotDuplicateIdAttributes(test, mode, prefix) {
835835
sig.signingKey = fs.readFileSync("./test/static/client.pem")
836836
sig.addReference("//*[local-name(.)='x']")
837837
sig.computeSignature(xml)
838-
var signedxml = sig.getOriginalXmlWithIds()
839-
var doc = new dom().parseFromString(signedxml)
838+
var signedXml = sig.getOriginalXmlWithIds()
839+
var doc = new dom().parseFromString(signedXml)
840840
var attrs = select("//@*", doc)
841-
test.equals(2, attrs.length, "wrong nuber of attributes")
841+
test.equals(2, attrs.length, "wrong number of attributes")
842842

843843
}
844844

@@ -852,10 +852,10 @@ function verifyAddsId(test, mode, nsMode) {
852852
sig.addReference("//*[local-name(.)='w']")
853853

854854
sig.computeSignature(xml)
855-
var signedxml = sig.getOriginalXmlWithIds()
856-
var doc = new dom().parseFromString(signedxml)
855+
var signedXml = sig.getOriginalXmlWithIds()
856+
var doc = new dom().parseFromString(signedXml)
857857

858-
op = nsMode == "equal" ? "=" : "!="
858+
var op = nsMode == "equal" ? "=" : "!="
859859

860860
var xpath = "//*[local-name(.)='{elem}' and '_{id}' = @*[local-name(.)='Id' and namespace-uri(.)" + op + "'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd']]"
861861

0 commit comments

Comments
 (0)