refactor: application dependency management (#2363)
This commit is contained in:
@@ -92,11 +92,11 @@ describe('upgrading', () => {
|
||||
version: oldVersion,
|
||||
})
|
||||
|
||||
expect((await this.application.encryptionService.rootKeyManager.getRootKeyWrapperKeyParams()).version).to.equal(
|
||||
expect((await this.application.encryption.rootKeyManager.getRootKeyWrapperKeyParams()).version).to.equal(
|
||||
oldVersion,
|
||||
)
|
||||
expect((await this.application.encryptionService.getRootKeyParams()).version).to.equal(oldVersion)
|
||||
expect((await this.application.encryptionService.getRootKey()).keyVersion).to.equal(oldVersion)
|
||||
expect((await this.application.encryption.getRootKeyParams()).version).to.equal(oldVersion)
|
||||
expect((await this.application.encryption.getRootKey()).keyVersion).to.equal(oldVersion)
|
||||
|
||||
this.application.setLaunchCallback({
|
||||
receiveChallenge: this.receiveChallenge,
|
||||
@@ -104,15 +104,15 @@ describe('upgrading', () => {
|
||||
const result = await this.application.upgradeProtocolVersion()
|
||||
expect(result).to.deep.equal({ success: true })
|
||||
|
||||
const wrappedRootKey = await this.application.encryptionService.rootKeyManager.getWrappedRootKey()
|
||||
const wrappedRootKey = await this.application.encryption.rootKeyManager.getWrappedRootKey()
|
||||
const payload = new EncryptedPayload(wrappedRootKey)
|
||||
expect(payload.version).to.equal(newVersion)
|
||||
|
||||
expect((await this.application.encryptionService.rootKeyManager.getRootKeyWrapperKeyParams()).version).to.equal(
|
||||
expect((await this.application.encryption.rootKeyManager.getRootKeyWrapperKeyParams()).version).to.equal(
|
||||
newVersion,
|
||||
)
|
||||
expect((await this.application.encryptionService.getRootKeyParams()).version).to.equal(newVersion)
|
||||
expect((await this.application.encryptionService.getRootKey()).keyVersion).to.equal(newVersion)
|
||||
expect((await this.application.encryption.getRootKeyParams()).version).to.equal(newVersion)
|
||||
expect((await this.application.encryption.getRootKey()).keyVersion).to.equal(newVersion)
|
||||
|
||||
/**
|
||||
* Immediately logging out ensures we don't rely on subsequent
|
||||
@@ -120,8 +120,8 @@ describe('upgrading', () => {
|
||||
*/
|
||||
this.application = await Factory.signOutApplicationAndReturnNew(this.application)
|
||||
await this.application.signIn(this.email, this.password, undefined, undefined, undefined, true)
|
||||
expect(this.application.itemManager.getDisplayableNotes().length).to.equal(1)
|
||||
expect(this.application.payloadManager.invalidPayloads).to.be.empty
|
||||
expect(this.application.items.getDisplayableNotes().length).to.equal(1)
|
||||
expect(this.application.payloads.invalidPayloads).to.be.empty
|
||||
}).timeout(15000)
|
||||
|
||||
it('upgrading from 003 to 004 with passcode only then reiniting app should create valid state', async function () {
|
||||
@@ -155,7 +155,7 @@ describe('upgrading', () => {
|
||||
await appFirst.launch(true)
|
||||
const result = await appFirst.upgradeProtocolVersion()
|
||||
expect(result).to.deep.equal({ success: true })
|
||||
expect(appFirst.payloadManager.invalidPayloads).to.be.empty
|
||||
expect(appFirst.payloads.invalidPayloads).to.be.empty
|
||||
await Factory.safeDeinit(appFirst)
|
||||
|
||||
/** Recreate the once more */
|
||||
@@ -166,15 +166,15 @@ describe('upgrading', () => {
|
||||
},
|
||||
})
|
||||
await appSecond.launch(true)
|
||||
expect(appSecond.payloadManager.invalidPayloads).to.be.empty
|
||||
expect(appSecond.payloads.invalidPayloads).to.be.empty
|
||||
await Factory.safeDeinit(appSecond)
|
||||
}).timeout(15000)
|
||||
|
||||
it('protocol version should be upgraded on password change', async function () {
|
||||
/** Delete default items key that is created on launch */
|
||||
const itemsKey = await this.application.encryptionService.getSureDefaultItemsKey()
|
||||
const itemsKey = await this.application.encryption.getSureDefaultItemsKey()
|
||||
await this.application.mutator.setItemToBeDeleted(itemsKey)
|
||||
expect(Uuids(this.application.itemManager.getDisplayableItemsKeys()).includes(itemsKey.uuid)).to.equal(false)
|
||||
expect(Uuids(this.application.items.getDisplayableItemsKeys()).includes(itemsKey.uuid)).to.equal(false)
|
||||
|
||||
Factory.createMappedNote(this.application)
|
||||
|
||||
@@ -186,10 +186,10 @@ describe('upgrading', () => {
|
||||
version: ProtocolVersion.V003,
|
||||
})
|
||||
|
||||
expect(this.application.itemManager.getDisplayableItemsKeys().length).to.equal(1)
|
||||
expect(this.application.items.getDisplayableItemsKeys().length).to.equal(1)
|
||||
|
||||
expect((await this.application.encryptionService.getRootKeyParams()).version).to.equal(ProtocolVersion.V003)
|
||||
expect((await this.application.encryptionService.getRootKey()).keyVersion).to.equal(ProtocolVersion.V003)
|
||||
expect((await this.application.encryption.getRootKeyParams()).version).to.equal(ProtocolVersion.V003)
|
||||
expect((await this.application.encryption.getRootKey()).keyVersion).to.equal(ProtocolVersion.V003)
|
||||
|
||||
/** Ensure note is encrypted with 003 */
|
||||
const notePayloads = await Factory.getStoragePayloadsOfType(this.application, ContentType.TYPES.Note)
|
||||
@@ -199,16 +199,16 @@ describe('upgrading', () => {
|
||||
const { error } = await this.application.changePassword(this.password, 'foobarfoo')
|
||||
expect(error).to.not.exist
|
||||
|
||||
const latestVersion = this.application.encryptionService.getLatestVersion()
|
||||
expect((await this.application.encryptionService.getRootKeyParams()).version).to.equal(latestVersion)
|
||||
expect((await this.application.encryptionService.getRootKey()).keyVersion).to.equal(latestVersion)
|
||||
const latestVersion = this.application.encryption.getLatestVersion()
|
||||
expect((await this.application.encryption.getRootKeyParams()).version).to.equal(latestVersion)
|
||||
expect((await this.application.encryption.getRootKey()).keyVersion).to.equal(latestVersion)
|
||||
|
||||
const defaultItemsKey = await this.application.encryptionService.getSureDefaultItemsKey()
|
||||
const defaultItemsKey = await this.application.encryption.getSureDefaultItemsKey()
|
||||
expect(defaultItemsKey.keyVersion).to.equal(latestVersion)
|
||||
|
||||
/** After change, note should now be encrypted with latest protocol version */
|
||||
|
||||
const note = this.application.itemManager.getDisplayableNotes()[0]
|
||||
const note = this.application.items.getDisplayableNotes()[0]
|
||||
await Factory.markDirtyAndSyncItem(this.application, note)
|
||||
|
||||
const refreshedNotePayloads = await Factory.getStoragePayloadsOfType(this.application, ContentType.TYPES.Note)
|
||||
@@ -243,44 +243,44 @@ describe('upgrading', () => {
|
||||
})
|
||||
|
||||
it('rolls back the local protocol upgrade if syncing fails', async function () {
|
||||
sinon.replace(this.application.syncService, 'sync', sinon.fake())
|
||||
sinon.replace(this.application.sync, 'sync', sinon.fake())
|
||||
this.application.setLaunchCallback({
|
||||
receiveChallenge: this.receiveChallenge,
|
||||
})
|
||||
expect((await this.application.encryptionService.rootKeyManager.getRootKeyWrapperKeyParams()).version).to.equal(
|
||||
expect((await this.application.encryption.rootKeyManager.getRootKeyWrapperKeyParams()).version).to.equal(
|
||||
oldVersion,
|
||||
)
|
||||
const errors = await this.application.upgradeProtocolVersion()
|
||||
expect(errors).to.not.be.empty
|
||||
|
||||
/** Ensure we're still on 003 */
|
||||
expect((await this.application.encryptionService.rootKeyManager.getRootKeyWrapperKeyParams()).version).to.equal(
|
||||
expect((await this.application.encryption.rootKeyManager.getRootKeyWrapperKeyParams()).version).to.equal(
|
||||
oldVersion,
|
||||
)
|
||||
expect((await this.application.encryptionService.getRootKeyParams()).version).to.equal(oldVersion)
|
||||
expect((await this.application.encryptionService.getRootKey()).keyVersion).to.equal(oldVersion)
|
||||
expect((await this.application.encryptionService.getSureDefaultItemsKey()).keyVersion).to.equal(oldVersion)
|
||||
expect((await this.application.encryption.getRootKeyParams()).version).to.equal(oldVersion)
|
||||
expect((await this.application.encryption.getRootKey()).keyVersion).to.equal(oldVersion)
|
||||
expect((await this.application.encryption.getSureDefaultItemsKey()).keyVersion).to.equal(oldVersion)
|
||||
})
|
||||
|
||||
it('rolls back the local protocol upgrade if the server responds with an error', async function () {
|
||||
sinon.replace(this.application.sessionManager, 'changeCredentials', () => [Error()])
|
||||
sinon.replace(this.application.sessions, 'changeCredentials', () => [Error()])
|
||||
|
||||
this.application.setLaunchCallback({
|
||||
receiveChallenge: this.receiveChallenge,
|
||||
})
|
||||
expect((await this.application.encryptionService.rootKeyManager.getRootKeyWrapperKeyParams()).version).to.equal(
|
||||
expect((await this.application.encryption.rootKeyManager.getRootKeyWrapperKeyParams()).version).to.equal(
|
||||
oldVersion,
|
||||
)
|
||||
const errors = await this.application.upgradeProtocolVersion()
|
||||
expect(errors).to.not.be.empty
|
||||
|
||||
/** Ensure we're still on 003 */
|
||||
expect((await this.application.encryptionService.rootKeyManager.getRootKeyWrapperKeyParams()).version).to.equal(
|
||||
expect((await this.application.encryption.rootKeyManager.getRootKeyWrapperKeyParams()).version).to.equal(
|
||||
oldVersion,
|
||||
)
|
||||
expect((await this.application.encryptionService.getRootKeyParams()).version).to.equal(oldVersion)
|
||||
expect((await this.application.encryptionService.getRootKey()).keyVersion).to.equal(oldVersion)
|
||||
expect((await this.application.encryptionService.getSureDefaultItemsKey()).keyVersion).to.equal(oldVersion)
|
||||
expect((await this.application.encryption.getRootKeyParams()).version).to.equal(oldVersion)
|
||||
expect((await this.application.encryption.getRootKey()).keyVersion).to.equal(oldVersion)
|
||||
expect((await this.application.encryption.getSureDefaultItemsKey()).keyVersion).to.equal(oldVersion)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user