Skip to content

Conversation

Abdullah-03
Copy link

Add appendElement option to WSSecurity, WSSecurityCert, and WSSecurityCertWithToken. When provided with an xml as a string it adds that to the end of the wsse header.

  • Introduced appendElement property in IWSSecurityOptions and IWSSecurityCertOptions interfaces.
  • Updated WSSecurity, WSSecurityCert, and WSSecurityCertWithToken classes to handle the new property.
  • Enhanced Readme.md to document the new feature.
  • Added tests to verify the functionality of appending custom XML elements.

@Abdullah-03
Copy link
Author

#1341

@w666
Copy link
Collaborator

w666 commented Sep 28, 2025

Seems like build is broken

appendElement: '<Certificate>Mfg...1+</Certificate>'
});
var xml = instance.postProcess('<soap:Envelope><soap:Header></soap:Header><soap:Body><Body></Body></soap:Body></soap:Envelope>', 'soap');
xml.should.containEql('<Certificate>Mfg...1+</Certificate>');
Copy link
Collaborator

Choose a reason for hiding this comment

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

how does the full XML look like? Maybe assert full one so it will provide better understanding of where new element is added?

it('should not add appendElement when not provided', function () {
var instance = new WSSecurityCert(key, cert, '');
var xml = instance.postProcess('<soap:Envelope><soap:Header></soap:Header><soap:Body><Body></Body></soap:Body></soap:Envelope>', 'soap');
xml.should.not.containEql('<Certificate>Mfg...1+</Certificate>');
Copy link
Collaborator

Choose a reason for hiding this comment

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

in this case assert full message would help as well.

Copy link
Author

Choose a reason for hiding this comment

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

I've decided to remove this test case as a full assertion made me realize this is redundant. With the default instantiation we are indirectly ensuring that there is no extra/custom element present in the WSSESecurity element.

See test case starting at line 38 for reference. That should do the same job (no custom element when one isn't provided in options as appendElement).

Readme.md Outdated
- `prefix`: (optional) Adds this value as a prefix for the generated signature tags.
- `attrs`: (optional) A hash of attributes and values attrName: value to add to the signature root node
- `idMode`: (optional) either 'wssecurity' to generate wsse-scoped reference Id on <Body> or undefined for an unscoped reference Id
- `appendElement`: (optional) A string containing XML to append to the end of the wsse:Security element. This can be used to add custom elements like certificates or other security tokens.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
- `appendElement`: (optional) A string containing XML to append to the end of the wsse:Security element. This can be used to add custom elements like certificates or other security tokens.
- `appendElement`: (optional) A string containing XML element to append to the end of the WSSecurity element. This can be used to add custom elements like certificates or other security tokens.

Readme.md Outdated
</SignedInfo>
</Signature>
<!-- Custom element is appended to the end of the security block -->
<custom:Element>test</custom:Element>
Copy link
Collaborator

Choose a reason for hiding this comment

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

<custom:MyCustomElement xmlns:custom="http://example.com/custom">
  foo
</custom:MyCustomElement>

probably better to follow spec and provide xml namespace declaration in the example

@w666
Copy link
Collaborator

w666 commented Sep 28, 2025

Also, project was recently converted to use prettier, there are new npm scripts npm run format and npm run format:check if you are not using prettier plugin in your IDE.

@Abdullah-03
Copy link
Author

Thanks for the feedback @w666. I'll do some refactoring and update the PR in a few days.

@Abdullah-03 Abdullah-03 force-pushed the feature/option-for-custom-xml-in-wsse branch from ac8f8bc to e4235f4 Compare September 29, 2025 18:22
@Abdullah-03 Abdullah-03 requested a review from w666 September 29, 2025 18:23
…lement'.

This allows user to pass a custom xml string that will be added to the Wsse Security element.
@Abdullah-03 Abdullah-03 force-pushed the feature/option-for-custom-xml-in-wsse branch from e4235f4 to f525051 Compare September 29, 2025 18:24
@w666
Copy link
Collaborator

w666 commented Oct 1, 2025

Hi, sorry, I stuck with another issue, will review this one as soon as I can.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants