-
-
Notifications
You must be signed in to change notification settings - Fork 229
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
test(encryption): add backwards-compatibility-test for encrypt/decrypt #367
base: main
Are you sure you want to change the base?
Conversation
New dependencies detected. Learn more about Socket for GitHub ↗︎
|
abef015
to
7c59ecb
Compare
7c59ecb
to
0d8bbb2
Compare
}), | ||
).toThrow('Missing encryptedData parameter'); | ||
}); | ||
run({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious whether it would be obvious that are we are running these tests with different inputs, or even why we are doing so. What are your thoughts on using describe
to organize/describe the different invocations? I'm thinking an arrangement that looks something like this:
describe('encryption', () => {
describe('using modern encryption and decryption APIs', () => {
run({
decrypt,
decryptSafely,
encrypt,
encryptSafely,
getEncryptionPublicKey,
});
});
describe('using legacy encryption API', () => {
run({
decrypt,
decryptSafely,
encrypt: legacyEncrypt,
encryptSafely: legacyEncryptSafely,
getEncryptionPublicKey: legacyGetEncryptionPublicKey,
});
});
describe('using legacy decryption API', () => {
run({
decrypt: legacyDecrypt,
decryptSafely: legacyDecryptSafely,
encrypt,
encryptSafely,
getEncryptionPublicKey,
});
});
});
Note that this would mean removing the describe('encryption', ...)
from run
.
Encryption in this library is historically using
tweetnacl
andtweetnacl-util
as encryption libraries.tweetnacl-util
was replaced with@scure/base
in #358 andtweetnacl
is also due for removal.This adds a snapshot of
encryption.ts
astest-legacy-encryption.ts
, and adds compatibility tests in both directions to ensure that new versions of the code can decrypt messages produced by the old version and vice-versa.It does this by wrapping the entire existing encryption-test-suite and injecting the functions under test.
Note for reviewers: Most of the diff in
encryption.test.ts
is indentation, which can be ignored bygit diff -w
).