diff --git a/README.md b/README.md index a41060e3..918de24a 100644 --- a/README.md +++ b/README.md @@ -179,7 +179,7 @@ You might find it difficult to guess such transforms, but there are typical tran ### xpath -See [xpath.js](https://github.com/yaronn/xpath.js) for usage +See [xpath](https://github.com/goto100/xpath) for usage ### SignedXml diff --git a/example/example.js b/example/example.js index 9b81b169..eda0c257 100644 --- a/example/example.js +++ b/example/example.js @@ -16,7 +16,7 @@ function signXml(xml, xpath, key, dest) function validateXml(xml, key) { var doc = new dom().parseFromString(xml) - var signature = select(doc, "/*/*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']")[0] + var signature = select("/*/*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']", doc)[0] var sig = new SignedXml() sig.keyInfoProvider = new FileKeyInfo(key) sig.loadSignature(signature.toString()) diff --git a/index.js b/index.js index 2866e538..31b13b1b 100644 --- a/index.js +++ b/index.js @@ -1,2 +1,2 @@ module.exports = require('./lib/signed-xml') -module.exports.xpath = require('xpath.js') \ No newline at end of file +module.exports.xpath = require('xpath').select \ No newline at end of file diff --git a/lib/enveloped-signature.js b/lib/enveloped-signature.js index 51665505..82b2c722 100644 --- a/lib/enveloped-signature.js +++ b/lib/enveloped-signature.js @@ -1,4 +1,4 @@ -var xpath = require('xpath.js'); +var xpath = require('xpath'); exports.EnvelopedSignature = EnvelopedSignature; @@ -6,7 +6,7 @@ function EnvelopedSignature() { } EnvelopedSignature.prototype.process = function (node) { - var signature = xpath(node, "./*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']")[0]; + var signature = xpath.select("./*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']", node)[0]; if (signature) signature.parentNode.removeChild(signature); return node; }; diff --git a/lib/signed-xml.js b/lib/signed-xml.js index 69d598fd..75593412 100644 --- a/lib/signed-xml.js +++ b/lib/signed-xml.js @@ -1,4 +1,4 @@ -var select = require('xpath.js') +var xpath = require('xpath') , Dom = require('xmldom').DOMParser , utils = require('./utils') , c14n = require('./c14n-canonicalization') @@ -6,7 +6,6 @@ var select = require('xpath.js') , EnvelopedSignature = require('./enveloped-signature').EnvelopedSignature , crypto = require('crypto') , fs = require('fs') - , xpath = require('xpath.js') exports.SignedXml = SignedXml exports.FileKeyInfo = FileKeyInfo @@ -209,7 +208,7 @@ function HMACSHA1() { * @returns {Array} i.e. [{prefix: "saml", namespaceURI: "urn:oasis:names:tc:SAML:2.0:assertion"}] */ function findAncestorNs(doc, docSubsetXpath){ - var docSubset = xpath(doc, docSubsetXpath); + var docSubset = xpath.select(docSubsetXpath, doc); if(!Array.isArray(docSubset) || docSubset.length < 1){ return []; @@ -418,7 +417,7 @@ SignedXml.prototype.validateReferences = function(doc) { var elemXpath; if (uri=="") { - elem = select(doc, "//*") + elem = xpath.select("//*", doc) } else if (uri.indexOf("'") != -1) { // xpath injection @@ -429,7 +428,7 @@ SignedXml.prototype.validateReferences = function(doc) { for (var index in this.idAttributes) { if (!this.idAttributes.hasOwnProperty(index)) continue; var tmp_elemXpath = "//*[@*[local-name(.)='" + this.idAttributes[index] + "']='" + uri + "']"; - var tmp_elem = select(doc, tmp_elemXpath) + var tmp_elem = xpath.select(tmp_elemXpath, doc) num_elements_for_id += tmp_elem.length; if (tmp_elem.length > 0) { elem = tmp_elem; @@ -519,7 +518,7 @@ SignedXml.prototype.loadSignature = function(signatureNode) { this.signatureXml = signatureNode.toString(); - var nodes = select(signatureNode, ".//*[local-name(.)='CanonicalizationMethod']/@Algorithm") + var nodes = xpath.select(".//*[local-name(.)='CanonicalizationMethod']/@Algorithm", signatureNode) if (nodes.length==0) throw new Error("could not find CanonicalizationMethod/@Algorithm element") this.canonicalizationAlgorithm = nodes[0].value @@ -527,7 +526,7 @@ SignedXml.prototype.loadSignature = function(signatureNode) { utils.findFirst(signatureNode, ".//*[local-name(.)='SignatureMethod']/@Algorithm").value this.references = [] - var references = select(signatureNode, ".//*[local-name(.)='SignedInfo']/*[local-name(.)='Reference']") + var references = xpath.select(".//*[local-name(.)='SignedInfo']/*[local-name(.)='Reference']", signatureNode) if (references.length == 0) throw new Error("could not find any Reference elements") for (var i in references) { @@ -539,7 +538,7 @@ SignedXml.prototype.loadSignature = function(signatureNode) { this.signatureValue = utils.findFirst(signatureNode, ".//*[local-name(.)='SignatureValue']/text()").data.replace(/\r?\n/g, '') - this.keyInfo = select(signatureNode, ".//*[local-name(.)='KeyInfo']") + this.keyInfo = xpath.select(".//*[local-name(.)='KeyInfo']", signatureNode) } /** @@ -576,7 +575,7 @@ SignedXml.prototype.loadReference = function(ref) { transforms.push(utils.findAttr(trans, "Algorithm").value) } - var inclusiveNamespaces = select(transformsNode, "//*[local-name(.)='InclusiveNamespaces']"); + var inclusiveNamespaces = xpath.select("//*[local-name(.)='InclusiveNamespaces']", transformsNode); if (inclusiveNamespaces.length > 0) { inclusiveNamespacesPrefixList = inclusiveNamespaces[0].getAttribute('PrefixList'); } @@ -685,7 +684,7 @@ SignedXml.prototype.computeSignature = function(xml, opts) { var signatureDoc = new Dom().parseFromString(this.signatureXml) - var referenceNode = select(doc, location.reference); + var referenceNode = xpath.select(location.reference, doc); if (!referenceNode || referenceNode.length === 0) { throw new Error("the following xpath cannot be used because it was not found: " + location.reference); @@ -736,7 +735,7 @@ SignedXml.prototype.createReferences = function(doc, prefix) { if (!this.references.hasOwnProperty(n)) continue; var ref = this.references[n] - , nodes = select(doc, ref.xpath) + , nodes = xpath.select(ref.xpath, doc) if (nodes.length==0) { throw new Error('the following xpath cannot be signed because it was not found: ' + ref.xpath) diff --git a/lib/utils.js b/lib/utils.js index e70ecf36..914965bb 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,4 +1,4 @@ -var select = require('xpath.js'); +var select = require('xpath').select function findAttr(node, localName, namespace) { for (var i = 0; i=0.0.3" + "xpath": "0.0.27" }, "devDependencies": { "nodeunit": "^0.11.3" diff --git a/test/c14n-non-exclusive-unit-test.js b/test/c14n-non-exclusive-unit-test.js index cff03704..ffcb3dae 100644 --- a/test/c14n-non-exclusive-unit-test.js +++ b/test/c14n-non-exclusive-unit-test.js @@ -1,11 +1,11 @@ var C14nCanonicalization = require("../lib/c14n-canonicalization").C14nCanonicalization , Dom = require('xmldom').DOMParser - , select = require('xpath.js') + , select = require('xpath').select , findAncestorNs = require('../lib/signed-xml').SignedXml.findAncestorNs var test_C14nCanonicalization = function(test, xml, xpath, expected) { var doc = new Dom().parseFromString(xml); - var elem = select(doc, xpath)[0]; + var elem = select(xpath, doc)[0]; var can = new C14nCanonicalization(); var result = can.process(elem, { ancestorNamespaces: findAncestorNs(doc, xpath) diff --git a/test/c14nWithComments-unit-tests.js b/test/c14nWithComments-unit-tests.js index ccd21cbb..a259ad8d 100644 --- a/test/c14nWithComments-unit-tests.js +++ b/test/c14nWithComments-unit-tests.js @@ -1,13 +1,13 @@ var c14nWithComments = require("../lib/exclusive-canonicalization").ExclusiveCanonicalizationWithComments , Dom = require('xmldom').DOMParser - , select = require('xpath.js') + , select = require('xpath').select , SignedXml = require('../lib/signed-xml.js').SignedXml var compare = function(test, xml, xpath, expected, inclusiveNamespacesPrefixList) { test.expect(1) var doc = new Dom().parseFromString(xml) - var elem = select(doc, xpath)[0] + var elem = select(xpath, doc)[0] var can = new c14nWithComments() var result = can.process(elem, { inclusiveNamespacesPrefixList: inclusiveNamespacesPrefixList }).toString() @@ -345,7 +345,7 @@ module.exports = { "Multiple Canonicalization with namespace definition outside of signed element": function (test) { //var doc = new Dom().parseFromString("") var doc = new Dom().parseFromString("") - var node = select(doc, "//*[local-name(.)='y']")[0] + var node = select("//*[local-name(.)='y']", doc)[0] var sig = new SignedXml() var res = sig.getCanonXml(["http://www.w3.org/2000/09/xmldsig#enveloped-signature", "http://www.w3.org/2001/10/xml-exc-c14n#"], node) test.equal("", res) @@ -358,7 +358,7 @@ module.exports = { // in a document. var xml = ''; var doc = new Dom().parseFromString(xml); - var node = select(doc, "//*[local-name(.)='y']")[0]; + var node = select("//*[local-name(.)='y']", doc)[0]; var sig = new SignedXml(); var transforms = ["http://www.w3.org/2000/09/xmldsig#enveloped-signature"]; var res = sig.getCanonXml(transforms, node); diff --git a/test/canonicalization-unit-tests.js b/test/canonicalization-unit-tests.js index 6b983cc6..cce7677f 100644 --- a/test/canonicalization-unit-tests.js +++ b/test/canonicalization-unit-tests.js @@ -1,13 +1,13 @@ var ExclusiveCanonicalization = require("../lib/exclusive-canonicalization").ExclusiveCanonicalization , Dom = require('xmldom').DOMParser - , select = require('xpath.js') + , select = require('xpath').select , SignedXml = require('../lib/signed-xml.js').SignedXml var compare = function(test, xml, xpath, expected, inclusiveNamespacesPrefixList, defaultNsForPrefix, ancestorNamespaces) { test.expect(1) var doc = new Dom().parseFromString(xml) - var elem = select(doc, xpath)[0] + var elem = select(xpath, doc)[0] var can = new ExclusiveCanonicalization() var result = can.process(elem, { inclusiveNamespacesPrefixList: inclusiveNamespacesPrefixList, @@ -381,7 +381,7 @@ module.exports = { "Multiple Canonicalization with namespace definition outside of signed element": function (test) { //var doc = new Dom().parseFromString("") var doc = new Dom().parseFromString("") - var node = select(doc, "//*[local-name(.)='y']")[0] + var node = select("//*[local-name(.)='y']", doc)[0] var sig = new SignedXml() var res = sig.getCanonXml(["http://www.w3.org/2000/09/xmldsig#enveloped-signature", "http://www.w3.org/2001/10/xml-exc-c14n#"], node) test.equal("", res) @@ -394,7 +394,7 @@ module.exports = { // in a document. var xml = ''; var doc = new Dom().parseFromString(xml); - var node = select(doc, "//*[local-name(.)='y']")[0]; + var node = select("//*[local-name(.)='y']", doc)[0]; var sig = new SignedXml(); var transforms = ["http://www.w3.org/2000/09/xmldsig#enveloped-signature"]; var res = sig.getCanonXml(transforms, node); diff --git a/test/document-test.js b/test/document-test.js index db0f8fce..a9be3233 100644 --- a/test/document-test.js +++ b/test/document-test.js @@ -1,11 +1,12 @@ var crypto = require('../index'); +var xpath = require('xpath'); var xmldom = require('xmldom'); var fs = require('fs'); exports['test with a document '] = function (test) { var xml = fs.readFileSync('./test/static/valid_saml.xml', 'utf-8'); var doc = new xmldom.DOMParser().parseFromString(xml); - var signature = new xmldom.DOMParser().parseFromString(crypto.xpath(doc, "/*/*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']")[0].toString()); + var signature = new xmldom.DOMParser().parseFromString(xpath.select("/*/*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']", doc)[0].toString()); var sig = new crypto.SignedXml(); sig.keyInfoProvider = new crypto.FileKeyInfo("./test/static/feide_public.pem"); sig.loadSignature(signature); diff --git a/test/hmac-tests.js b/test/hmac-tests.js index d20dd441..17149afa 100644 --- a/test/hmac-tests.js +++ b/test/hmac-tests.js @@ -1,11 +1,12 @@ var crypto = require('../index'); +var xpath = require('xpath'); var xmldom = require('xmldom'); var fs = require('fs'); exports['test validating HMAC signature'] = function (test) { var xml = fs.readFileSync('./test/static/hmac_signature.xml', 'utf-8'); var doc = new xmldom.DOMParser().parseFromString(xml); - var signature = crypto.xpath(doc, "/*/*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']")[0]; + var signature = xpath.select("/*/*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']", doc)[0]; var sig = new crypto.SignedXml(); sig.keyInfoProvider = new crypto.FileKeyInfo("./test/static/hmac.key"); sig.loadSignature(signature); @@ -17,7 +18,7 @@ exports['test validating HMAC signature'] = function (test) { exports['test HMAC signature with incorrect key'] = function (test) { var xml = fs.readFileSync('./test/static/hmac_signature.xml', 'utf-8'); var doc = new xmldom.DOMParser().parseFromString(xml); - var signature = crypto.xpath(doc, "/*/*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']")[0]; + var signature = xpath.select("/*/*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']", doc)[0]; var sig = new crypto.SignedXml(); sig.keyInfoProvider = new crypto.FileKeyInfo("./test/static/hmac-foobar.key"); sig.loadSignature(signature); @@ -40,7 +41,7 @@ exports['test create and validate HMAC signature'] = function (test) { sig.computeSignature(xml); var doc = new xmldom.DOMParser().parseFromString(sig.getSignedXml()); - var signature = crypto.xpath(doc, "/*/*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']")[0]; + var signature = xpath.select("/*/*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']", doc)[0]; var verify = new crypto.SignedXml(); verify.keyInfoProvider = new crypto.FileKeyInfo("./test/static/hmac.key"); verify.loadSignature(signature); diff --git a/test/saml-response-test.js b/test/saml-response-test.js index 396cdfd3..28b063d6 100644 --- a/test/saml-response-test.js +++ b/test/saml-response-test.js @@ -1,11 +1,12 @@ var crypto = require('../index'); +var xpath = require('xpath'); var xmldom = require('xmldom'); var fs = require('fs'); exports['test validating SAML response'] = function (test) { var xml = fs.readFileSync('./test/static/valid_saml.xml', 'utf-8'); var doc = new xmldom.DOMParser().parseFromString(xml); - var signature = crypto.xpath(doc, "/*/*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']")[0]; + var signature = xpath.select("/*/*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']", doc)[0]; var sig = new crypto.SignedXml(); sig.keyInfoProvider = new crypto.FileKeyInfo("./test/static/feide_public.pem"); sig.loadSignature(signature); @@ -17,8 +18,8 @@ exports['test validating SAML response'] = function (test) { exports['test validating wrapped assertion signature'] = function (test) { var xml = fs.readFileSync('./test/static/valid_saml_signature_wrapping.xml', 'utf-8'); var doc = new xmldom.DOMParser().parseFromString(xml); - var assertion = crypto.xpath(doc, "//*[local-name(.)='Assertion']")[0]; - var signature = crypto.xpath(assertion, "//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']")[0]; + var assertion = xpath.select("//*[local-name(.)='Assertion']", doc)[0]; + var signature = xpath.select("//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']", assertion)[0]; var sig = new crypto.SignedXml(); sig.keyInfoProvider = new crypto.FileKeyInfo("./test/static/feide_public.pem"); sig.loadSignature(signature); @@ -37,7 +38,7 @@ exports['test validating wrapped assertion signature'] = function (test) { exports['test validating SAML response where a namespace is defined outside the signed element'] = function (test) { var xml = fs.readFileSync('./test/static/saml_external_ns.xml', 'utf-8'); var doc = new xmldom.DOMParser().parseFromString(xml); - var signature = crypto.xpath(doc, "//*//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']")[0]; + var signature = xpath.select("//*//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']", doc)[0]; var sig = new crypto.SignedXml(); sig.keyInfoProvider = new crypto.FileKeyInfo("./test/static/saml_external_ns.pem"); sig.loadSignature(signature); @@ -49,8 +50,8 @@ exports['test validating SAML response where a namespace is defined outside the exports['test reference id does not contain quotes'] = function (test) { var xml = fs.readFileSync('./test/static/id_with_quotes.xml', 'utf-8'); var doc = new xmldom.DOMParser().parseFromString(xml); - var assertion = crypto.xpath(doc, "//*[local-name(.)='Assertion']")[0]; - var signature = crypto.xpath(assertion, "//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']")[0]; + var assertion = xpath.select("//*[local-name(.)='Assertion']", doc)[0]; + var signature = xpath.select("//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']", assertion)[0]; var sig = new crypto.SignedXml(); sig.keyInfoProvider = new crypto.FileKeyInfo("./test/static/feide_public.pem"); sig.loadSignature(signature); @@ -67,7 +68,7 @@ exports['test reference id does not contain quotes'] = function (test) { exports['test validating SAML response WithComments'] = function (test) { var xml = fs.readFileSync('./test/static/valid_saml_withcomments.xml', 'utf-8'); var doc = new xmldom.DOMParser().parseFromString(xml); - var signature = crypto.xpath(doc, "/*/*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']")[0]; + var signature = xpath.select("/*/*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']", doc)[0]; var sig = new crypto.SignedXml(); sig.keyInfoProvider = new crypto.FileKeyInfo("./test/static/feide_public.pem"); sig.loadSignature(signature); diff --git a/test/signature-integration-tests.js b/test/signature-integration-tests.js index 9eda305a..98f420f8 100644 --- a/test/signature-integration-tests.js +++ b/test/signature-integration-tests.js @@ -1,4 +1,4 @@ -var select = require('xpath.js') +var xpath = require('xpath') , Dom = require('xmldom').DOMParser , SignedXml = require('../lib/signed-xml.js').SignedXml , fs = require('fs') @@ -76,7 +76,7 @@ module.exports = { var doc = new Dom().parseFromString(xml); xml = doc.firstChild.toString(); - var signature = crypto.xpath(doc, "//*//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']")[0]; + var signature = xpath.select("//*//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']", doc)[0]; var sig = new crypto.SignedXml(); sig.keyInfoProvider = new crypto.FileKeyInfo("./test/static/windows_store_certificate.pem"); sig.loadSignature(signature); @@ -92,7 +92,7 @@ module.exports = { var doc = new Dom().parseFromString(xml); xml = doc.firstChild.toString() - var signature = crypto.xpath(doc, "//*//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']")[0]; + var signature = xpath.select("//*//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']", doc)[0]; var sig = new crypto.SignedXml(); sig.keyInfoProvider = new crypto.FileKeyInfo("./test/static/signature_with_inclusivenamespaces.pem"); sig.loadSignature(signature); @@ -109,7 +109,7 @@ module.exports = { var doc = new Dom().parseFromString(xml); xml = doc.firstChild.toString() - var signature = crypto.xpath(doc, "//*//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']")[0]; + var signature = xpath.select("//*//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']", doc)[0]; var sig = new crypto.SignedXml(); sig.keyInfoProvider = new crypto.FileKeyInfo("./test/static/signature_with_inclusivenamespaces.pem"); sig.loadSignature(signature); @@ -126,7 +126,7 @@ module.exports = { var doc = new Dom().parseFromString(xml); xml = doc.firstChild.toString() - var signature = crypto.xpath(doc, "//*//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']")[0]; + var signature = xpath.select("//*//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']", doc)[0]; var sig = new crypto.SignedXml(); sig.keyInfoProvider = new crypto.FileKeyInfo("./test/static/signature_with_inclusivenamespaces.pem"); sig.loadSignature(signature); diff --git a/test/signature-unit-tests.js b/test/signature-unit-tests.js index 7fb5aaf8..dff41c29 100644 --- a/test/signature-unit-tests.js +++ b/test/signature-unit-tests.js @@ -1,8 +1,7 @@ -var select = require('xpath.js') +var select = require('xpath').select , dom = require('xmldom').DOMParser , SignedXml = require('../lib/signed-xml.js').SignedXml , FileKeyInfo = require('../lib/signed-xml.js').FileKeyInfo - , xml_assert = require('./xml-assert.js') , fs = require('fs') module.exports = { @@ -54,7 +53,7 @@ module.exports = { }); var doc = new dom().parseFromString(sig.getSignedXml()) - var referenceNode = select(doc, '/root/name')[0] + var referenceNode = select('/root/name', doc)[0] test.strictEqual(referenceNode.lastChild.localName, "Signature", "the signature should be appended to root/name"); test.done(); @@ -75,7 +74,7 @@ module.exports = { }); var doc = new dom().parseFromString(sig.getSignedXml()) - var referenceNode = select(doc, '/root/name')[0] + var referenceNode = select('/root/name', doc)[0] test.strictEqual(referenceNode.firstChild.localName, "Signature", "the signature should be prepended to root/name"); test.done(); @@ -96,7 +95,7 @@ module.exports = { }); var doc = new dom().parseFromString(sig.getSignedXml()) - var referenceNode = select(doc, '/root/name')[0] + var referenceNode = select('/root/name', doc)[0] test.strictEqual(referenceNode.previousSibling.localName, "Signature", "the signature should be inserted before to root/name"); test.done(); @@ -117,7 +116,7 @@ module.exports = { }); var doc = new dom().parseFromString(sig.getSignedXml()) - var referenceNode = select(doc, '/root/name')[0] + var referenceNode = select('/root/name', doc)[0] test.strictEqual(referenceNode.nextSibling.localName, "Signature", "the signature should be inserted after to root/name"); test.done(); @@ -515,7 +514,7 @@ module.exports = { sig.computeSignature(xml) var signedXml = sig.getSignedXml() var doc = new dom().parseFromString(signedXml) - var URI = select(doc, "//*[local-name(.)='Reference']/@URI")[0] + var URI = select("//*[local-name(.)='Reference']/@URI", doc)[0] test.equal(URI.value, "", "uri should be empty but instead was " + URI.value) test.done() }, @@ -553,7 +552,7 @@ function passValidSignature(test, file, mode) { function passLoadSignature(test, file, toString) { var xml = fs.readFileSync(file).toString() var doc = new dom().parseFromString(xml) - var node = select(doc, "/*//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']")[0] + var node = select("/*//*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']", doc)[0] var sig = new SignedXml() sig.loadSignature(toString ? node.toString() : node) @@ -569,7 +568,7 @@ function passLoadSignature(test, file, toString) { sig.signatureValue, "wrong signature value") - var keyInfo = select(sig.keyInfo[0], "//*[local-name(.)='KeyInfo']/*[local-name(.)='dummyKey']")[0]; + var keyInfo = select("//*[local-name(.)='KeyInfo']/*[local-name(.)='dummyKey']", sig.keyInfo[0])[0]; test.equal(keyInfo.firstChild.data, "1234", "keyInfo clause not correctly loaded") test.equal(3, sig.references.length) @@ -597,7 +596,7 @@ function failInvalidSignature(test, file, mode) { function verifySignature(xml, mode) { var doc = new dom().parseFromString(xml) - var node = select(doc, "/*/*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']")[0] + var node = select("/*/*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']", doc)[0] var sig = new SignedXml(mode) sig.keyInfoProvider = new FileKeyInfo("./test/static/client_public.pem") @@ -615,7 +614,7 @@ function verifyDoesNotDuplicateIdAttributes(test, mode, prefix) { sig.computeSignature(xml) var signedxml = sig.getOriginalXmlWithIds() var doc = new dom().parseFromString(signedxml) - var attrs = select(doc, "//@*") + var attrs = select("//@*", doc) test.equals(2, attrs.length, "wrong nuber of attributes") } @@ -673,6 +672,6 @@ function verifyAddsAttrs(test) { function nodeExists(test, doc, xpath) { if (!doc && !xpath) return - var node = select(doc, xpath) + var node = select(xpath, doc) test.ok(node.length==1, "xpath " + xpath + " not found") } diff --git a/test/wsfed-metadata-test.js b/test/wsfed-metadata-test.js index c685b269..f8f2415d 100644 --- a/test/wsfed-metadata-test.js +++ b/test/wsfed-metadata-test.js @@ -1,11 +1,12 @@ var crypto = require('../index'); +var xpath = require('xpath'); var xmldom = require('xmldom'); var fs = require('fs'); exports['test validating WS-Fed Metadata'] = function (test) { var xml = fs.readFileSync('./test/static/wsfederation_metadata.xml', 'utf-8'); var doc = new xmldom.DOMParser().parseFromString(xml); - var signature = crypto.xpath(doc, "/*/*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']")[0]; + var signature = xpath.select("/*/*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']", doc)[0]; var sig = new crypto.SignedXml(); sig.keyInfoProvider = new crypto.FileKeyInfo("./test/static/wsfederation_metadata.pem"); sig.loadSignature(signature); diff --git a/test/xml-assert.js b/test/xml-assert.js index cc7a2a55..823744a8 100644 --- a/test/xml-assert.js +++ b/test/xml-assert.js @@ -1,10 +1,8 @@ -var select = require('xpath.js') - , dom = require('xmldom').DOMParser - +var select = require('xpath').select function nodeExists(test, doc, xpath) { if (!doc && !xpath) return - var node = select(doc, xpath) + var node = select(xpath, doc) test.ok(node.length==1, "xpath " + xpath + " not found") }