-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for directly querying a node to see if it has passed vali…
…dation (#389)
- Loading branch information
Showing
4 changed files
with
132 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,3 +41,74 @@ describe("Document tests", function () { | |
expect(result).to.be.true; | ||
}); | ||
}); | ||
|
||
describe("Validated node references tests", function () { | ||
it("should return references if the document is validly signed", function () { | ||
const xml = fs.readFileSync("./test/static/valid_saml.xml", "utf-8"); | ||
const doc = new xmldom.DOMParser().parseFromString(xml); | ||
const sig = new SignedXml(); | ||
sig.loadSignature(sig.findSignatures(doc)[0]); | ||
const validSignature = sig.checkSignature(xml); | ||
expect(validSignature).to.be.true; | ||
|
||
const ref = sig.getReferences()[0]; | ||
const result = ref.getValidatedNode(); | ||
expect(result?.toString()).to.equal(doc.toString()); | ||
}); | ||
|
||
it("should not return references if the document is not validly signed", function () { | ||
const xml = fs.readFileSync("./test/static/invalid_signature - changed content.xml", "utf-8"); | ||
const doc = new xmldom.DOMParser().parseFromString(xml); | ||
const sig = new SignedXml(); | ||
sig.loadSignature(sig.findSignatures(doc)[0]); | ||
const validSignature = sig.checkSignature(xml); | ||
expect(validSignature).to.be.false; | ||
|
||
const ref = sig.getReferences()[1]; | ||
const result = ref.getValidatedNode(); | ||
expect(result).to.be.null; | ||
}); | ||
|
||
it("should return `null` if the selected node isn't found", function () { | ||
const xml = fs.readFileSync("./test/static/valid_saml.xml", "utf-8"); | ||
const doc = new xmldom.DOMParser().parseFromString(xml); | ||
const sig = new SignedXml(); | ||
sig.loadSignature(sig.findSignatures(doc)[0]); | ||
const validSignature = sig.checkSignature(xml); | ||
expect(validSignature).to.be.true; | ||
|
||
const ref = sig.getReferences()[0]; | ||
const result = ref.getValidatedNode("/non-existent-node"); | ||
expect(result).to.be.null; | ||
}); | ||
|
||
it("should return the selected node if it is validly signed", function () { | ||
const xml = fs.readFileSync("./test/static/valid_saml.xml", "utf-8"); | ||
const doc = new xmldom.DOMParser().parseFromString(xml); | ||
const sig = new SignedXml(); | ||
sig.loadSignature(sig.findSignatures(doc)[0]); | ||
const validSignature = sig.checkSignature(xml); | ||
expect(validSignature).to.be.true; | ||
|
||
const ref = sig.getReferences()[0]; | ||
const result = ref.getValidatedNode( | ||
"//*[local-name()='Attribute' and @Name='mail']/*[local-name()='AttributeValue']/text()", | ||
); | ||
expect(result?.nodeValue).to.equal("[email protected]"); | ||
}); | ||
|
||
it("should return `null` if the selected node isn't validly signed", function () { | ||
const xml = fs.readFileSync("./test/static/invalid_signature - changed content.xml", "utf-8"); | ||
const doc = new xmldom.DOMParser().parseFromString(xml); | ||
const sig = new SignedXml(); | ||
sig.loadSignature(sig.findSignatures(doc)[0]); | ||
const validSignature = sig.checkSignature(xml); | ||
expect(validSignature).to.be.false; | ||
|
||
const ref = sig.getReferences()[0]; | ||
const result = ref.getValidatedNode( | ||
"//*[local-name()='Attribute' and @Name='mail']/*[local-name()='AttributeValue']/text()", | ||
); | ||
expect(result).to.be.null; | ||
}); | ||
}); |