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

Use TS in tests and fix type definitions of decryptMessageLegacy, decryptMIMEMessage #127

Merged
merged 7 commits into from
Oct 12, 2021

Conversation

larabr
Copy link
Collaborator

@larabr larabr commented Oct 6, 2021

  • Fix decryptMessageLegacy, decryptMIMEMessage to accept a string input message (used to accept a Message instead).
  • Rewrite tests in typescript for better detection of type issues (partially addresses Add tests for type definitions #112; not all functions are tested).
  • Upgrade ava to v3 to support its typescript integration.
  • Upgrade CI node version to LTS to be able to run the new test suite.

@larabr larabr changed the title Fix type definitions of decryptMessageLegacy and decryptMIMEMessage Use TS in tests, fix type definitions of decryptMessageLegacy, decryptMIMEMessage Oct 6, 2021
@larabr larabr changed the title Use TS in tests, fix type definitions of decryptMessageLegacy, decryptMIMEMessage Use TS in tests and fix type definitions of decryptMessageLegacy, decryptMIMEMessage Oct 6, 2021
@larabr larabr requested a review from twiss October 6, 2021 14:31
Copy link
Member

@twiss twiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nitpicks below. Alternatively, I'm also fine with merging this PR as-is and then changing the below in a separate PR.

@@ -4,6 +4,11 @@ const protonmailCryptoTailMessage = '---END ENCRYPTED MESSAGE---';
const protonmailCryptoHeaderRandomKey = '---BEGIN ENCRYPTED RANDOM KEY---';
const protonmailCryptoTailRandomKey = '---END ENCRYPTED RANDOM KEY---';

/**
* Extract armored encrypted message from email
* @param {String|Object} EmailPM
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know the function kinda sort accepts it, but do we ever pass an object here? If not I don't really think we should start explicitly allowing it now. Maybe we can even get rid of the checks at some point

Suggested change
* @param {String|Object} EmailPM
* @param {String} EmailPM

@@ -14,6 +19,11 @@ export function getEncMessageFromEmailPM(EmailPM) {
return '';
}

/**
* Extract (legacy, custom) armored encrypted random key from email
* @param {String|Object} EmailPM
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idem

Suggested change
* @param {String|Object} EmailPM
* @param {String} EmailPM

@@ -50,7 +50,7 @@ export async function decryptMessage(options) {
}

// Backwards-compatible decrypt message function
// 'message' option must be a string!
// `options.message` must be a string, to properly handle legacy messages (and avoid misusing this function)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As written, it kind of sounds like it only needs to be a string if you care about legacy messages, which is true - but I would rather change that and remove the checks, so that this function always throws for other types, so that we enforce this rather than write a comment about it.

Suggested change
// `options.message` must be a string, to properly handle legacy messages (and avoid misusing this function)
// `options.message` must be a string

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change the behaviour in a separate PR, to keep this one about TS fixes only 👍

@larabr larabr merged commit 220b00d into ProtonMail:master Oct 12, 2021
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