Added constructor check for buffers

This commit is contained in:
Alexander Cerutti
2021-11-14 00:42:14 +01:00
parent 3326fc29d7
commit 964be0802c
3 changed files with 30 additions and 7 deletions

View File

@@ -32,6 +32,18 @@ describe("PKPass", () => {
);
});
describe("constructor", () => {
it("should warn about a non-object buffer parameter", () => {
console.warn = jasmine.createSpy("warn");
pass = new PKPass(undefined, baseCerts);
expect(console.warn).toHaveBeenCalledWith(
Messages.INIT.INVALID_BUFFERS.replace("%s", "undefined"),
);
});
});
describe("setBeacons", () => {
it("should reset instance.props['beacons'] if 'null' is passed as value", () => {
pass.setBeacons({

View File

@@ -130,6 +130,7 @@ export default class PKPass extends Bundle {
) {
super("application/vnd.apple.pkpass");
if (buffers && typeof buffers === "object") {
const buffersEntries = Object.entries(buffers);
for (
@@ -140,6 +141,11 @@ export default class PKPass extends Bundle {
const [fileName, contentBuffer] = buffer;
this.addBuffer(fileName, contentBuffer);
}
} else {
console.warn(
Messages.format(Messages.INIT.INVALID_BUFFERS, typeof buffers),
);
}
if (props) {
/** Overrides validation and pushing in props */

View File

@@ -1,3 +1,8 @@
export const INIT = {
INVALID_BUFFERS:
"Cannot set buffers in constructor: expected object but received %s",
} as const;
export const CERTIFICATES = {
INVALID:
"Invalid certificate(s) loaded. %s. Please provide valid WWDR certificates and developer signer certificate and key (with passphrase).\nRefer to docs to obtain them",