From 94af5c47407fe987505ec846a234bbb295e70cae Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 5 Apr 2021 04:18:33 -0400 Subject: [PATCH 1/2] refactored has_pgp, last_use and pubkey_last_check to camelCase --- extension/chrome/elements/add_pubkey.ts | 2 +- .../compose-recipients-module.ts | 14 ++--- .../compose-send-btn-module.ts | 2 +- .../compose-modules/compose-storage-module.ts | 10 ++-- .../formatters/signed-msg-mail-formatter.ts | 2 +- extension/chrome/elements/pgp_pubkey.ts | 2 +- extension/chrome/settings/modules/contacts.ts | 6 +- extension/js/background_page/migrations.ts | 4 +- extension/js/common/core/crypto/key.ts | 6 +- .../js/common/platform/store/contact-store.ts | 60 +++++++++---------- .../webmail/gmail-element-replacer.ts | 2 +- test/source/platform/store/contact-store.ts | 16 ++--- .../browser-unit-tests/unit-ContactStore.js | 36 +++++------ test/source/tests/compose.ts | 8 +-- 14 files changed, 85 insertions(+), 85 deletions(-) diff --git a/extension/chrome/elements/add_pubkey.ts b/extension/chrome/elements/add_pubkey.ts index c8ff3349531..9b5a06c5a1b 100644 --- a/extension/chrome/elements/add_pubkey.ts +++ b/extension/chrome/elements/add_pubkey.ts @@ -37,7 +37,7 @@ View.run(class AddPubkeyView extends View { for (const missingPubkeyEmail of this.missingPubkeyEmails) { Xss.sanitizeAppend('select.email', ``); } - for (const contact of await ContactStore.search(undefined, { has_pgp: true })) { + for (const contact of await ContactStore.search(undefined, { hasPgp: true })) { Xss.sanitizeAppend('select.copy_from_email', ``); } this.fetchKeyUi.handleOnPaste($('.pubkey')); diff --git a/extension/chrome/elements/compose-modules/compose-recipients-module.ts b/extension/chrome/elements/compose-modules/compose-recipients-module.ts index f067d9fbac9..706ae85c767 100644 --- a/extension/chrome/elements/compose-modules/compose-recipients-module.ts +++ b/extension/chrome/elements/compose-modules/compose-recipients-module.ts @@ -411,7 +411,7 @@ export class ComposeRecipientsModule extends ViewModule { const recipientsHasPgp: RecipientElement[] = []; for (const recipient of noPgpRecipients) { const [contact] = await ContactStore.get(undefined, [recipient.email]); - if (contact && contact.has_pgp) { + if (contact && contact.hasPgp) { $(recipient.element).removeClass('no_pgp').find('i').remove(); clearInterval(this.addedPubkeyDbLookupInterval); recipientsHasPgp.push(recipient); @@ -584,16 +584,16 @@ export class ComposeRecipientsModule extends ViewModule { this.view.errModule.debug(`renderSearchRes len: ${contacts.length}`); // have pgp on top, no pgp bottom. Sort each groups by last use const sortedContacts = contacts.sort((a: ContactPreview, b: ContactPreview) => { - if (a.has_pgp && !b.has_pgp) { + if (a.hasPgp && !b.hasPgp) { return -1; } - if (!a.has_pgp && b.has_pgp) { + if (!a.hasPgp && b.hasPgp) { return 1; } - if ((a.last_use || 0) > (b.last_use || 0)) { + if ((a.lastUse || 0) > (b.lastUse || 0)) { return -1; } - if ((a.last_use || 0) < (b.last_use || 0)) { + if ((a.lastUse || 0) < (b.lastUse || 0)) { return 1; } return 0; @@ -603,7 +603,7 @@ export class ComposeRecipientsModule extends ViewModule { let ulHtml = ''; for (const contact of renderableContacts) { ulHtml += `
  • `; - if (contact.has_pgp) { + if (contact.hasPgp) { ulHtml += ''; } else { ulHtml += ''; @@ -835,7 +835,7 @@ export class ComposeRecipientsModule extends ViewModule { 'you an updated public key.' + this.recipientKeyIdText(contact)); } else if (contact.pubkey) { recipient.status = RecipientStatus.HAS_PGP; - $(el).addClass("has_pgp"); + $(el).addClass('has_pgp'); Xss.sanitizePrepend(el, ''); $(el).attr('title', 'Does use encryption' + this.recipientKeyIdText(contact)); } else { diff --git a/extension/chrome/elements/compose-modules/compose-send-btn-module.ts b/extension/chrome/elements/compose-modules/compose-send-btn-module.ts index 6450e6c89cd..47f2c55c3ec 100644 --- a/extension/chrome/elements/compose-modules/compose-send-btn-module.ts +++ b/extension/chrome/elements/compose-modules/compose-send-btn-module.ts @@ -120,7 +120,7 @@ export class ComposeSendBtnModule extends ViewModule { return; // user has canceled the pass phrase dialog, or didn't respond to it in time } } - await ContactStore.update(undefined, Array.prototype.concat.apply([], Object.values(newMsgData.recipients)), { last_use: Date.now() }); + await ContactStore.update(undefined, Array.prototype.concat.apply([], Object.values(newMsgData.recipients)), { lastUse: Date.now() }); const msgObj = await GeneralMailFormatter.processNewMsg(this.view, newMsgData, senderKi, signingPrv); await this.finalizeSendableMsg(msgObj, senderKi); await this.doSendMsg(msgObj); diff --git a/extension/chrome/elements/compose-modules/compose-storage-module.ts b/extension/chrome/elements/compose-modules/compose-storage-module.ts index 4990dcf4ef0..76cd8560714 100644 --- a/extension/chrome/elements/compose-modules/compose-storage-module.ts +++ b/extension/chrome/elements/compose-modules/compose-storage-module.ts @@ -68,7 +68,7 @@ export class ComposeStorageModule extends ViewModule { const emailsWithoutPubkeys = []; for (const i of contacts.keys()) { const contact = contacts[i]; - if (contact && contact.has_pgp && contact.pubkey) { + if (contact && contact.hasPgp && contact.pubkey) { armoredPubkeys.push({ pubkey: contact.pubkey, email: contact.email, isMine: false }); } else if (contact && this.ksLookupsByEmail[contact.email]) { armoredPubkeys.push({ pubkey: this.ksLookupsByEmail[contact.email], email: contact.email, isMine: false }); @@ -88,7 +88,7 @@ export class ComposeStorageModule extends ViewModule { public lookupPubkeyFromDbOrKeyserverAndUpdateDbIfneeded = async (email: string, name: string | undefined): Promise => { const [storedContact] = await ContactStore.get(undefined, [email]); - if (storedContact && storedContact.has_pgp && storedContact.pubkey) { + if (storedContact && storedContact.hasPgp && storedContact.pubkey) { // Potentially check if pubkey was updated - async. By the time user finishes composing, newer version would have been updated in db. // If sender didn't pull a particular pubkey for a long time and it has since expired, but there actually is a newer version on attester, this may unnecessarily show "bad pubkey", // -> until next time user tries to pull it. This could be fixed by attempting to fix up the rendered recipient inside the async function below. @@ -132,7 +132,7 @@ export class ComposeStorageModule extends ViewModule { if (!contact.pubkey || !contact.fingerprint) { return; } - const lastCheckOverWeekAgoOrNever = !contact.pubkey_last_check || new Date(contact.pubkey_last_check).getTime() < Date.now() - (1000 * 60 * 60 * 24 * 7); + const lastCheckOverWeekAgoOrNever = !contact.pubkeyLastCheck || new Date(contact.pubkeyLastCheck).getTime() < Date.now() - (1000 * 60 * 60 * 24 * 7); const isExpired = contact.expiresOn && contact.expiresOn < Date.now(); if (lastCheckOverWeekAgoOrNever || isExpired) { const { pubkey: fetchedPubkeyArmored } = await this.view.pubLookup.lookupFingerprint(contact.fingerprint); @@ -142,7 +142,7 @@ export class ComposeStorageModule extends ViewModule { // the fetched pubkey has at least the same or newer signature // the "same or newer" was due to a bug we encountered earlier where keys were badly recorded in db // sometime in Oct 2020 we could turn the ">=" back to ">" above - await ContactStore.update(undefined, contact.email, { pubkey: fetchedPubkey, last_use: Date.now(), pubkey_last_check: Date.now() }); + await ContactStore.update(undefined, contact.email, { pubkey: fetchedPubkey, lastUse: Date.now(), pubkeyLastCheck: Date.now() }); const [updatedPubkey] = await ContactStore.get(undefined, [contact.email]); if (!updatedPubkey) { throw new Error("Cannot retrieve Contact right after updating it"); @@ -152,7 +152,7 @@ export class ComposeStorageModule extends ViewModule { } } } - await ContactStore.update(undefined, contact.email, { pubkey: contact.pubkey, pubkey_last_check: Date.now() }); + await ContactStore.update(undefined, contact.email, { pubkey: contact.pubkey, pubkeyLastCheck: Date.now() }); // we checked for newer key and it did not result in updating the key, don't check again for another week } catch (e) { ApiErr.reportIfSignificant(e); diff --git a/extension/chrome/elements/compose-modules/formatters/signed-msg-mail-formatter.ts b/extension/chrome/elements/compose-modules/formatters/signed-msg-mail-formatter.ts index 24b5831c5d7..f3aff6103c4 100644 --- a/extension/chrome/elements/compose-modules/formatters/signed-msg-mail-formatter.ts +++ b/extension/chrome/elements/compose-modules/formatters/signed-msg-mail-formatter.ts @@ -32,7 +32,7 @@ export class SignedMsgMailFormatter extends BaseMailFormatter { newMsg.plaintext = newMsg.plaintext.split('\n').map(l => l.replace(/\s+$/g, '')).join('\n').trim(); const signedData = await MsgUtil.sign(signingPrv, newMsg.plaintext); const allContacts = [...newMsg.recipients.to || [], ...newMsg.recipients.cc || [], ...newMsg.recipients.bcc || []]; - ContactStore.update(undefined, allContacts, { last_use: Date.now() }).catch(Catch.reportErr); + ContactStore.update(undefined, allContacts, { lastUse: Date.now() }).catch(Catch.reportErr); return await SendableMsg.createPgpInline(this.acctEmail, this.headers(newMsg), signedData, attachments); } // pgp/mime detached signature - it must be signed later, while being mime-encoded diff --git a/extension/chrome/elements/pgp_pubkey.ts b/extension/chrome/elements/pgp_pubkey.ts index d7e386e3737..70f70053749 100644 --- a/extension/chrome/elements/pgp_pubkey.ts +++ b/extension/chrome/elements/pgp_pubkey.ts @@ -128,7 +128,7 @@ View.run(class PgpPubkeyView extends View { } else { const [contact] = await ContactStore.get(undefined, [String($('.input_email').val())]); $('.action_add_contact') - .text(contact?.has_pgp ? 'update key' : `import ${this.isExpired ? 'expired ' : ''}key`) + .text(contact?.hasPgp ? 'update key' : `import ${this.isExpired ? 'expired ' : ''}key`) .css('background-color', this.isExpired ? '#989898' : ''); } } diff --git a/extension/chrome/settings/modules/contacts.ts b/extension/chrome/settings/modules/contacts.ts index 3e75229c0f4..3a23adfba94 100644 --- a/extension/chrome/settings/modules/contacts.ts +++ b/extension/chrome/settings/modules/contacts.ts @@ -66,7 +66,7 @@ View.run(class ContactsView extends View { // --- PRIVATE private loadAndRenderContactList = async () => { - this.contacts = await ContactStore.search(undefined, { has_pgp: true, limit: 500, substring: String($('.input-search-contacts').val()) }); + this.contacts = await ContactStore.search(undefined, { hasPgp: true, limit: 500, substring: String($('.input-search-contacts').val()) }); let lineActionsHtml = '  export all  ' + '  import public keys  '; if (this.orgRules.getCustomSksPubkeyServer()) { @@ -109,7 +109,7 @@ View.run(class ContactsView extends View { } private actionExportAllKeysHandler = async () => { - const allArmoredPublicKeys = (await ContactStore.searchPubkeys(undefined, { has_pgp: true })).map(a => a!.trim()).join('\n'); + const allArmoredPublicKeys = (await ContactStore.searchPubkeys(undefined, { hasPgp: true })).map(a => a!.trim()).join('\n'); const exportFile = new Attachment({ name: 'public-keys-export.asc', type: 'application/pgp-keys', data: Buf.fromUtfStr(allArmoredPublicKeys) }); Browser.saveToDownloads(exportFile); } @@ -152,7 +152,7 @@ View.run(class ContactsView extends View { try { // parse will throw if the key is not recognized const pubkey = await KeyUtil.parse(armoredPubkey); - await ContactStore.update(undefined, email, { pubkey, last_use: Date.now() }); + await ContactStore.update(undefined, email, { pubkey, lastUse: Date.now() }); await this.loadAndRenderContactList(); } catch (e) { await Ui.modal.warning('Cannot recognize a valid public key, please try again. Let us know at human@flowcrypt.com if you need help.'); diff --git a/extension/js/background_page/migrations.ts b/extension/js/background_page/migrations.ts index c9973c240d3..06f0e011fc3 100644 --- a/extension/js/background_page/migrations.ts +++ b/extension/js/background_page/migrations.ts @@ -84,8 +84,8 @@ const moveContactsBatchToEmailsAndPubkeys = async (db: IDBDatabase, count?: numb update: { name: entry.name, pubkey, - last_use: entry.last_use, - pubkey_last_check: pubkey ? entry.pubkey_last_check : undefined + lastUse: entry.last_use, + pubkeyLastCheck: pubkey ? entry.pubkey_last_check : undefined } as ContactUpdate }; })); diff --git a/extension/js/common/core/crypto/key.ts b/extension/js/common/core/crypto/key.ts index be68cd24a3b..2e87d6a802b 100644 --- a/extension/js/common/core/crypto/key.ts +++ b/extension/js/common/core/crypto/key.ts @@ -51,10 +51,10 @@ export type Contact = { email: string; name: string | null; pubkey: Key | undefined; - has_pgp: 0 | 1; + hasPgp: 0 | 1; fingerprint: string | null; - last_use: number | null; - pubkey_last_check: number | null; + lastUse: number | null; + pubkeyLastCheck: number | null; expiresOn: number | null; }; diff --git a/extension/js/common/platform/store/contact-store.ts b/extension/js/common/platform/store/contact-store.ts index 00bf2690c84..6e0248ba9ff 100644 --- a/extension/js/common/platform/store/contact-store.ts +++ b/extension/js/common/platform/store/contact-store.ts @@ -47,18 +47,18 @@ export type ContactV4 = { export type ContactPreview = { email: string; name: string | null; - has_pgp: 0 | 1; - last_use: number | null; + hasPgp: 0 | 1; + lastUse: number | null; }; export type ContactUpdate = { name?: string | null; - last_use?: number | null; + lastUse?: number | null; pubkey?: Key; - pubkey_last_check?: number | null; // when non-null, `pubkey` must be supplied + pubkeyLastCheck?: number | null; // when non-null, `pubkey` must be supplied }; -type DbContactFilter = { has_pgp?: boolean, substring?: string, limit?: number }; +type DbContactFilter = { hasPgp?: boolean, substring?: string, limit?: number }; /** * Store of contacts and their public keys @@ -69,7 +69,7 @@ export class ContactStore extends AbstractStore { // static [f: string]: Function; // https://github.com/Microsoft/TypeScript/issues/6480 - private static dbQueryKeys = ['limit', 'substring', 'has_pgp']; + private static dbQueryKeys = ['limit', 'substring', 'hasPgp']; public static dbOpen = async (): Promise => { return await new Promise((resolve, reject) => { @@ -104,7 +104,7 @@ export class ContactStore extends AbstractStore { if (!validEmail) { throw new Error(`Cannot handle the contact because email is not valid: ${email}`); } - return { email: validEmail, name: name || null, has_pgp: 0, last_use: null }; + return { email: validEmail, name: name || null, hasPgp: 0, lastUse: null }; } public static obj = async ({ email, name, pubkey, lastUse, lastCheck }: DbContactObjArg): Promise => { @@ -120,10 +120,10 @@ export class ContactStore extends AbstractStore { email: validEmail, name: name || null, pubkey: undefined, - has_pgp: 0, // number because we use it for sorting + hasPgp: 0, // number because we use it for sorting fingerprint: null, - last_use: lastUse || null, - pubkey_last_check: null, + lastUse: lastUse || null, + pubkeyLastCheck: null, expiresOn: null }; } @@ -132,9 +132,9 @@ export class ContactStore extends AbstractStore { email: validEmail, name: name || null, pubkey: pk, - has_pgp: 1, // number because we use it for sorting - last_use: lastUse || null, - pubkey_last_check: lastCheck || null, + hasPgp: 1, // number because we use it for sorting + lastUse: lastUse || null, + pubkeyLastCheck: lastCheck || null, ...ContactStore.getKeyAttributes(pk) }; } @@ -245,7 +245,7 @@ export class ContactStore extends AbstractStore { } public static updateTx = (tx: IDBTransaction, email: string, update: ContactUpdate) => { - if (update.pubkey && !update.pubkey_last_check) { + if (update.pubkey && !update.pubkeyLastCheck) { const req = tx.objectStore('pubkeys').get(update.pubkey.id); ContactStore.setReqPipe(req, (pubkey: Pubkey) => ContactStore.updateTxPhase2(tx, email, update, pubkey)); } else { @@ -277,13 +277,13 @@ export class ContactStore extends AbstractStore { // todo: will we benefit anything when not saving pubkey if it isn't modified? pubkeyEntity = { fingerprint: update.pubkey.id, - lastCheck: DateUtility.asNumber(update.pubkey_last_check ?? existingPubkey?.lastCheck), + lastCheck: DateUtility.asNumber(update.pubkeyLastCheck ?? existingPubkey?.lastCheck), expiresOn: keyAttrs.expiresOn, longids: update.pubkey.allIds.map(id => OpenPGPKey.fingerprintToLongid(id)), armoredKey: KeyUtil.armor(update.pubkey) } as Pubkey; - } else if (update.pubkey_last_check) { - Catch.report(`Wrongly updating pubkey_last_check without specifying pubkey for ${email} - ignoring`); + } else if (update.pubkeyLastCheck) { + Catch.report(`Wrongly updating pubkeyLastCheck without specifying pubkey for ${email} - ignoring`); } const req = tx.objectStore('emails').get(email); ContactStore.setReqPipe(req, (emailEntity: Email) => { @@ -298,8 +298,8 @@ export class ContactStore extends AbstractStore { if (Object.keys(update).includes('name')) { emailEntity.name = update.name ?? null; } - if (Object.keys(update).includes('last_use')) { - emailEntity.lastUse = DateUtility.asNumber(update.last_use); + if (Object.keys(update).includes('lastUse')) { + emailEntity.lastUse = DateUtility.asNumber(update.lastUse); } ContactStore.updateSearchable(emailEntity); tx.objectStore('emails').put(emailEntity); @@ -341,23 +341,23 @@ export class ContactStore extends AbstractStore { } } query.substring = ContactStore.normalizeString(query.substring || ''); - if (typeof query.has_pgp === 'undefined' && query.substring) { - const resultsWithPgp = await ContactStore.rawSearch(db, { substring: query.substring, limit: query.limit, has_pgp: true }); + if (typeof query.hasPgp === 'undefined' && query.substring) { + const resultsWithPgp = await ContactStore.rawSearch(db, { substring: query.substring, limit: query.limit, hasPgp: true }); if (query.limit && resultsWithPgp.length === query.limit) { return resultsWithPgp; } else { const limit = query.limit ? query.limit - resultsWithPgp.length : undefined; - const resultsWithoutPgp = await ContactStore.rawSearch(db, { substring: query.substring, limit, has_pgp: false }); + const resultsWithoutPgp = await ContactStore.rawSearch(db, { substring: query.substring, limit, hasPgp: false }); return resultsWithPgp.concat(resultsWithoutPgp); } } const emails = db.transaction(['emails'], 'readonly').objectStore('emails'); const raw: Email[] = await new Promise((resolve, reject) => { let search: IDBRequest; - if (typeof query.has_pgp === 'undefined') { // any query.has_pgp value - search = emails.openCursor(); // no substring, already covered in `typeof query.has_pgp === 'undefined' && query.substring` above - } else { // specific query.has_pgp value - const indexRange = ContactStore.dbIndexRange(query.has_pgp, query.substring ?? ''); + if (typeof query.hasPgp === 'undefined') { // any query.hasPgp value + search = emails.openCursor(); // no substring, already covered in `typeof query.hasPgp === 'undefined' && query.substring` above + } else { // specific query.hasPgp value + const indexRange = ContactStore.dbIndexRange(query.hasPgp, query.substring ?? ''); // To find all the index keys starting with a certain sequence of characters (e.g. 'abc') // we use a range with inclusive lower boundary and exclusive upper boundary // ['t:abc', 't:abd) or ['f:abc', 'f:abd'), so that any key having an arbitrary tail of @@ -490,14 +490,14 @@ export class ContactStore extends AbstractStore { email: email.email, name: email.name, pubkey: key, - has_pgp: key ? 1 : 0, - last_use: email.lastUse, - pubkey_last_check: lastCheck, + hasPgp: key ? 1 : 0, + lastUse: email.lastUse, + pubkeyLastCheck: lastCheck, ...ContactStore.getKeyAttributes(key) }; } private static toContactPreview = (result: Email): ContactPreview => { - return { email: result.email, name: result.name, has_pgp: result.fingerprints.length > 0 ? 1 : 0, last_use: result.lastUse }; + return { email: result.email, name: result.name, hasPgp: result.fingerprints.length > 0 ? 1 : 0, lastUse: result.lastUse }; } } diff --git a/extension/js/content_scripts/webmail/gmail-element-replacer.ts b/extension/js/content_scripts/webmail/gmail-element-replacer.ts index 28aab28ae4e..fd5aa20600e 100644 --- a/extension/js/content_scripts/webmail/gmail-element-replacer.ts +++ b/extension/js/content_scripts/webmail/gmail-element-replacer.ts @@ -704,7 +704,7 @@ export class GmailElementReplacer implements WebmailElementReplacer { } } catch (e) { ApiErr.reportIfSignificant(e); - // this is a low-importance request, so evaluate has_pgp as false on errors + // this is a low-importance request, so evaluate hasPgp as false on errors // this way faulty requests wouldn't unnecessarily repeat and overwhelm Attester this.recipientHasPgpCache[email] = false; everyoneUsesEncryption = false; diff --git a/test/source/platform/store/contact-store.ts b/test/source/platform/store/contact-store.ts index 5e7ac70b132..ec6adea63b4 100644 --- a/test/source/platform/store/contact-store.ts +++ b/test/source/platform/store/contact-store.ts @@ -11,7 +11,7 @@ export type ContactUpdate = { email?: string; name?: string | null; pubkey?: Key; - last_use?: number | null; + lastUse?: number | null; }; export class ContactStore { @@ -44,7 +44,7 @@ export class ContactStore { updated.pubkey = key; updated.fingerprint = key.id; updated.expiresOn = key.expiration ? Number(key.expiration) : null; - updated.has_pgp = 1; + updated.hasPgp = 1; } } @@ -54,10 +54,10 @@ export class ContactStore { email, name: name || null, pubkey: undefined, - has_pgp: 0, // number because we use it for sorting + hasPgp: 0, // number because we use it for sorting fingerprint: null, - last_use: lastUse || null, - pubkey_last_check: null, + lastUse: lastUse || null, + pubkeyLastCheck: null, expiresOn: null }; } @@ -66,10 +66,10 @@ export class ContactStore { email, name, pubkey: pk, - has_pgp: 1, // number because we use it for sorting + hasPgp: 1, // number because we use it for sorting fingerprint: pk.id, - last_use: lastUse, - pubkey_last_check: lastCheck, + lastUse: lastUse, + pubkeyLastCheck: lastCheck, } as Contact; return contact; } diff --git a/test/source/tests/browser-unit-tests/unit-ContactStore.js b/test/source/tests/browser-unit-tests/unit-ContactStore.js index 13923036d25..13e64e81514 100644 --- a/test/source/tests/browser-unit-tests/unit-ContactStore.js +++ b/test/source/tests/browser-unit-tests/unit-ContactStore.js @@ -41,26 +41,26 @@ BROWSER_UNIT_TEST_NAME(`ContactStore is able to search by partial email address` }); await ContactStore.save(undefined, [contactABBDEF, contactABCDEF, contactABCDDF, contactABDDEF, contactABCDVWXYZHELLOCOM]); - const contactsABC = await ContactStore.search(undefined, { has_pgp: true, substring: 'abc' }); + const contactsABC = await ContactStore.search(undefined, { hasPgp: true, substring: 'abc' }); if (contactsABC.length !== 3) { throw Error(`Expected 3 contacts to match "abc" but got "${contactsABC.length}"`); } - const contactsABCD = await ContactStore.search(undefined, { has_pgp: true, substring: 'abcd' }); + const contactsABCD = await ContactStore.search(undefined, { hasPgp: true, substring: 'abcd' }); if (contactsABCD.length !== 3) { throw Error(`Expected 3 contacts to match "abcd" but got "${contactsABCD.length}"`); } - const contactsABCDE = await ContactStore.search(undefined, { has_pgp: true, substring: 'abcde' }); + const contactsABCDE = await ContactStore.search(undefined, { hasPgp: true, substring: 'abcde' }); if (contactsABCDE.length !== 1) { throw Error(`Expected 1 contact to match "abcde" but got "${contactsABCDE.length}"`); } if (contactsABCDE[0].email !== 'abcdef@test.com') { throw Error(`Expected "abcdef@test.com" but got "${contactsABCDE[0].email}"`); } - const contactsVWX = await ContactStore.search(undefined, { has_pgp: true, substring: 'vwx' }); + const contactsVWX = await ContactStore.search(undefined, { hasPgp: true, substring: 'vwx' }); if (contactsVWX.length !== 1) { throw Error(`Expected 1 contact to match "vwx" but got "${contactsVWX.length}"`); } - const contactsHEL = await ContactStore.search(undefined, { has_pgp: true, substring: 'hel' }); + const contactsHEL = await ContactStore.search(undefined, { hasPgp: true, substring: 'hel' }); if (contactsHEL.length !== 1) { throw Error(`Expected 1 contact to match "hel" but got "${contactsHEL.length}"`); } @@ -104,7 +104,7 @@ BROWSER_UNIT_TEST_NAME(`ContactStore doesn't store smaller words in searchable w return 'pass'; })(); -BROWSER_UNIT_TEST_NAME(`ContactStore.update updates correct 'pubkey_last_check'`); +BROWSER_UNIT_TEST_NAME(`ContactStore.update updates correct 'pubkeyLastCheck'`); (async () => { const db = await ContactStore.dbOpen(); const email = 'flowcrypt.compatibility@gmail.com'; @@ -146,8 +146,8 @@ BROWSER_UNIT_TEST_NAME(`ContactStore.update updates correct 'pubkey_last_check'` const pubkey1 = await KeyUtil.parse(testConstants.flowcryptcompatibilityPublicKey7FDE685548AEA788); const pubkey2 = await KeyUtil.parse(testConstants.flowcryptcompatibilityPublicKeyADAC279C95093207); const date1_1 = date2_0 + 1000; - // update entity 1 with pubkey_last_check = date1_1 - await ContactStore.update(db, email, { pubkey_last_check: date1_1, pubkey: pubkey1 }); + // update entity 1 with pubkeyLastCheck = date1_1 + await ContactStore.update(db, email, { pubkeyLastCheck: date1_1, pubkey: pubkey1 }); // extract the entities from the database entity1 = await getEntity(fp1); entity2 = await getEntity(fp2); @@ -158,9 +158,9 @@ BROWSER_UNIT_TEST_NAME(`ContactStore.update updates correct 'pubkey_last_check'` throw Error(`Expected lastCheck=${date2_0} for ${fp2} but got ${entity2.lastCheck}`); } const date2_2 = date1_1 + 10000; - // updating with undefined value shouldn't modify pubkey_last_check - await ContactStore.update(db, email, { pubkey_last_check: undefined, pubkey: pubkey1 }); - await ContactStore.update(db, email, { pubkey_last_check: date2_2, pubkey: pubkey2 }); + // updating with undefined value shouldn't modify pubkeyLastCheck + await ContactStore.update(db, email, { pubkeyLastCheck: undefined, pubkey: pubkey1 }); + await ContactStore.update(db, email, { pubkeyLastCheck: date2_2, pubkey: pubkey2 }); // extract the entities from the database entity1 = await getEntity(fp1); entity2 = await getEntity(fp2); @@ -170,7 +170,7 @@ BROWSER_UNIT_TEST_NAME(`ContactStore.update updates correct 'pubkey_last_check'` if (entity2.lastCheck !== date2_2) { throw Error(`Expected lastCheck=${date2_2} for ${fp2} but got ${entity2.lastCheck}`); } - // updating contact details without specifying a pubkey shouln't update pubkey_last_check + // updating contact details without specifying a pubkey shouln't update pubkeyLastCheck await ContactStore.update(db, email, { name: 'Some Name' }); // extract the entities from the database entity1 = await getEntity(fp1); @@ -228,10 +228,10 @@ BROWSER_UNIT_TEST_NAME(`ContactStore.update tests`); await compareEntities(); const date = new Date(); expectedObj2.lastUse = date.getTime(); - await ContactStore.update(db, email2, { last_use: date }); + await ContactStore.update(db, email2, { lastUse: date }); await compareEntities(); expectedObj2.lastUse = undefined; - await ContactStore.update(db, email2, { last_use: undefined }); + await ContactStore.update(db, email2, { lastUse: undefined }); await compareEntities(); return 'pass'; })(); @@ -245,11 +245,11 @@ BROWSER_UNIT_TEST_NAME(`ContactStore saves and returns dates as numbers`); const contact = await ContactStore.obj({ email, pubkey: testConstants.expiredPub, lastCheck, lastUse }); await ContactStore.save(undefined, [contact]); const [loaded] = await ContactStore.get(undefined, [email]); - if (typeof loaded.last_use !== 'number') { - throw Error(`last_use was expected to be a number, but got ${typeof loaded.last_use}`); + if (typeof loaded.lastUse !== 'number') { + throw Error(`lastUse was expected to be a number, but got ${typeof loaded.lastUse}`); } - if (typeof loaded.pubkey_last_check !== 'number') { - throw Error(`pubkey_last_check was expected to be a number, but got ${typeof loaded.pubkey_last_check}`); + if (typeof loaded.pubkeyLastCheck !== 'number') { + throw Error(`pubkeyLastCheck was expected to be a number, but got ${typeof loaded.pubkeyLastCheck}`); } if (typeof loaded.expiresOn !== 'number') { throw Error(`expiresOn was expected to be a number, but got ${typeof loaded.expiresOn}`); diff --git a/test/source/tests/compose.ts b/test/source/tests/compose.ts index ef8191058d7..dbd6b625d8b 100644 --- a/test/source/tests/compose.ts +++ b/test/source/tests/compose.ts @@ -582,13 +582,13 @@ export const defineComposeTests = (testVariant: TestVariant, testWithBrowser: Te await composeFrame.waitAndClick('.swal2-cancel'); await composeFrame.waitAndClick('@action-close-new-message'); await inboxPage.waitTillGone('@container-new-message'); - // check that contacts are ordered according to has_pgp and last_use + // check that contacts are ordered according to hasPgp and lastUse composeFrame = await InboxPageRecipe.openAndGetComposeFrame(inboxPage); await composeFrame.type('@input-to', 'testsearchorder'); await expectContactsResultEqual(composeFrame, [ - 'testsearchorder3@flowcrypt.com', // has_pgp + last_use - 'testsearchorder9@flowcrypt.com', // has_pgp - 'testsearchorder5@flowcrypt.com', // last_use + 'testsearchorder3@flowcrypt.com', // hasPgp + lastUse + 'testsearchorder9@flowcrypt.com', // hasPgp + 'testsearchorder5@flowcrypt.com', // lastUse 'testsearchorder1@flowcrypt.com', 'testsearchorder2@flowcrypt.com', 'testsearchorder4@flowcrypt.com', From 21ef96a02543f7113ec365e10b4c2239489ae852 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 5 Apr 2021 04:36:32 -0400 Subject: [PATCH 2/2] tslint fix --- test/source/platform/store/contact-store.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/source/platform/store/contact-store.ts b/test/source/platform/store/contact-store.ts index ec6adea63b4..0a52e8db689 100644 --- a/test/source/platform/store/contact-store.ts +++ b/test/source/platform/store/contact-store.ts @@ -68,7 +68,7 @@ export class ContactStore { pubkey: pk, hasPgp: 1, // number because we use it for sorting fingerprint: pk.id, - lastUse: lastUse, + lastUse, pubkeyLastCheck: lastCheck, } as Contact; return contact;