Skip to content

Commit ee0beef

Browse files
committed
refactor: Algorithms constant, fix test, fix examples
1 parent 994f15e commit ee0beef

File tree

5 files changed

+5
-19
lines changed

5 files changed

+5
-19
lines changed

example/new-api-example.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const fs = require("fs");
22
const { XmlSignerFactory, XmlDSigValidator, Algorithms, pemToDer } = require("../lib/index");
33

4-
54
// Example XML to sign
65
const xml = `<root>
76
<data id="data1">Hello World</data>

src/algorithms.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ export const Algorithms = {
4141
transform: TRANSFORM_ALGORITHMS,
4242
hash: HASH_ALGORITHMS,
4343
signature: SIGNATURE_ALGORITHMS,
44-
}
44+
};

src/signed-xml.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ export class SignedXml {
556556
if (this.idAttributeQNames) {
557557
// idAttributeQNames supersede idAttributes
558558
for (const qName of this.idAttributeQNames) {
559-
const [prefix, localName, namespaceURI] = utils.resolveQName(qName, this.namespaceMap);
559+
const [, localName, namespaceURI] = utils.resolveQName(qName, this.namespaceMap);
560560
let tmp_elemXpath: string;
561561
if (namespaceURI) {
562562
tmp_elemXpath = `//*[@*[local-name(.)='${localName}' and namespace-uri(.)='${namespaceURI}']='${uri}']`;
@@ -571,8 +571,8 @@ export class SignedXml {
571571
if (num_elements_for_id > 1) {
572572
throw new Error(
573573
"Cannot validate a document which contains multiple elements with the " +
574-
"same value for the ID / Id / Id attributes, in order to prevent " +
575-
"signature wrapping attack.",
574+
"same value for the ID / Id / Id attributes, in order to prevent " +
575+
"signature wrapping attack.",
576576
);
577577
}
578578

src/xmldsig-validator.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { KeyLike } from "crypto";
22
import { DOMParser } from "@xmldom/xmldom";
33
import { SignedXml } from "./signed-xml";
4-
import { BaseOptions } from "node:vm";
54

65
const DEFAULT_ID_ATTRIBUTES = ["Id", "ID", "id"];
76
const DEFAULT_MAX_TRANSFORMS = 4;

test/xml-validator.spec.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,8 @@ describe("XmlValidator", function () {
9494
});
9595
expect(validator).to.be.instanceOf(XmlDSigValidator);
9696
});
97-
98-
it("should throw error when neither publicCert nor getCertFromKeyInfo is provided", function () {
99-
expect(() => {
100-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
101-
new XmlDSigValidator({} as any);
102-
}).to.throw(
103-
"XmlValidator requires either a publicCert or getCertFromKeyInfo function in options.",
104-
);
105-
});
10697
});
10798

108-
10999
describe("validate", function () {
110100
it("should validate a valid signed XML document", function () {
111101
const xml = "<root><test>content</test></root>";
@@ -181,7 +171,7 @@ describe("XmlValidator", function () {
181171
const signedXml = createSignedXml(xml);
182172

183173
const validator = new XmlDSigValidator({ publicCert });
184-
174+
185175
// First validation
186176
const result1 = validator.validate(signedXml);
187177
expect(result1.valid).to.be.true;
@@ -254,10 +244,8 @@ describe("XmlValidator", function () {
254244
expect(() => validator.validate(xml)).to.throw();
255245
});
256246
});
257-
258247
});
259248

260-
261249
describe("XmlValidator Security Features", function () {
262250
it("should prevent signature wrapping attacks by only returning signed content", function () {
263251
const xml = "<root><test>content</test><unsigned>malicious</unsigned></root>";

0 commit comments

Comments
 (0)