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

test(encryption): add backwards-compatibility-test for encrypt/decrypt #367

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

legobeat
Copy link
Contributor

@legobeat legobeat commented May 1, 2024

Encryption in this library is historically using tweetnacl and tweetnacl-util as encryption libraries. tweetnacl-util was replaced with @scure/base in #358 and tweetnacl is also due for removal.

This adds a snapshot of encryption.ts as test-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 by git diff -w).

Copy link

socket-security bot commented May 1, 2024

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/[email protected] None 0 8.14 kB dchest

View full report↗︎

@legobeat legobeat changed the title test(encryption): add compatibility-test to v7.0.1 test(encryption): add backwards-compatibility-test for encrypt/decrypt May 1, 2024
@legobeat legobeat requested a review from a team May 1, 2024 07:51
@legobeat legobeat marked this pull request as ready for review May 1, 2024 07:53
@legobeat legobeat force-pushed the test-compat-encryption branch from abef015 to 7c59ecb Compare May 1, 2024 08:04
@legobeat legobeat force-pushed the test-compat-encryption branch from 7c59ecb to 0d8bbb2 Compare July 12, 2024 19:54
@legobeat legobeat requested review from mcmire, Mrtenz and MajorLift July 12, 2024 19:54
@Mrtenz Mrtenz removed their request for review August 15, 2024 09:00
}),
).toThrow('Missing encryptedData parameter');
});
run({
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants