chore: vault tests refactors and lint (#2374)
This commit is contained in:
@@ -17,7 +17,7 @@ describe('asymmetric messages', function () {
|
||||
beforeEach(async function () {
|
||||
localStorage.clear()
|
||||
|
||||
context = await Factory.createAppContextWithRealCrypto()
|
||||
context = await Factory.createVaultsContextWithRealCrypto()
|
||||
|
||||
await context.launch()
|
||||
await context.register()
|
||||
@@ -29,7 +29,7 @@ describe('asymmetric messages', function () {
|
||||
|
||||
contactContext.lockSyncing()
|
||||
|
||||
await context.vaults.changeVaultNameAndDescription(sharedVault, {
|
||||
await context.changeVaultName(sharedVault, {
|
||||
name: 'new vault name',
|
||||
description: 'new vault description',
|
||||
})
|
||||
@@ -38,11 +38,8 @@ describe('asymmetric messages', function () {
|
||||
get: () => 'invalid user uuid',
|
||||
})
|
||||
|
||||
const completedProcessingMessagesPromise = contactContext.resolveWhenAsymmetricMessageProcessingCompletes()
|
||||
|
||||
contactContext.unlockSyncing()
|
||||
await contactContext.sync()
|
||||
await completedProcessingMessagesPromise
|
||||
await contactContext.syncAndAwaitMessageProcessing()
|
||||
|
||||
const updatedVault = contactContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
|
||||
|
||||
@@ -53,33 +50,22 @@ describe('asymmetric messages', function () {
|
||||
})
|
||||
|
||||
it('should delete message after processing it', async () => {
|
||||
const { contactContext, deinitContactContext } = await Collaboration.createSharedVaultWithAcceptedInvite(context)
|
||||
const { sharedVault, contactContext, deinitContactContext } =
|
||||
await Collaboration.createSharedVaultWithAcceptedInvite(context)
|
||||
|
||||
const eventData = {
|
||||
current: {
|
||||
encryption: context.encryption.getKeyPair(),
|
||||
signing: context.encryption.getSigningKeyPair(),
|
||||
},
|
||||
previous: {
|
||||
encryption: context.encryption.getKeyPair(),
|
||||
signing: context.encryption.getSigningKeyPair(),
|
||||
},
|
||||
}
|
||||
|
||||
await context.contacts.sendOwnContactChangeEventToAllContacts(eventData)
|
||||
await context.changeVaultName(sharedVault, {
|
||||
name: 'New Name',
|
||||
description: 'New Description',
|
||||
})
|
||||
|
||||
const deleteFunction = sinon.spy(contactContext.asymmetric, 'deleteMessageAfterProcessing')
|
||||
|
||||
const promise = contactContext.resolveWhenAsymmetricMessageProcessingCompletes()
|
||||
|
||||
await contactContext.sync()
|
||||
|
||||
await promise
|
||||
await contactContext.syncAndAwaitMessageProcessing()
|
||||
|
||||
expect(deleteFunction.callCount).to.equal(1)
|
||||
|
||||
const messages = await contactContext.asymmetric.getInboundMessages()
|
||||
expect(messages.length).to.equal(0)
|
||||
expect(messages.getValue().length).to.equal(0)
|
||||
|
||||
await deinitContactContext()
|
||||
})
|
||||
@@ -106,10 +92,7 @@ describe('asymmetric messages', function () {
|
||||
|
||||
await sendContactSharePromise
|
||||
|
||||
const completedProcessingMessagesPromise = contactContext.resolveWhenAsymmetricMessageProcessingCompletes()
|
||||
|
||||
await contactContext.sync()
|
||||
await completedProcessingMessagesPromise
|
||||
await contactContext.syncAndAwaitMessageProcessing()
|
||||
|
||||
const updatedContact = contactContext.contacts.findContact(thirdPartyContext.userUuid)
|
||||
expect(updatedContact.name).to.equal('Changed 3rd Party Name')
|
||||
@@ -122,7 +105,10 @@ describe('asymmetric messages', function () {
|
||||
const { sharedVault, contactContext, deinitContactContext } =
|
||||
await Collaboration.createSharedVaultWithAcceptedInvite(context)
|
||||
|
||||
const handleInitialContactShareMessage = contactContext.resolveWhenAsymmetricMessageProcessingCompletes()
|
||||
const handleInitialContactShareMessage = contactContext.resolveWhenAsyncFunctionCompletes(
|
||||
contactContext.asymmetric,
|
||||
'handleRemoteReceivedAsymmetricMessages',
|
||||
)
|
||||
|
||||
const { thirdPartyContext, deinitThirdPartyContext } = await Collaboration.inviteNewPartyToSharedVault(
|
||||
context,
|
||||
@@ -162,6 +148,7 @@ describe('asymmetric messages', function () {
|
||||
await Collaboration.acceptAllInvites(thirdPartyContext)
|
||||
|
||||
await contactContext.sync()
|
||||
contactContext.lockSyncing()
|
||||
|
||||
const sendContactSharePromise = context.resolveWhenSharedVaultServiceSendsContactShareMessage()
|
||||
|
||||
@@ -179,6 +166,7 @@ describe('asymmetric messages', function () {
|
||||
const thirdPartySpy = sinon.spy(thirdPartyContext.asymmetric, 'handleTrustedContactShareMessage')
|
||||
|
||||
await context.sync()
|
||||
contactContext.unlockSyncing()
|
||||
await contactContext.sync()
|
||||
await thirdPartyContext.sync()
|
||||
|
||||
@@ -194,12 +182,26 @@ describe('asymmetric messages', function () {
|
||||
const { sharedVault, contactContext, deinitContactContext } =
|
||||
await Collaboration.createSharedVaultWithAcceptedInvite(context)
|
||||
|
||||
contactContext.anticipateConsoleError(
|
||||
'(2x) Error decrypting contentKey from parameters',
|
||||
'Items keys are encrypted with new root key and are later decrypted in the test',
|
||||
)
|
||||
|
||||
contactContext.lockSyncing()
|
||||
|
||||
const promise = context.resolveWhenAsyncFunctionCompletes(
|
||||
context.sharedVaults._notifyVaultUsersOfKeyRotation,
|
||||
'execute',
|
||||
)
|
||||
await context.vaults.rotateVaultRootKey(sharedVault)
|
||||
await promise
|
||||
|
||||
const firstPartySpy = sinon.spy(context.asymmetric, 'handleTrustedSharedVaultRootKeyChangedMessage')
|
||||
const secondPartySpy = sinon.spy(contactContext.asymmetric, 'handleTrustedSharedVaultRootKeyChangedMessage')
|
||||
|
||||
await context.sync()
|
||||
|
||||
contactContext.unlockSyncing()
|
||||
await contactContext.sync()
|
||||
|
||||
expect(firstPartySpy.callCount).to.equal(0)
|
||||
@@ -212,7 +214,7 @@ describe('asymmetric messages', function () {
|
||||
const { sharedVault, contactContext, deinitContactContext } =
|
||||
await Collaboration.createSharedVaultWithAcceptedInvite(context)
|
||||
|
||||
await context.vaults.changeVaultNameAndDescription(sharedVault, {
|
||||
await context.changeVaultName(sharedVault, {
|
||||
name: 'New Name',
|
||||
description: 'New Description',
|
||||
})
|
||||
@@ -238,20 +240,13 @@ describe('asymmetric messages', function () {
|
||||
|
||||
contactContext.lockSyncing()
|
||||
|
||||
const sendPromise = context.resolveWhenAsyncFunctionCompletes(
|
||||
context.contacts,
|
||||
'sendOwnContactChangeEventToAllContacts',
|
||||
)
|
||||
await context.changePassword('new password')
|
||||
await sendPromise
|
||||
|
||||
const firstPartySpy = sinon.spy(context.asymmetric, 'handleTrustedSenderKeypairChangedMessage')
|
||||
const secondPartySpy = sinon.spy(contactContext.asymmetric, 'handleTrustedSenderKeypairChangedMessage')
|
||||
|
||||
const completedProcessingMessagesPromise = contactContext.resolveWhenAsymmetricMessageProcessingCompletes()
|
||||
contactContext.unlockSyncing()
|
||||
await contactContext.sync()
|
||||
await completedProcessingMessagesPromise
|
||||
await contactContext.syncAndAwaitMessageProcessing()
|
||||
|
||||
expect(firstPartySpy.callCount).to.equal(0)
|
||||
expect(secondPartySpy.callCount).to.equal(1)
|
||||
@@ -269,14 +264,12 @@ describe('asymmetric messages', function () {
|
||||
|
||||
await context.changePassword('new password')
|
||||
|
||||
await context.vaults.changeVaultNameAndDescription(sharedVault, {
|
||||
await context.changeVaultName(sharedVault, {
|
||||
name: 'New Name',
|
||||
description: 'New Description',
|
||||
})
|
||||
|
||||
const completedProcessingMessagesPromise = contactContext.resolveWhenAsymmetricMessageProcessingCompletes()
|
||||
await contactContext.sync()
|
||||
await completedProcessingMessagesPromise
|
||||
await contactContext.syncAndAwaitMessageProcessing()
|
||||
|
||||
const updatedVault = contactContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
|
||||
expect(updatedVault.name).to.equal('New Name')
|
||||
@@ -295,16 +288,14 @@ describe('asymmetric messages', function () {
|
||||
|
||||
await context.changePassword('new password')
|
||||
|
||||
await context.vaults.changeVaultNameAndDescription(sharedVault, {
|
||||
await context.changeVaultName(sharedVault, {
|
||||
name: 'New Name',
|
||||
description: 'New Description',
|
||||
})
|
||||
|
||||
context.lockSyncing()
|
||||
|
||||
const completedProcessingMessagesPromise = contactContext.resolveWhenAsymmetricMessageProcessingCompletes()
|
||||
await contactContext.sync()
|
||||
await completedProcessingMessagesPromise
|
||||
await contactContext.syncAndAwaitMessageProcessing()
|
||||
|
||||
/**
|
||||
* There's really no good way to await the exact call since
|
||||
@@ -313,12 +304,12 @@ describe('asymmetric messages', function () {
|
||||
await context.sleep(0.25)
|
||||
|
||||
const messages = await context.asymmetric.getInboundMessages()
|
||||
expect(messages.length).to.equal(0)
|
||||
expect(messages.getValue().length).to.equal(0)
|
||||
|
||||
await deinitContactContext()
|
||||
})
|
||||
|
||||
it.skip('should process sender keypair changed message', async () => {
|
||||
it('should process sender keypair changed message', async () => {
|
||||
const { contactContext, deinitContactContext } = await Collaboration.createContactContext()
|
||||
await Collaboration.createTrustedContactForUserOfContext(context, contactContext)
|
||||
await Collaboration.createTrustedContactForUserOfContext(contactContext, context)
|
||||
@@ -326,9 +317,7 @@ describe('asymmetric messages', function () {
|
||||
|
||||
await context.changePassword('new_password')
|
||||
|
||||
const completedProcessingMessagesPromise = contactContext.resolveWhenAsymmetricMessageProcessingCompletes()
|
||||
await contactContext.sync()
|
||||
await completedProcessingMessagesPromise
|
||||
await contactContext.syncAndAwaitMessageProcessing()
|
||||
|
||||
const updatedContact = contactContext.contacts.findContact(context.userUuid)
|
||||
|
||||
@@ -341,7 +330,7 @@ describe('asymmetric messages', function () {
|
||||
await deinitContactContext()
|
||||
})
|
||||
|
||||
it.skip('sender keypair changed message should be signed using old key pair', async () => {
|
||||
it('sender keypair changed message should be signed using old key pair', async () => {
|
||||
const { contactContext, deinitContactContext } = await Collaboration.createSharedVaultWithAcceptedInvite(context)
|
||||
|
||||
const oldKeyPair = context.encryption.getKeyPair()
|
||||
@@ -352,9 +341,7 @@ describe('asymmetric messages', function () {
|
||||
const secondPartySpy = sinon.spy(contactContext.asymmetric, 'handleTrustedSenderKeypairChangedMessage')
|
||||
|
||||
await context.sync()
|
||||
const completedProcessingMessagesPromise = contactContext.resolveWhenAsymmetricMessageProcessingCompletes()
|
||||
await contactContext.sync()
|
||||
await completedProcessingMessagesPromise
|
||||
await contactContext.syncAndAwaitMessageProcessing()
|
||||
|
||||
const message = secondPartySpy.args[0][0]
|
||||
const encryptedMessage = message.encrypted_message
|
||||
@@ -376,9 +363,7 @@ describe('asymmetric messages', function () {
|
||||
const newKeyPair = context.encryption.getKeyPair()
|
||||
const newSigningKeyPair = context.encryption.getSigningKeyPair()
|
||||
|
||||
const completedProcessingMessagesPromise = contactContext.resolveWhenAsymmetricMessageProcessingCompletes()
|
||||
await contactContext.sync()
|
||||
await completedProcessingMessagesPromise
|
||||
await contactContext.syncAndAwaitMessageProcessing()
|
||||
|
||||
const updatedContact = contactContext.contacts.findContact(context.userUuid)
|
||||
expect(updatedContact.publicKeySet.encryption).to.equal(newKeyPair.publicKey)
|
||||
@@ -395,7 +380,7 @@ describe('asymmetric messages', function () {
|
||||
|
||||
contactContext.lockSyncing()
|
||||
|
||||
await context.vaults.changeVaultNameAndDescription(sharedVault, {
|
||||
await context.changeVaultName(sharedVault, {
|
||||
name: 'New Name',
|
||||
description: 'New Description',
|
||||
})
|
||||
@@ -405,7 +390,7 @@ describe('asymmetric messages', function () {
|
||||
await promise
|
||||
|
||||
const messages = await contactContext.asymmetric.getInboundMessages()
|
||||
expect(messages.length).to.equal(0)
|
||||
expect(messages.getValue().length).to.equal(0)
|
||||
|
||||
const updatedVault = contactContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
|
||||
expect(updatedVault.name).to.not.equal('New Name')
|
||||
@@ -413,4 +398,85 @@ describe('asymmetric messages', function () {
|
||||
|
||||
await deinitContactContext()
|
||||
})
|
||||
|
||||
it('should be able to decrypt previously sent own messages', async () => {
|
||||
const { sharedVault, contactContext, deinitContactContext } =
|
||||
await Collaboration.createSharedVaultWithAcceptedInvite(context)
|
||||
|
||||
contactContext.lockSyncing()
|
||||
|
||||
await context.changeVaultName(sharedVault, {
|
||||
name: 'New Name',
|
||||
description: 'New Description',
|
||||
})
|
||||
|
||||
const usecase = context.application.dependencies.get(TYPES.ResendAllMessages)
|
||||
const result = await usecase.execute({
|
||||
keys: {
|
||||
encryption: context.encryption.getKeyPair(),
|
||||
signing: context.encryption.getSigningKeyPair(),
|
||||
},
|
||||
previousKeys: {
|
||||
encryption: context.encryption.getKeyPair(),
|
||||
signing: context.encryption.getSigningKeyPair(),
|
||||
},
|
||||
})
|
||||
|
||||
expect(result.isFailed()).to.be.false
|
||||
|
||||
await deinitContactContext()
|
||||
})
|
||||
|
||||
it('sending a new vault invite to a trusted contact then changing account password should still allow contact to trust invite', async () => {
|
||||
const { contactContext, contact, deinitContactContext } = await Collaboration.createSharedVaultWithAcceptedInvite(
|
||||
context,
|
||||
)
|
||||
|
||||
contactContext.lockSyncing()
|
||||
|
||||
const newVault = await Collaboration.createSharedVault(context)
|
||||
|
||||
await context.vaultInvites.inviteContactToSharedVault(
|
||||
newVault,
|
||||
contact,
|
||||
SharedVaultUserPermission.PERMISSIONS.Write,
|
||||
)
|
||||
|
||||
await contactContext.runAnyRequestToPreventRefreshTokenFromExpiring()
|
||||
|
||||
await context.changePassword('new password')
|
||||
|
||||
await contactContext.runAnyRequestToPreventRefreshTokenFromExpiring()
|
||||
|
||||
/**
|
||||
* When resending keypair changed messages here, we expect that one of their previous messages will fail to decrypt.
|
||||
* This is because the first contact keypair change message was encrypted using their keypair N (original), then after
|
||||
* the second password change, the reference to "previous" key will be N + 1 instead of N, so there is no longer a reference
|
||||
* to the original keypair. This is not a problem, and in fact even if the message were decryptable, it would be skipped
|
||||
* because we do not want to re-send keypair changed messages.
|
||||
*/
|
||||
|
||||
await context.changePassword('new password 2')
|
||||
|
||||
const messages = await contactContext.asymmetric.getInboundMessages()
|
||||
if (messages.isFailed()) {
|
||||
console.error(messages.getError())
|
||||
}
|
||||
|
||||
expect(messages.isFailed()).to.be.false
|
||||
expect(messages.getValue().length).to.equal(2)
|
||||
|
||||
contactContext.unlockSyncing()
|
||||
await contactContext.syncAndAwaitInviteProcessing()
|
||||
|
||||
const invites = contactContext.vaultInvites.getCachedPendingInviteRecords()
|
||||
expect(invites.length).to.equal(1)
|
||||
|
||||
const invite = invites[0]
|
||||
expect(invite.trusted).to.equal(true)
|
||||
|
||||
await contactContext.vaultInvites.acceptInvite(invite)
|
||||
|
||||
await deinitContactContext()
|
||||
}).timeout(Factory.ThirtySecondTimeout)
|
||||
})
|
||||
|
||||
@@ -17,7 +17,7 @@ describe('shared vault conflicts', function () {
|
||||
beforeEach(async function () {
|
||||
localStorage.clear()
|
||||
|
||||
context = await Factory.createAppContextWithRealCrypto()
|
||||
context = await Factory.createVaultsContextWithRealCrypto()
|
||||
|
||||
await context.launch()
|
||||
await context.register()
|
||||
|
||||
@@ -17,7 +17,7 @@ describe('contacts', function () {
|
||||
beforeEach(async function () {
|
||||
localStorage.clear()
|
||||
|
||||
context = await Factory.createAppContextWithRealCrypto()
|
||||
context = await Factory.createVaultsContextWithRealCrypto()
|
||||
|
||||
await context.launch()
|
||||
await context.register()
|
||||
@@ -101,6 +101,5 @@ describe('contacts', function () {
|
||||
await deinitContactContext()
|
||||
})
|
||||
|
||||
it.skip('should be able to refresh a contact using a collaborationID that includes full chain of previous public keys', async () => {
|
||||
})
|
||||
it.skip('should be able to refresh a contact using a collaborationID that includes full chain of previous public keys', async () => {})
|
||||
})
|
||||
|
||||
@@ -17,7 +17,7 @@ describe('shared vault crypto', function () {
|
||||
beforeEach(async function () {
|
||||
localStorage.clear()
|
||||
|
||||
context = await Factory.createAppContextWithRealCrypto()
|
||||
context = await Factory.createVaultsContextWithRealCrypto()
|
||||
|
||||
await context.launch()
|
||||
await context.register()
|
||||
@@ -28,11 +28,13 @@ describe('shared vault crypto', function () {
|
||||
const appIdentifier = context.identifier
|
||||
await context.deinit()
|
||||
|
||||
let recreatedContext = await Factory.createAppContextWithRealCrypto(appIdentifier)
|
||||
let recreatedContext = await Factory.createVaultsContextWithRealCrypto(appIdentifier)
|
||||
await recreatedContext.launch()
|
||||
|
||||
expect(recreatedContext.encryption.getKeyPair()).to.not.be.undefined
|
||||
expect(recreatedContext.encryption.getSigningKeyPair()).to.not.be.undefined
|
||||
|
||||
await recreatedContext.deinit()
|
||||
})
|
||||
|
||||
it('changing user password should re-encrypt all key system root keys and contacts with new user root key', async () => {
|
||||
@@ -90,11 +92,13 @@ describe('shared vault crypto', function () {
|
||||
await deinitContactContext()
|
||||
})
|
||||
|
||||
it.skip('encrypting an item into storage then loading it should verify authenticity of original content rather than most recent symmetric signature', async () => {
|
||||
it('encrypting an item into storage then loading it should verify authenticity of original content rather than most recent symmetric signature', async () => {
|
||||
const { note, contactContext, deinitContactContext } =
|
||||
await Collaboration.createSharedVaultWithAcceptedInviteAndNote(context)
|
||||
|
||||
await contactContext.changeNoteTitleAndSync(note, 'new title')
|
||||
const contactNote = contactContext.items.findItem(note.uuid)
|
||||
|
||||
await contactContext.changeNoteTitleAndSync(contactNote, 'new title')
|
||||
|
||||
/** Override decrypt result to return failing signature */
|
||||
const objectToSpy = context.encryption
|
||||
@@ -103,6 +107,7 @@ describe('shared vault crypto', function () {
|
||||
|
||||
const decryptedPayloads = await objectToSpy.decryptSplit(split)
|
||||
expect(decryptedPayloads.length).to.equal(1)
|
||||
expect(decryptedPayloads[0].content_type).to.equal(ContentType.TYPES.Note)
|
||||
|
||||
const payload = decryptedPayloads[0]
|
||||
const mutatedPayload = new DecryptedPayload({
|
||||
@@ -118,6 +123,7 @@ describe('shared vault crypto', function () {
|
||||
|
||||
return [mutatedPayload]
|
||||
})
|
||||
|
||||
await context.sync()
|
||||
|
||||
let updatedNote = context.items.findItem(note.uuid)
|
||||
@@ -127,7 +133,7 @@ describe('shared vault crypto', function () {
|
||||
const appIdentifier = context.identifier
|
||||
await context.deinit()
|
||||
|
||||
let recreatedContext = await Factory.createAppContextWithRealCrypto(appIdentifier)
|
||||
let recreatedContext = await Factory.createVaultsContextWithRealCrypto(appIdentifier)
|
||||
await recreatedContext.launch()
|
||||
|
||||
updatedNote = recreatedContext.items.findItem(note.uuid)
|
||||
@@ -140,7 +146,7 @@ describe('shared vault crypto', function () {
|
||||
|
||||
await recreatedContext.deinit()
|
||||
|
||||
recreatedContext = await Factory.createAppContextWithRealCrypto(appIdentifier)
|
||||
recreatedContext = await Factory.createVaultsContextWithRealCrypto(appIdentifier)
|
||||
await recreatedContext.launch()
|
||||
|
||||
/** Decrypting from storage will now verify current user symmetric signature only */
|
||||
|
||||
@@ -18,7 +18,7 @@ describe('shared vault deletion', function () {
|
||||
beforeEach(async function () {
|
||||
localStorage.clear()
|
||||
|
||||
context = await Factory.createAppContextWithRealCrypto()
|
||||
context = await Factory.createVaultsContextWithRealCrypto()
|
||||
|
||||
await context.launch()
|
||||
await context.register()
|
||||
|
||||
@@ -5,7 +5,7 @@ import * as Collaboration from '../lib/Collaboration.js'
|
||||
chai.use(chaiAsPromised)
|
||||
const expect = chai.expect
|
||||
|
||||
describe.skip('shared vault files', function () {
|
||||
describe('shared vault files', function () {
|
||||
this.timeout(Factory.TwentySecondTimeout)
|
||||
|
||||
let context
|
||||
@@ -19,7 +19,7 @@ describe.skip('shared vault files', function () {
|
||||
beforeEach(async function () {
|
||||
localStorage.clear()
|
||||
|
||||
context = await Factory.createAppContextWithRealCrypto()
|
||||
context = await Factory.createVaultsContextWithRealCrypto()
|
||||
|
||||
await context.launch()
|
||||
await context.register()
|
||||
@@ -29,7 +29,7 @@ describe.skip('shared vault files', function () {
|
||||
})
|
||||
|
||||
describe('private vaults', () => {
|
||||
it('should be able to upload and download file to vault as owner', async () => {
|
||||
it('should be able to upload and download file to private vault as owner', async () => {
|
||||
const vault = await Collaboration.createPrivateVault(context)
|
||||
const response = await fetch('/mocha/assets/small_file.md')
|
||||
const buffer = new Uint8Array(await response.arrayBuffer())
|
||||
@@ -45,7 +45,7 @@ describe.skip('shared vault files', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('should be able to upload and download file to vault as owner', async () => {
|
||||
it('should be able to upload and download file to shared vault as owner', async () => {
|
||||
const sharedVault = await Collaboration.createSharedVault(context)
|
||||
const response = await fetch('/mocha/assets/small_file.md')
|
||||
const buffer = new Uint8Array(await response.arrayBuffer())
|
||||
|
||||
@@ -17,7 +17,7 @@ describe.skip('vault importing', function () {
|
||||
beforeEach(async function () {
|
||||
localStorage.clear()
|
||||
|
||||
context = await Factory.createAppContextWithRealCrypto()
|
||||
context = await Factory.createVaultsContextWithRealCrypto()
|
||||
|
||||
await context.launch()
|
||||
await context.register()
|
||||
@@ -39,7 +39,7 @@ describe.skip('vault importing', function () {
|
||||
|
||||
const backupData = await context.application.createEncryptedBackupFileForAutomatedDesktopBackups()
|
||||
|
||||
const otherContext = await Factory.createAppContextWithRealCrypto()
|
||||
const otherContext = await Factory.createVaultsContextWithRealCrypto()
|
||||
await otherContext.launch()
|
||||
|
||||
await otherContext.application.importData(backupData)
|
||||
|
||||
@@ -17,7 +17,7 @@ describe('shared vault invites', function () {
|
||||
beforeEach(async function () {
|
||||
localStorage.clear()
|
||||
|
||||
context = await Factory.createAppContextWithRealCrypto()
|
||||
context = await Factory.createVaultsContextWithRealCrypto()
|
||||
await context.launch()
|
||||
await context.register()
|
||||
})
|
||||
|
||||
@@ -17,7 +17,7 @@ describe('shared vault items', function () {
|
||||
beforeEach(async function () {
|
||||
localStorage.clear()
|
||||
|
||||
context = await Factory.createAppContextWithRealCrypto()
|
||||
context = await Factory.createVaultsContextWithRealCrypto()
|
||||
|
||||
await context.launch()
|
||||
await context.register()
|
||||
@@ -38,13 +38,19 @@ describe('shared vault items', function () {
|
||||
it('should add item to shared vault with contact', async () => {
|
||||
const note = await context.createSyncedNote('foo', 'bar')
|
||||
|
||||
const { sharedVault, deinitContactContext } = await Collaboration.createSharedVaultWithAcceptedInvite(context)
|
||||
const { sharedVault, contactContext, deinitContactContext } =
|
||||
await Collaboration.createSharedVaultWithAcceptedInvite(context)
|
||||
|
||||
await Collaboration.moveItemToVault(context, sharedVault, note)
|
||||
|
||||
await contactContext.sync()
|
||||
|
||||
const updatedNote = context.items.findItem(note.uuid)
|
||||
expect(updatedNote.key_system_identifier).to.equal(sharedVault.systemIdentifier)
|
||||
|
||||
const contactNote = contactContext.items.findItem(note.uuid)
|
||||
expect(contactNote.key_system_identifier).to.equal(sharedVault.systemIdentifier)
|
||||
|
||||
await deinitContactContext()
|
||||
})
|
||||
|
||||
@@ -117,7 +123,7 @@ describe('shared vault items', function () {
|
||||
})
|
||||
|
||||
it('adding item to vault while belonging to other vault should move the item to new vault', async () => {
|
||||
const { note, sharedVault, contactContext, contact, deinitContactContext } =
|
||||
const { note, contactContext, contact, deinitContactContext } =
|
||||
await Collaboration.createSharedVaultWithAcceptedInviteAndNote(context)
|
||||
|
||||
const { sharedVault: otherSharedVault } = await Collaboration.createSharedVaultAndInviteContact(
|
||||
@@ -126,6 +132,8 @@ describe('shared vault items', function () {
|
||||
contact,
|
||||
)
|
||||
|
||||
await Collaboration.acceptAllInvites(contactContext)
|
||||
|
||||
const updatedNote = await Collaboration.moveItemToVault(context, otherSharedVault, note)
|
||||
|
||||
expect(updatedNote.key_system_identifier).to.equal(otherSharedVault.systemIdentifier)
|
||||
@@ -134,7 +142,6 @@ describe('shared vault items', function () {
|
||||
await contactContext.sync()
|
||||
|
||||
const receivedNote = contactContext.items.findItem(note.uuid)
|
||||
expect(receivedNote).to.not.be.undefined
|
||||
expect(receivedNote.title).to.equal(note.title)
|
||||
expect(receivedNote.key_system_identifier).to.equal(otherSharedVault.systemIdentifier)
|
||||
expect(receivedNote.shared_vault_uuid).to.equal(otherSharedVault.sharing.sharedVaultUuid)
|
||||
|
||||
@@ -16,7 +16,7 @@ describe('vault key management', function () {
|
||||
beforeEach(async function () {
|
||||
localStorage.clear()
|
||||
|
||||
context = await Factory.createAppContextWithRealCrypto()
|
||||
context = await Factory.createVaultsContextWithRealCrypto()
|
||||
|
||||
await context.launch()
|
||||
})
|
||||
|
||||
@@ -17,7 +17,7 @@ describe('vault key rotation', function () {
|
||||
beforeEach(async function () {
|
||||
localStorage.clear()
|
||||
|
||||
context = await Factory.createAppContextWithRealCrypto()
|
||||
context = await Factory.createVaultsContextWithRealCrypto()
|
||||
|
||||
await context.launch()
|
||||
await context.register()
|
||||
@@ -99,7 +99,7 @@ describe('vault key rotation', function () {
|
||||
await context.vaults.rotateVaultRootKey(sharedVault)
|
||||
await promise
|
||||
|
||||
const outboundMessages = await context.asymmetric.getOutboundMessages()
|
||||
const outboundMessages = (await context.asymmetric.getOutboundMessages()).getValue()
|
||||
const expectedMessages = ['root key change', 'vault metadata change']
|
||||
expect(outboundMessages.length).to.equal(expectedMessages.length)
|
||||
|
||||
@@ -154,10 +154,8 @@ describe('vault key rotation', function () {
|
||||
await context.vaults.rotateVaultRootKey(sharedVault)
|
||||
await promise
|
||||
|
||||
const contactPromise = contactContext.resolveWhenAsymmetricMessageProcessingCompletes()
|
||||
contactContext.unlockSyncing()
|
||||
await contactContext.sync()
|
||||
await contactPromise
|
||||
await contactContext.syncAndAwaitMessageProcessing()
|
||||
|
||||
const newPrimaryItemsKey = contactContext.keys.getPrimaryKeySystemItemsKey(sharedVault.systemIdentifier)
|
||||
expect(newPrimaryItemsKey).to.not.be.undefined
|
||||
@@ -217,7 +215,7 @@ describe('vault key rotation', function () {
|
||||
await context.vaults.rotateVaultRootKey(sharedVault)
|
||||
await firstPromise
|
||||
|
||||
const asymmetricMessageAfterFirstChange = await context.asymmetric.getOutboundMessages()
|
||||
const asymmetricMessageAfterFirstChange = (await context.asymmetric.getOutboundMessages()).getValue()
|
||||
const expectedMessages = ['root key change', 'vault metadata change']
|
||||
expect(asymmetricMessageAfterFirstChange.length).to.equal(expectedMessages.length)
|
||||
|
||||
@@ -227,7 +225,7 @@ describe('vault key rotation', function () {
|
||||
await context.vaults.rotateVaultRootKey(sharedVault)
|
||||
await secondPromise
|
||||
|
||||
const asymmetricMessageAfterSecondChange = await context.asymmetric.getOutboundMessages()
|
||||
const asymmetricMessageAfterSecondChange = (await context.asymmetric.getOutboundMessages()).getValue()
|
||||
expect(asymmetricMessageAfterSecondChange.length).to.equal(expectedMessages.length)
|
||||
|
||||
const messageAfterSecondChange = asymmetricMessageAfterSecondChange[0]
|
||||
|
||||
@@ -17,13 +17,13 @@ describe('keypair change', function () {
|
||||
beforeEach(async function () {
|
||||
localStorage.clear()
|
||||
|
||||
context = await Factory.createAppContextWithRealCrypto()
|
||||
context = await Factory.createVaultsContextWithRealCrypto()
|
||||
|
||||
await context.launch()
|
||||
await context.register()
|
||||
})
|
||||
|
||||
it.skip('contacts should be able to handle receiving multiple keypair changed messages and trust them in order', async () => {
|
||||
it('contacts should be able to handle receiving multiple keypair changed messages and trust them in order', async () => {
|
||||
const { note, contactContext, deinitContactContext } =
|
||||
await Collaboration.createSharedVaultWithAcceptedInviteAndNote(context)
|
||||
|
||||
@@ -39,20 +39,24 @@ describe('keypair change', function () {
|
||||
publicKeyChain.push(context.publicKey)
|
||||
signingPublicKeyChain.push(context.signingPublicKey)
|
||||
|
||||
await contactContext.runAnyRequestToPreventRefreshTokenFromExpiring()
|
||||
|
||||
await context.changePassword('new_password-2')
|
||||
publicKeyChain.push(context.publicKey)
|
||||
signingPublicKeyChain.push(context.signingPublicKey)
|
||||
|
||||
await contactContext.runAnyRequestToPreventRefreshTokenFromExpiring()
|
||||
|
||||
await context.changePassword('new_password-3')
|
||||
publicKeyChain.push(context.publicKey)
|
||||
signingPublicKeyChain.push(context.signingPublicKey)
|
||||
|
||||
await contactContext.runAnyRequestToPreventRefreshTokenFromExpiring()
|
||||
|
||||
await context.changeNoteTitleAndSync(note, 'new title')
|
||||
|
||||
contactContext.unlockSyncing()
|
||||
const promise = contactContext.resolveWhenAsymmetricMessageProcessingCompletes()
|
||||
await contactContext.sync()
|
||||
await promise
|
||||
await contactContext.syncAndAwaitMessageProcessing()
|
||||
|
||||
const originatorContact = contactContext.contacts.findContact(context.userUuid)
|
||||
let currentKeySet = originatorContact.publicKeySet
|
||||
@@ -70,7 +74,7 @@ describe('keypair change', function () {
|
||||
expect(receivedNote.signatureData.result.passes).to.be.true
|
||||
|
||||
await deinitContactContext()
|
||||
})
|
||||
}).timeout(Factory.ThirtySecondTimeout)
|
||||
|
||||
it('should not trust messages sent with previous key pair', async () => {
|
||||
const { sharedVault, contactContext, deinitContactContext } =
|
||||
@@ -86,15 +90,13 @@ describe('keypair change', function () {
|
||||
sinon.stub(context.encryption, 'getKeyPair').returns(previousKeyPair)
|
||||
sinon.stub(context.encryption, 'getSigningKeyPair').returns(previousSigningKeyPair)
|
||||
|
||||
await context.vaults.changeVaultNameAndDescription(sharedVault, {
|
||||
await context.changeVaultName(sharedVault, {
|
||||
name: 'New Name',
|
||||
description: 'New Description',
|
||||
})
|
||||
|
||||
contactContext.unlockSyncing()
|
||||
const promise = contactContext.resolveWhenAsymmetricMessageProcessingCompletes()
|
||||
await contactContext.sync()
|
||||
await promise
|
||||
await contactContext.syncAndAwaitMessageProcessing()
|
||||
|
||||
const updatedVault = contactContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
|
||||
expect(updatedVault.name).to.equal(sharedVault.name)
|
||||
@@ -133,23 +135,18 @@ describe('keypair change', function () {
|
||||
|
||||
contactContext.lockSyncing()
|
||||
|
||||
await context.vaults.changeVaultNameAndDescription(sharedVault, {
|
||||
await context.changeVaultName(sharedVault, {
|
||||
name: 'New Name',
|
||||
description: 'New Description',
|
||||
})
|
||||
|
||||
const originalMessages = await contactContext.asymmetric.getInboundMessages()
|
||||
const originalMessages = (await contactContext.asymmetric.getInboundMessages()).getValue()
|
||||
expect(originalMessages.length).to.equal(1)
|
||||
const originalMessage = originalMessages[0]
|
||||
|
||||
const promise = context.resolveWhenAsyncFunctionCompletes(
|
||||
context.application.dependencies.get(TYPES.HandleKeyPairChange),
|
||||
'execute',
|
||||
)
|
||||
await context.changePassword('new_password')
|
||||
await promise
|
||||
|
||||
const updatedMessages = await contactContext.asymmetric.getInboundMessages()
|
||||
const updatedMessages = (await contactContext.asymmetric.getInboundMessages()).getValue()
|
||||
const expectedMessages = ['keypair-change', 'vault-change']
|
||||
expect(updatedMessages.length).to.equal(expectedMessages.length)
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ describe('shared vault permissions', function () {
|
||||
beforeEach(async function () {
|
||||
localStorage.clear()
|
||||
|
||||
context = await Factory.createAppContextWithRealCrypto()
|
||||
context = await Factory.createVaultsContextWithRealCrypto()
|
||||
|
||||
await context.launch()
|
||||
await context.register()
|
||||
|
||||
@@ -18,7 +18,7 @@ describe('public key cryptography', function () {
|
||||
beforeEach(async function () {
|
||||
localStorage.clear()
|
||||
|
||||
context = await Factory.createAppContextWithRealCrypto()
|
||||
context = await Factory.createVaultsContextWithRealCrypto()
|
||||
|
||||
await context.launch()
|
||||
await context.register()
|
||||
@@ -40,7 +40,7 @@ describe('public key cryptography', function () {
|
||||
const password = context.password
|
||||
await context.signout()
|
||||
|
||||
const recreatedContext = await Factory.createAppContextWithRealCrypto()
|
||||
const recreatedContext = await Factory.createVaultsContextWithRealCrypto()
|
||||
await recreatedContext.launch()
|
||||
recreatedContext.email = email
|
||||
recreatedContext.password = password
|
||||
@@ -51,6 +51,8 @@ describe('public key cryptography', function () {
|
||||
|
||||
expect(recreatedContext.sessions.getSigningPublicKey()).to.not.be.undefined
|
||||
expect(recreatedContext.encryption.getSigningKeyPair().privateKey).to.not.be.undefined
|
||||
|
||||
await recreatedContext.deinit()
|
||||
})
|
||||
|
||||
it('should rotate keypair during password change', async () => {
|
||||
@@ -74,7 +76,7 @@ describe('public key cryptography', function () {
|
||||
})
|
||||
|
||||
it('should allow option to enable collaboration for previously signed in accounts', async () => {
|
||||
const newContext = await Factory.createAppContextWithRealCrypto()
|
||||
const newContext = await Factory.createVaultsContextWithRealCrypto()
|
||||
await newContext.launch()
|
||||
|
||||
await newContext.register()
|
||||
@@ -94,5 +96,7 @@ describe('public key cryptography', function () {
|
||||
expect(result.error).to.be.undefined
|
||||
|
||||
expect(newContext.application.sessions.isUserMissingKeyPair()).to.be.false
|
||||
|
||||
await newContext.deinit()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -10,15 +10,10 @@ describe('shared vaults', function () {
|
||||
let context
|
||||
let vaults
|
||||
|
||||
afterEach(async function () {
|
||||
await context.deinit()
|
||||
localStorage.clear()
|
||||
})
|
||||
|
||||
beforeEach(async function () {
|
||||
localStorage.clear()
|
||||
|
||||
context = await Factory.createAppContextWithRealCrypto()
|
||||
context = await Factory.createVaultsContextWithRealCrypto()
|
||||
|
||||
await context.launch()
|
||||
await context.register()
|
||||
@@ -26,11 +21,18 @@ describe('shared vaults', function () {
|
||||
vaults = context.vaults
|
||||
})
|
||||
|
||||
afterEach(async function () {
|
||||
await context.deinit()
|
||||
localStorage.clear()
|
||||
})
|
||||
|
||||
it('should update vault name and description', async () => {
|
||||
const { sharedVault, contactContext, deinitContactContext } =
|
||||
await Collaboration.createSharedVaultWithAcceptedInvite(context)
|
||||
|
||||
await vaults.changeVaultNameAndDescription(sharedVault, {
|
||||
contactContext.lockSyncing()
|
||||
|
||||
await context.changeVaultName(sharedVault, {
|
||||
name: 'new vault name',
|
||||
description: 'new vault description',
|
||||
})
|
||||
@@ -39,9 +41,8 @@ describe('shared vaults', function () {
|
||||
expect(updatedVault.name).to.equal('new vault name')
|
||||
expect(updatedVault.description).to.equal('new vault description')
|
||||
|
||||
const promise = contactContext.resolveWhenAsymmetricMessageProcessingCompletes()
|
||||
await contactContext.sync()
|
||||
await promise
|
||||
contactContext.unlockSyncing()
|
||||
await contactContext.syncAndAwaitMessageProcessing()
|
||||
|
||||
const contactVault = contactContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
|
||||
expect(contactVault.name).to.equal('new vault name')
|
||||
@@ -65,7 +66,7 @@ describe('shared vaults', function () {
|
||||
expect(contactContext.keys.getPrimaryKeySystemRootKey(sharedVault.systemIdentifier)).to.be.undefined
|
||||
expect(contactContext.keys.getKeySystemItemsKeys(sharedVault.systemIdentifier)).to.be.empty
|
||||
|
||||
const recreatedContext = await Factory.createAppContextWithRealCrypto(contactContext.identifier)
|
||||
const recreatedContext = await Factory.createVaultsContextWithRealCrypto(contactContext.identifier)
|
||||
await recreatedContext.launch()
|
||||
|
||||
expect(recreatedContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })).to.be.undefined
|
||||
@@ -92,7 +93,7 @@ describe('shared vaults', function () {
|
||||
expect(contactContext.keys.getPrimaryKeySystemRootKey(sharedVault.systemIdentifier)).to.be.undefined
|
||||
expect(contactContext.keys.getKeySystemItemsKeys(sharedVault.systemIdentifier)).to.be.empty
|
||||
|
||||
const recreatedContext = await Factory.createAppContextWithRealCrypto(contactContext.identifier)
|
||||
const recreatedContext = await Factory.createVaultsContextWithRealCrypto(contactContext.identifier)
|
||||
await recreatedContext.launch()
|
||||
|
||||
expect(recreatedContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })).to.be.undefined
|
||||
@@ -127,4 +128,52 @@ describe('shared vaults', function () {
|
||||
|
||||
await deinitThirdPartyContext()
|
||||
})
|
||||
|
||||
it('syncing a shared vault exclusively should not retrieve non vault items', async () => {
|
||||
const { sharedVault, contactContext, deinitContactContext } =
|
||||
await Collaboration.createSharedVaultWithAcceptedInvite(context)
|
||||
|
||||
await contactContext.createSyncedNote('foo', 'bar')
|
||||
|
||||
const syncPromise = contactContext.awaitNextSyncSharedVaultFromScratchEvent()
|
||||
|
||||
await contactContext.application.sync.syncSharedVaultsFromScratch([sharedVault.sharing.sharedVaultUuid])
|
||||
|
||||
const syncResponse = await syncPromise
|
||||
|
||||
const expectedItems = ['key system items key']
|
||||
|
||||
expect(syncResponse.retrievedPayloads.length).to.equal(expectedItems.length)
|
||||
|
||||
await deinitContactContext()
|
||||
})
|
||||
|
||||
it('syncing a shared vault with note exclusively should retrieve note and items key', async () => {
|
||||
const { sharedVault, contactContext, deinitContactContext } =
|
||||
await Collaboration.createSharedVaultWithAcceptedInviteAndNote(context)
|
||||
|
||||
const syncPromise = contactContext.awaitNextSyncSharedVaultFromScratchEvent()
|
||||
|
||||
await contactContext.application.sync.syncSharedVaultsFromScratch([sharedVault.sharing.sharedVaultUuid])
|
||||
|
||||
const syncResponse = await syncPromise
|
||||
|
||||
const expectedItems = ['key system items key', 'note']
|
||||
|
||||
expect(syncResponse.retrievedPayloads.length).to.equal(expectedItems.length)
|
||||
|
||||
await deinitContactContext()
|
||||
})
|
||||
|
||||
it('regular sync should not needlessly return vault items', async () => {
|
||||
await Collaboration.createSharedVault(context)
|
||||
|
||||
const promise = context.resolveWithSyncRetrievedPayloads()
|
||||
|
||||
await context.sync()
|
||||
|
||||
const retrievedPayloads = await promise
|
||||
|
||||
expect(retrievedPayloads.length).to.equal(0)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -17,7 +17,7 @@ describe('signatures', function () {
|
||||
beforeEach(async function () {
|
||||
localStorage.clear()
|
||||
|
||||
context = await Factory.createAppContextWithRealCrypto()
|
||||
context = await Factory.createVaultsContextWithRealCrypto()
|
||||
|
||||
await context.launch()
|
||||
await context.register()
|
||||
|
||||
@@ -17,7 +17,7 @@ describe('vaults', function () {
|
||||
beforeEach(async function () {
|
||||
localStorage.clear()
|
||||
|
||||
context = await Factory.createAppContextWithRealCrypto()
|
||||
context = await Factory.createVaultsContextWithRealCrypto()
|
||||
|
||||
await context.launch()
|
||||
|
||||
@@ -77,7 +77,7 @@ describe('vaults', function () {
|
||||
await vaults.moveItemToVault(vault, note)
|
||||
await context.deinit()
|
||||
|
||||
const recreatedContext = await Factory.createAppContextWithRealCrypto(appIdentifier)
|
||||
const recreatedContext = await Factory.createVaultsContextWithRealCrypto(appIdentifier)
|
||||
await recreatedContext.launch()
|
||||
|
||||
const updatedNote = recreatedContext.items.findItem(note.uuid)
|
||||
@@ -101,7 +101,7 @@ describe('vaults', function () {
|
||||
|
||||
await context.deinit()
|
||||
|
||||
const recreatedContext = await Factory.createAppContextWithRealCrypto(appIdentifier)
|
||||
const recreatedContext = await Factory.createVaultsContextWithRealCrypto(appIdentifier)
|
||||
await recreatedContext.launch()
|
||||
|
||||
const notes = recreatedContext.notes
|
||||
@@ -128,7 +128,7 @@ describe('vaults', function () {
|
||||
|
||||
await context.deinit()
|
||||
|
||||
const recreatedContext = await Factory.createAppContextWithRealCrypto(appIdentifier)
|
||||
const recreatedContext = await Factory.createVaultsContextWithRealCrypto(appIdentifier)
|
||||
await recreatedContext.launch()
|
||||
|
||||
const updatedNote = recreatedContext.items.findItem(note.uuid)
|
||||
@@ -181,7 +181,7 @@ describe('vaults', function () {
|
||||
await vaults.moveItemToVault(vault, note)
|
||||
await context.deinit()
|
||||
|
||||
const recreatedContext = await Factory.createAppContextWithRealCrypto(appIdentifier)
|
||||
const recreatedContext = await Factory.createVaultsContextWithRealCrypto(appIdentifier)
|
||||
await recreatedContext.launch()
|
||||
|
||||
const updatedNote = recreatedContext.items.findItem(note.uuid)
|
||||
|
||||
Reference in New Issue
Block a user