Skip to content

Commit

Permalink
remove nodeunit
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan committed Jun 5, 2023
1 parent f5a96c4 commit b96aa08
Show file tree
Hide file tree
Showing 77 changed files with 96 additions and 2,833 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"prettier-format": "prettier --config .prettierrc.json --write .",
"prerelease": "git clean -xfd && npm ci && npm test",
"release": "release-it",
"test": "nodeunit ./test/canonicalization-unit-tests.js ./test/c14nWithComments-unit-tests.js ./test/signature-unit-tests.js ./test/saml-response-test.js ./test/signature-integration-tests.js ./test/document-test.js ./test/wsfed-metadata-test.js ./test/hmac-tests.js ./test/c14n-non-exclusive-unit-test.js"
"test": "jasmine"
},
"dependencies": {
"@xmldom/xmldom": "^0.8.5",
Expand All @@ -44,7 +44,6 @@
"eslint": "^8.41.0",
"eslint-config-prettier": "^8.8.0",
"jasmine": "^5.0.0",
"nodeunit": "^0.11.3",
"prettier": "^2.8.8",
"prettier-plugin-packagejson": "^2.4.3",
"release-it": "^15.6.0"
Expand Down
8 changes: 4 additions & 4 deletions spec/document-test.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var fs = require("fs");
describe("Document tests", function () {

it("test with a document (using FileKeyInfo)", function () {
var xml = fs.readFileSync("./test/static/valid_saml.xml", "utf-8");
var xml = fs.readFileSync("./spec/static/valid_saml.xml", "utf-8");
var doc = new xmldom.DOMParser().parseFromString(xml);
var signature = new xmldom.DOMParser().parseFromString(
xpath
Expand All @@ -17,15 +17,15 @@ describe("Document tests", function () {
.toString()
);
var sig = new crypto.SignedXml();
sig.keyInfoProvider = new crypto.FileKeyInfo("./test/static/feide_public.pem");
sig.keyInfoProvider = new crypto.FileKeyInfo("./spec/static/feide_public.pem");
sig.loadSignature(signature);
var result = sig.checkSignature(xml);

expect(result).toBe(true);
});

it("test with a document (using StringKeyInfo)", function () {
var xml = fs.readFileSync("./test/static/valid_saml.xml", "utf-8");
var xml = fs.readFileSync("./spec/static/valid_saml.xml", "utf-8");
var doc = new xmldom.DOMParser().parseFromString(xml);
var signature = new xmldom.DOMParser().parseFromString(
xpath
Expand All @@ -36,7 +36,7 @@ describe("Document tests", function () {
.toString()
);
var sig = new crypto.SignedXml();
var feidePublicCert = fs.readFileSync("./test/static/feide_public.pem");
var feidePublicCert = fs.readFileSync("./spec/static/feide_public.pem");
sig.keyInfoProvider = new crypto.StringKeyInfo(feidePublicCert);
sig.loadSignature(signature);
var result = sig.checkSignature(xml);
Expand Down
12 changes: 6 additions & 6 deletions spec/hmac-tests.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@ describe("HMAC tests", function () {
});

it("test validating HMAC signature", function () {
var xml = fs.readFileSync("./test/static/hmac_signature.xml", "utf-8");
var xml = fs.readFileSync("./spec/static/hmac_signature.xml", "utf-8");
var doc = new xmldom.DOMParser().parseFromString(xml);
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.keyInfoProvider = new crypto.FileKeyInfo("./spec/static/hmac.key");
sig.loadSignature(signature);
var result = sig.checkSignature(xml);

expect(result).toBe(true);
});

it("test HMAC signature with incorrect key", function () {
var xml = fs.readFileSync("./test/static/hmac_signature.xml", "utf-8");
var xml = fs.readFileSync("./spec/static/hmac_signature.xml", "utf-8");
var doc = new xmldom.DOMParser().parseFromString(xml);
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.keyInfoProvider = new crypto.FileKeyInfo("./spec/static/hmac-foobar.key");
sig.loadSignature(signature);
var result = sig.checkSignature(xml);

Expand All @@ -49,7 +49,7 @@ describe("HMAC tests", function () {
it("test create and validate HMAC signature", function () {
var xml = "<library>" + "<book>" + "<name>Harry Potter</name>" + "</book>" + "</library>";
var sig = new crypto.SignedXml();
sig.signingKey = fs.readFileSync("./test/static/hmac.key");
sig.signingKey = fs.readFileSync("./spec/static/hmac.key");
sig.signatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#hmac-sha1";
sig.addReference("//*[local-name(.)='book']");
sig.computeSignature(xml);
Expand All @@ -60,7 +60,7 @@ describe("HMAC tests", function () {
doc
)[0];
var verify = new crypto.SignedXml();
verify.keyInfoProvider = new crypto.FileKeyInfo("./test/static/hmac.key");
verify.keyInfoProvider = new crypto.FileKeyInfo("./spec/static/hmac.key");
verify.loadSignature(signature);
var result = verify.checkSignature(sig.getSignedXml());

Expand Down
20 changes: 10 additions & 10 deletions spec/saml-response-test.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@ var fs = require("fs");
describe("SAML response tests", function () {

it("test validating SAML response", function () {
var xml = fs.readFileSync("./test/static/valid_saml.xml", "utf-8");
var xml = fs.readFileSync("./spec/static/valid_saml.xml", "utf-8");
var doc = new xmldom.DOMParser().parseFromString(xml);
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.keyInfoProvider = new crypto.FileKeyInfo("./spec/static/feide_public.pem");
sig.loadSignature(signature);
var result = sig.checkSignature(xml);

expect(result).toBe(true);
});

it("test validating wrapped assertion signature", function () {
var xml = fs.readFileSync("./test/static/valid_saml_signature_wrapping.xml", "utf-8");
var xml = fs.readFileSync("./spec/static/valid_saml_signature_wrapping.xml", "utf-8");
var doc = new xmldom.DOMParser().parseFromString(xml);
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.keyInfoProvider = new crypto.FileKeyInfo("./spec/static/feide_public.pem");
sig.loadSignature(signature);
expect(function () {sig.checkSignature(xml)})
.withContext("Should not validate a document which contains multiple elements with the " +
Expand All @@ -40,44 +40,44 @@ describe("SAML response tests", function () {

it("test validating SAML response where a namespace is defined outside the signed element",
function () {
var xml = fs.readFileSync("./test/static/saml_external_ns.xml", "utf-8");
var xml = fs.readFileSync("./spec/static/saml_external_ns.xml", "utf-8");
var doc = new xmldom.DOMParser().parseFromString(xml);
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.keyInfoProvider = new crypto.FileKeyInfo("./spec/static/saml_external_ns.pem");
sig.loadSignature(signature);
var result = sig.checkSignature(xml);
expect(result).toBe(true);
});

it("test reference id does not contain quotes", function () {
var xml = fs.readFileSync("./test/static/id_with_quotes.xml", "utf-8");
var xml = fs.readFileSync("./spec/static/id_with_quotes.xml", "utf-8");
var doc = new xmldom.DOMParser().parseFromString(xml);
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.keyInfoProvider = new crypto.FileKeyInfo("./spec/static/feide_public.pem");
sig.loadSignature(signature);
expect(function () {sig.checkSignature(xml)})
.withContext("id should not contain quotes")
.toThrow();
});

it("test validating SAML response WithComments", function () {
var xml = fs.readFileSync("./test/static/valid_saml_withcomments.xml", "utf-8");
var xml = fs.readFileSync("./spec/static/valid_saml_withcomments.xml", "utf-8");
var doc = new xmldom.DOMParser().parseFromString(xml);
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.keyInfoProvider = new crypto.FileKeyInfo("./spec/static/feide_public.pem");
sig.loadSignature(signature);
var result = sig.checkSignature(xml);
// This doesn't matter, just want to make sure that we don't fail due to unknown algorithm
Expand Down
30 changes: 15 additions & 15 deletions spec/signature-integration-tests.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe("Signature integration tests", function () {
it("verify signature", function () {
var xml =
'<root><x xmlns="ns"></x><y z_attr="value" a_attr1="foo"></y><z><ns:w ns:attr="value" xmlns:ns="myns"></ns:w></z></root>';
verifySignature(xml, "./test/static/integration/expectedVerify.xml", [
verifySignature(xml, "./spec/static/integration/expectedVerify.xml", [
"//*[local-name(.)='x']",
"//*[local-name(.)='y']",
"//*[local-name(.)='w']",
Expand All @@ -27,7 +27,7 @@ describe("Signature integration tests", function () {
"</book>" +
"</library>";

verifySignature(xml, "./test/static/integration/expectedVerifyComplex.xml", [
verifySignature(xml, "./spec/static/integration/expectedVerifyComplex.xml", [
"//*[local-name(.)='book']",
]);
});
Expand All @@ -52,15 +52,15 @@ describe("Signature integration tests", function () {
"</Signature>";

var sig = new crypto.SignedXml();
sig.keyInfoProvider = new crypto.FileKeyInfo("./test/static/client_public.pem");
sig.keyInfoProvider = new crypto.FileKeyInfo("./spec/static/client_public.pem");
sig.loadSignature(signature);
var result = sig.checkSignature(xml);

expect(result).toBe(true);
});

it("add canonicalization if output of transforms will be a node-set rather than an octet stream", function () {
var xml = fs.readFileSync("./test/static/windows_store_signature.xml", "utf-8");
var xml = fs.readFileSync("./spec/static/windows_store_signature.xml", "utf-8");

// Make sure that whitespace in the source document is removed -- see xml-crypto issue #23 and post at
// http://webservices20.blogspot.co.il/2013/06/validating-windows-mobile-app-store.html
Expand All @@ -76,15 +76,15 @@ describe("Signature integration tests", function () {
doc
)[0];
var sig = new crypto.SignedXml();
sig.keyInfoProvider = new crypto.FileKeyInfo("./test/static/windows_store_certificate.pem");
sig.keyInfoProvider = new crypto.FileKeyInfo("./spec/static/windows_store_certificate.pem");
sig.loadSignature(signature);
var result = sig.checkSignature(xml);

expect(result).toBe(true);
});

it("signature with inclusive namespaces", function () {
var xml = fs.readFileSync("./test/static/signature_with_inclusivenamespaces.xml", "utf-8");
var xml = fs.readFileSync("./spec/static/signature_with_inclusivenamespaces.xml", "utf-8");
var doc = new Dom().parseFromString(xml);
xml = doc.firstChild.toString();

Expand All @@ -94,7 +94,7 @@ describe("Signature integration tests", function () {
)[0];
var sig = new crypto.SignedXml();
sig.keyInfoProvider = new crypto.FileKeyInfo(
"./test/static/signature_with_inclusivenamespaces.pem"
"./spec/static/signature_with_inclusivenamespaces.pem"
);
sig.loadSignature(signature);
var result = sig.checkSignature(xml);
Expand All @@ -104,7 +104,7 @@ describe("Signature integration tests", function () {

it("signature with inclusive namespaces with unix line separators", function () {
var xml = fs.readFileSync(
"./test/static/signature_with_inclusivenamespaces_lines.xml",
"./spec/static/signature_with_inclusivenamespaces_lines.xml",
"utf-8"
);
var doc = new Dom().parseFromString(xml);
Expand All @@ -116,7 +116,7 @@ describe("Signature integration tests", function () {
)[0];
var sig = new crypto.SignedXml();
sig.keyInfoProvider = new crypto.FileKeyInfo(
"./test/static/signature_with_inclusivenamespaces.pem"
"./spec/static/signature_with_inclusivenamespaces.pem"
);
sig.loadSignature(signature);
var result = sig.checkSignature(xml);
Expand All @@ -126,7 +126,7 @@ describe("Signature integration tests", function () {

it("signature with inclusive namespaces with windows line separators", function () {
var xml = fs.readFileSync(
"./test/static/signature_with_inclusivenamespaces_lines_windows.xml",
"./spec/static/signature_with_inclusivenamespaces_lines_windows.xml",
"utf-8"
);
var doc = new Dom().parseFromString(xml);
Expand All @@ -138,7 +138,7 @@ describe("Signature integration tests", function () {
)[0];
var sig = new crypto.SignedXml();
sig.keyInfoProvider = new crypto.FileKeyInfo(
"./test/static/signature_with_inclusivenamespaces.pem"
"./spec/static/signature_with_inclusivenamespaces.pem"
);
sig.loadSignature(signature);
var result = sig.checkSignature(xml);
Expand All @@ -151,7 +151,7 @@ describe("Signature integration tests", function () {

var sig = new SignedXml();
sig.addReference("//*[local-name(.)='book']");
sig.signingKey = fs.readFileSync("./test/static/client.pem");
sig.signingKey = fs.readFileSync("./spec/static/client.pem");
sig.computeSignature(xml);

var signed = sig.getSignedXml();
Expand Down Expand Up @@ -189,7 +189,7 @@ describe("Signature integration tests", function () {

function verifySignature(xml, expected, xpath) {
var sig = new SignedXml();
sig.signingKey = fs.readFileSync("./test/static/client.pem");
sig.signingKey = fs.readFileSync("./spec/static/client.pem");
sig.keyInfo = null;

xpath.map(function (n) {
Expand All @@ -199,12 +199,12 @@ function verifySignature(xml, expected, xpath) {
sig.computeSignature(xml);
var signed = sig.getSignedXml();

//fs.writeFileSync("./test/validators/XmlCryptoUtilities/XmlCryptoUtilities/bin/Debug/signedExample.xml", signed)
//fs.writeFileSync("./spec/validators/XmlCryptoUtilities/XmlCryptoUtilities/bin/Debug/signedExample.xml", signed)
var expectedContent = fs.readFileSync(expected).toString();
expect(signed).withContext("signature xml different than expected").toEqual(expectedContent);
/*
var spawn = require('child_process').spawn
var proc = spawn('./test/validators/XmlCryptoUtilities/XmlCryptoUtilities/bin/Debug/XmlCryptoUtilities.exe', ['verify'])
var proc = spawn('./spec/validators/XmlCryptoUtilities/XmlCryptoUtilities/bin/Debug/XmlCryptoUtilities.exe', ['verify'])
proc.stdout.on('data', function (data) {
console.log('stdout: ' + data);
Expand Down
Loading

0 comments on commit b96aa08

Please sign in to comment.