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

Internal audit improvements #30

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions tests/asymmetric.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,23 @@ describe("Symmetric encryption", () => {
const ciphertext1 = encrypt(bytes, bob.publicKey);
const ciphertext2 = encrypt("Hello world", bob.publicKey);

// ok
expect(() => decryptBytes(ciphertext1, bob)).not.toThrow();
expect(() => decryptString(ciphertext2, bob)).not.toThrow();

expect(() => decryptBytes(ciphertext1, cindy)).toThrow();
expect(() => decryptString(ciphertext2, cindy)).toThrow();
// ko
try {
decryptBytes(ciphertext1, cindy);
throw new Error("Should have thrown but didn't");
} catch (err: any) {
expect(err.message).toBe("incorrect key pair for the given ciphertext");
}

try {
decryptString(ciphertext2, cindy);
throw new Error("Should have thrown but didn't");
} catch (err: any) {
expect(err.message).toBe("incorrect key pair for the given ciphertext");
}
});
});
14 changes: 10 additions & 4 deletions tests/proposal-encryption.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,12 @@ describe("Proposal data encryption", () => {
}).not.toThrow();

for (const otherKey of otherKeys) {
expect(() => {
try {
decryptProposal(data, otherKey);
}).toThrow();
throw new Error("Should have thrown but didn't");
} catch (err: any) {
expect(err.message).toBe("wrong secret key for the given ciphertext");
}
}
});
});
Expand Down Expand Up @@ -150,9 +153,12 @@ describe("Symmetric key encryption across members", () => {
);

for (let i = 0; i < encryptedItems.length; i++) {
expect(() => {
try {
decryptSymmetricKey(encryptedItems, intruders[i]);
}).toThrow();
throw new Error("Should have thrown but didn't");
} catch (err: any) {
expect(err.message).toBe("The given keypair cannot decrypt any of the ciphertext's");
}
}

for (let i = 0; i < encryptedItems.length; i++) {
Expand Down
15 changes: 13 additions & 2 deletions tests/symmetric.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,18 @@ describe("Symmetric encryption", () => {
expect(() => decryptBytes(encryptedPayload1, symKey)).not.toThrow();
expect(() => decryptString(encryptedPayload2, symKey)).not.toThrow();

expect(() => decryptBytes(encryptedPayload1, wrongKey)).toThrow();
expect(() => decryptString(encryptedPayload2, wrongKey)).toThrow();
try {
decryptBytes(encryptedPayload1, wrongKey);
throw new Error("Should have thrown but didn't");
} catch (err: any) {
expect(err.message).toBe("wrong secret key for the given ciphertext");
}

try {
decryptString(encryptedPayload2, wrongKey);
throw new Error("Should have thrown but didn't");
} catch (err: any) {
expect(err.message).toBe("wrong secret key for the given ciphertext");
}
});
});
Loading