mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-24 16:07:22 +02:00
Merge pull request #21543 from Snuffleupagus/FakeSignatureVerifier
Add a `FakeSignatureVerifier` for development mode and TESTING builds (PR 21247 follow-up)
This commit is contained in:
commit
6689097a0a
107
test/integration/digital_signature_spec.mjs
Normal file
107
test/integration/digital_signature_spec.mjs
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
/* Copyright 2026 Mozilla Foundation
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { closePages, FSI, loadAndWait, PDI } from "./test_utils.mjs";
|
||||||
|
|
||||||
|
describe("Digital signatures", () => {
|
||||||
|
describe("Document without signatures", () => {
|
||||||
|
let pages;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
pages = await loadAndWait("tracemonkey.pdf", ".textLayer .endOfContent");
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
await closePages(pages);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("check that the signatureProperties button is hidden", async () => {
|
||||||
|
await Promise.all(
|
||||||
|
pages.map(async ([browserName, page]) => {
|
||||||
|
const buttonHidden = await page.$eval(
|
||||||
|
"#signatureProperties",
|
||||||
|
el => el.hidden
|
||||||
|
);
|
||||||
|
expect(buttonHidden).withContext(`In ${browserName}`).toBeTrue();
|
||||||
|
|
||||||
|
const separatorHidden = await page.$eval(
|
||||||
|
"#signaturePropertiesSeparator",
|
||||||
|
el => el.hidden
|
||||||
|
);
|
||||||
|
expect(separatorHidden).withContext(`In ${browserName}`).toBeTrue();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Document with signatures", () => {
|
||||||
|
let pages;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
pages = await loadAndWait("issue20433.pdf", ".textLayer .endOfContent");
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
await closePages(pages);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("check that the signatureProperties button is visible", async () => {
|
||||||
|
await Promise.all(
|
||||||
|
pages.map(async ([browserName, page]) => {
|
||||||
|
const buttonHidden = await page.$eval(
|
||||||
|
"#signatureProperties",
|
||||||
|
el => el.hidden
|
||||||
|
);
|
||||||
|
expect(buttonHidden).withContext(`In ${browserName}`).toBeFalse();
|
||||||
|
|
||||||
|
const separatorHidden = await page.$eval(
|
||||||
|
"#signaturePropertiesSeparator",
|
||||||
|
el => el.hidden
|
||||||
|
);
|
||||||
|
expect(separatorHidden).withContext(`In ${browserName}`).toBeFalse();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("check that the signatureProperties panel contains two signatures", async () => {
|
||||||
|
await Promise.all(
|
||||||
|
pages.map(async ([browserName, page]) => {
|
||||||
|
await page.click("#signatureProperties");
|
||||||
|
await page.waitForSelector("#signaturePropertiesPanel", {
|
||||||
|
hidden: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
await page.waitForFunction(
|
||||||
|
`document.getElementById("signaturePropertiesBanner").textContent !== ""`
|
||||||
|
);
|
||||||
|
const bannerMsg = await page.$eval(
|
||||||
|
"#signaturePropertiesBanner",
|
||||||
|
el => el.textContent
|
||||||
|
);
|
||||||
|
expect(bannerMsg)
|
||||||
|
.withContext(`In ${browserName}`)
|
||||||
|
.toEqual(
|
||||||
|
`Document signed but ${FSI}2${PDI} digital signatures could not be verified`
|
||||||
|
);
|
||||||
|
|
||||||
|
await page.keyboard.press("Escape");
|
||||||
|
await page.waitForSelector("#signaturePropertiesPanel", {
|
||||||
|
hidden: true,
|
||||||
|
});
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -34,6 +34,7 @@ async function runTests(results) {
|
|||||||
"comment_spec.mjs",
|
"comment_spec.mjs",
|
||||||
"copy_paste_spec.mjs",
|
"copy_paste_spec.mjs",
|
||||||
"cursor_tools_spec.mjs",
|
"cursor_tools_spec.mjs",
|
||||||
|
"digital_signature_spec.mjs",
|
||||||
"document_properties_spec.mjs",
|
"document_properties_spec.mjs",
|
||||||
"find_spec.mjs",
|
"find_spec.mjs",
|
||||||
"freetext_editor_spec.mjs",
|
"freetext_editor_spec.mjs",
|
||||||
|
|||||||
@ -61,8 +61,7 @@ class BaseExternalServices {
|
|||||||
* Properties UI should subclass `BaseExternalServices` and return
|
* Properties UI should subclass `BaseExternalServices` and return
|
||||||
* an object exposing `verify(signature)` (and optionally
|
* an object exposing `verify(signature)` (and optionally
|
||||||
* `viewCertificate(certificate)`) that resolves to a
|
* `viewCertificate(certificate)`) that resolves to a
|
||||||
* `VerificationResult` — see `web/firefoxcom.js` for the exact
|
* `VerificationResult` — see `web/firefoxcom.js` for the exact shape.
|
||||||
* shape.
|
|
||||||
*
|
*
|
||||||
* @returns {Object|null}
|
* @returns {Object|null}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -66,6 +66,13 @@ class ExternalServices extends BaseExternalServices {
|
|||||||
createSignatureStorage(eventBus, signal) {
|
createSignatureStorage(eventBus, signal) {
|
||||||
return new SignatureStorage(eventBus, signal);
|
return new SignatureStorage(eventBus, signal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createSignatureVerifier() {
|
||||||
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
|
||||||
|
return new FakeSignatureVerifier();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MLManager {
|
class MLManager {
|
||||||
@ -166,6 +173,33 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
|
|||||||
this.enableGuessAltText = enabled;
|
this.enableGuessAltText = enabled;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-var
|
||||||
|
var FakeSignatureVerifier = class {
|
||||||
|
async verify(signature) {
|
||||||
|
if (signature.signatureType === null) {
|
||||||
|
return {
|
||||||
|
status: "unknown",
|
||||||
|
errorCode: "SUBFILTER_NOT_SUPPORTED",
|
||||||
|
message: signature.subFilter,
|
||||||
|
certificate: null,
|
||||||
|
documentModifiedAfterSigning: !signature.coversWholeDocument,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
status: "unknown",
|
||||||
|
errorCode: "EMPTY_RESPONSE",
|
||||||
|
message: null,
|
||||||
|
certificate: null,
|
||||||
|
documentModifiedAfterSigning: !signature.coversWholeDocument,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async viewCertificate(certificate) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export { ExternalServices, initCom, MLManager, Preferences };
|
export { ExternalServices, initCom, MLManager, Preferences };
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user