Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Nodeunit with Mocha #294

Merged
merged 14 commits into from
Jun 6, 2023
Merged

Replace Nodeunit with Mocha #294

merged 14 commits into from
Jun 6, 2023

Conversation

shunkica
Copy link
Contributor

@shunkica shunkica commented Jun 5, 2023

No description provided.

@shunkica
Copy link
Contributor Author

shunkica commented Jun 5, 2023

Hm... The tests are failing because Node.JS 12.17+ is required for Jasmine.

Ivan and others added 2 commits June 5, 2023 12:47
@cjbarth
Copy link
Contributor

cjbarth commented Jun 5, 2023

I'm sorry @shunkica , I was working on another project that used Jasmine, this org uses Mocha. I've pushed a change to support Mocha. Thank you for your hard work!

@cjbarth
Copy link
Contributor

cjbarth commented Jun 5, 2023

Hm... The tests are failing because Node.JS 12.17+ is required for Jasmine.

@LoneRifle , this is going to be an ever bigger problem going forward. I suggest that we read this and decide what we'd like to do. I'm all for supporting lts/-2, but I don't like the idea of staying farther back than that. Thoughts?

@cjbarth cjbarth changed the title Replace Nodeunit with Jasmine Replace Nodeunit with Mocha Jun 5, 2023
@LoneRifle
Copy link
Collaborator

@cjbarth I concur; I took the trouble to look at NodeJS' download metrics. It is worth noting that most downloads in the past two years or so are limited to lts/-2, thereabouts.

My only concern is within enterprise organisations, which tend to have very long change management cycles to bring in new software releases and hence a tendency to have very old releases of Node. But considering the number of security vulnerabilities found in older releases, perhaps these organisations would have moved quicker to get to newer ones.

@cjbarth
Copy link
Contributor

cjbarth commented Jun 6, 2023

Reviewing this code is very difficult. I'm going to avoid the rename for the first pass, review it, land it, and then do a file rename.

@cjbarth
Copy link
Contributor

cjbarth commented Jun 6, 2023

For reference, here is the log of tests from nodeunit. There are 232 assertions, so after the refactor, there should be 232 assertions, unless we have a clear reason why not.

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


canonicalization-unit-tests.js
✔ Exclusive canonicalization works on xml with no namespaces
✔ Exclusive canonicalization works on inner xpath
✔ Exclusive canonicalization works on xml with prefixed namespaces defined in output nodes
✔ element used prefixed ns which is also the default
✔ Exclusive canonicalization works with default namespace for prefix
✔ Exclusive canonicalization works on xml with prefixed namespaces defined in output nodes. ns definition is not duplicated on each usage
✔ Exclusive canonicalization works on xml with prefixed namespaces defined in output nodes but before used
✔ Exclusive canonicalization works on xml with prefixed namespaces defined outside output nodes
✔ Exclusive canonicalization works on xml with prefixed namespace defined in inclusive list
✔ Exclusive canonicalization works on xml with multiple prefixed namespaces defined in inclusive list
✔ Exclusive canonicalization works on xml with prefixed namespace defined in inclusive list defined outside output nodes
✔ Exclusive canonicalization works on xml with prefixed namespace defined in inclusive list used on attribute
✔ Exclusive canonicalization works on xml with default namespace inside output nodes
✔ Exclusive canonicalization works on xml with multiple different default namespaces
✔ Exclusive canonicalization works on xml with multiple similar default namespaces
✔ Exclusive canonicalization works on xml with default namespace outside output nodes
✔ Exclusive canonicalization works when prefixed namespace is defined in output nodes not in the parent chain of who needs it
✔ Exclusive canonicalization works on xml with unordered attributes
✔ Exclusive canonicalization sorts upper case attributes before lower case
✔ Exclusive canonicalization removes Comments
✔ Exclusive canonicalization works on xml with attributes with different namespace than element
✔ Exclusive canonicalization works on xml with attribute values with special characters
✔ Exclusive canonicalization does not normalize whitespace characters into single spaces
✔ Exclusive canonicalization works on xml with element values with special characters
✔ Exclusive canonicalization preserves white space in values
✔ Exclusive canonicalization does not alter CR-NL (windows line separator) sequences
✔ Exclusive canonicalization preserves and encodes CR white space
✔ Exclusive canonicalization preserves white space between elements
✔ Exclusive canonicalization turns empty element to start-end tag pairs
✔ Exclusive canonicalization preserves empty start-end tag pairs
✔ Exclusive canonicalization with empty default namespace outside output nodes
✔ Exclusive canonicalization with empty default namespace inside output nodes
✔ The XML declaration and document type declaration (DTD) are removed
✔ Attribute value delimiters are set to quotation marks (double quotes)
✔ CDATA sections are replaced with their character content
✔ SignedInfo canonization
✔ Exclusive canonicalization works on complex xml
✔ Multiple Canonicalization with namespace definition outside of signed element
✔ Enveloped-signature canonicalization respects currentnode
✔ The XML canonicalization method processes a node-set by imposing the following additional document order rules on the namespace and attribute nodes of each element:   - An element's namespace and attribute nodes have a document order position greater than the element but less than any child node of the element.     Namespace nodes have a lesser document order position than attribute nodes.   - An element's namespace nodes are sorted lexicographically by local name (the default namespace node, if one exists, has no local name and is therefore lexicographically least).   - An element's attribute nodes are sorted lexicographically with namespace URI as the primary key and local name as the secondary key (an empty namespace URI is lexicographically least).     Lexicographic comparison, which orders strings from least to greatest alphabetically, is based on the UCS codepoint values, which is equivalent to lexicographic ordering based on UTF-8.
✔ saml attributed order (bug #25)
✔ Body Xml Element Canonicalization
✔ Overriding namespace in canonicalization

c14nWithComments-unit-tests.js
✔ Exclusive canonicalization works on xml with no namespaces
✔ Exclusive canonicalization works on inner xpath
✔ Exclusive canonicalization works on xml with prefixed namespaces defined in output nodes
✔ element used prefixed ns which is also the default
✔ Exclusive canonicalization works on xml with prefixed namespaces defined in output nodes. ns definition is not duplicated on each usage
✔ Exclusive canonicalization works on xml with prefixed namespaces defined in output nodes but before used
✔ Exclusive canonicalization works on xml with prefixed namespaces defined outside output nodes
✔ Exclusive canonicalization works on xml with prefixed namespace defined in inclusive list
✔ Exclusive canonicalization works on xml with multiple prefixed namespaces defined in inclusive list
✔ Exclusive canonicalization works on xml with prefixed namespace defined in inclusive list defined outside output nodes
✔ Exclusive canonicalization works on xml with prefixed namespace defined in inclusive list used on attribute
✔ Exclusive canonicalization works on xml with default namespace inside output nodes
✔ Exclusive canonicalization works on xml with multiple different default namespaces
✔ Exclusive canonicalization works on xml with multiple similar default namespaces
✔ Exclusive canonicalization works on xml with default namespace outside output nodes
✔ Exclusive canonicalization works when prefixed namespace is defined in output nodes not in the parent chain of who needs it
✔ Exclusive canonicalization works on xml with unordered attributes
✔ Exclusive canonicalization sorts upper case attributes before lower case
✔ C14N#WithComments retains Comments
✔ Exclusive canonicalization works on xml with attributes with different namespace than element
✔ Exclusive canonicalization works on xml with attribute and element values with special characters
✔ Exclusive canonicalization preserves white space in values
✔ Exclusive canonicalization preserves white space between elements
✔ Exclusive canonicalization turns empty element to start-end tag pairs
✔ Exclusive canonicalization preserves empty start-end tag pairs
✔ Exclusive canonicalization with empty default namespace outside output nodes
✔ Exclusive canonicalization with empty default namespace inside output nodes
✔ The XML declaration and document type declaration (DTD) are removed
✔ Attribute value delimiters are set to quotation marks (double quotes)
✔ CDATA sections are replaced with their character content
✔ SignedInfo canonization
✔ Exclusive canonicalization works on complex xml
✔ Multiple Canonicalization with namespace definition outside of signed element
✔ Enveloped-signature canonicalization respects currentnode
✔ The XML canonicalization method processes a node-set by imposing the following additional document order rules on the namespace and attribute nodes of each element:   - An element's namespace and attribute nodes have a document order position greater than the element but less than any child node of the element.     Namespace nodes have a lesser document order position than attribute nodes.   - An element's namespace nodes are sorted lexicographically by local name (the default namespace node, if one exists, has no local name and is therefore lexicographically least).   - An element's attribute nodes are sorted lexicographically with namespace URI as the primary key and local name as the secondary key (an empty namespace URI is lexicographically least).     Lexicographic comparison, which orders strings from least to greatest alphabetically, is based on the UCS codepoint values, which is equivalent to lexicographic ordering based on UTF-8.
✔ saml attributed order (bug #25)

signature-unit-tests.js
✔ signer adds increasing id attributes to elements
✔ signer adds references with namespaces
✔ signer does not duplicate existing id attributes
✔ signer adds custom attributes to the signature root node
✔ signer appends signature to the root node by default
✔ signer appends signature to a reference node
✔ signer prepends signature to a reference node
✔ signer inserts signature before a reference node
✔ signer inserts signature after a reference node
✔ signer creates signature with correct structure
✔ signer creates signature with correct structure (with prefix)
✔ signer creates correct signature values
✔ signer creates correct signature values using async callback
✔ correctly loads signature
✔ verify valid signature
✔ fail invalid signature
✔ allow empty reference uri when signing
✔ signer appends signature to a non-existing reference node
✔ signer adds existing prefixes
✔ creates InclusiveNamespaces element when inclusiveNamespacesPrefixList is set on Reference
✔ does not create InclusiveNamespaces element when inclusiveNamespacesPrefixList is not set on Reference
✔ creates InclusiveNamespaces element inside CanonicalizationMethod when inclusiveNamespacesPrefixList is set on SignedXml options
✔ does not create InclusiveNamespaces element inside CanonicalizationMethod when inclusiveNamespacesPrefixList is not set on SignedXml options
✔ adds attributes to KeyInfo element when attrs are present in keyInfoProvider

saml-response-test.js
✔ test validating SAML response
✔ test validating wrapped assertion signature
✔ test validating SAML response where a namespace is defined outside the signed element
✔ test reference id does not contain quotes
✔ test validating SAML response WithComments

signature-integration-tests.js
✔ verify signature
✔ verify signature of complex element
✔ empty URI reference should consider the whole document
✔ add canonicalization if output of transforms will be a node-set rather than an octet stream
✔ signature with inclusive namespaces
✔ signature with inclusive namespaces with unix line separators
✔ signature with inclusive namespaces with windows line separators
✔ should create single root xml document when signing inner node

document-test.js
✔ test with a document (using FileKeyInfo)
✔ test with a document (using StringKeyInfo)

wsfed-metadata-test.js
✔ test validating WS-Fed Metadata

hmac-tests.js
✔ test validating HMAC signature
✔ test HMAC signature with incorrect key
✔ test create and validate HMAC signature

c14n-non-exclusive-unit-test.js
✔ findAncestorNs: Correctly picks up root ancestor namespace
✔ findAncestorNs: Correctly picks up intermediate ancestor namespace
✔ findAncestorNs: Correctly picks up multiple ancestor namespaces declared in the one same element
✔ findAncestorNs: Correctly picks up multiple ancestor namespaces scattered among depth
✔ findAncestorNs: Correctly picks up multiple ancestor namespaces without duplicate
✔ findAncestorNs: Correctly eliminates duplicate prefix
✔ findAncestorNs: Exclude namespace which is already declared with same prefix on target node
✔ findAncestorNs: Ignores namespace declared in the target xpath node
✔ C14n: Correctly picks up root ancestor namespace
✔ C14n: Correctly picks up intermediate ancestor namespace
✔ C14n: Correctly picks up multiple ancestor namespaces declared in the one same element
✔ C14n: Correctly picks up multiple ancestor namespaces scattered among depth
✔ C14n: Correctly picks up multiple ancestor namespaces without duplicate
✔ C14n: Correctly eliminates duplicate prefix
✔ C14n: Exclude namespace which is already declared with same prefix on target node
✔ C14n: Preserve namespace declared in the target xpath node
✔ C14n: Don't redeclare an attribute's namespace prefix if already in scope
✔ C14n: Don't declare an attribute's namespace prefix if in scope from parent

OK: 232 assertions (1031ms)

@shunkica
Copy link
Contributor Author

shunkica commented Jun 6, 2023

You would need something like this to count the number of assertions made
I have not tested it.

Edit:
The plugin doesn't work for me, but I have made a quick and dirty hack to chai/interface/expect.js and have confirmed there were 232 assertions made.

var expects = 0;
module.exports = function (chai, util) {
  chai.expect = function (val, message) {
    console.log(++expects);
    return new chai.Assertion(val, message);
  };
  ...
230
    √ Attribute value delimiters are set to quotation marks (double quotes)
231
    √ Exclusive canonicalization works on xml with element values with special characters
232
    √ Overriding namespace in canonicalization


  140 passing (301ms)

cjbarth
cjbarth previously approved these changes Jun 6, 2023
Copy link
Contributor

@cjbarth cjbarth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the tests look like they were ported without any changes.

@cjbarth cjbarth merged commit 5a1ac33 into node-saml:master Jun 6, 2023
@cjbarth cjbarth added the chore label Jun 6, 2023
@shunkica shunkica deleted the jasmine branch June 7, 2023 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants