refactor: import/export use cases (#2397)
This commit is contained in:
@@ -20,8 +20,8 @@ import {
|
||||
ApplicationStageChangedEventPayload,
|
||||
StorageValueModes,
|
||||
ChallengeObserver,
|
||||
ImportDataReturnType,
|
||||
ImportDataUseCase,
|
||||
ImportDataResult,
|
||||
ImportData,
|
||||
StoragePersistencePolicies,
|
||||
HomeServerServiceInterface,
|
||||
DeviceInterface,
|
||||
@@ -79,6 +79,8 @@ import {
|
||||
SetHost,
|
||||
MfaServiceInterface,
|
||||
GenerateUuid,
|
||||
CreateDecryptedBackupFile,
|
||||
CreateEncryptedBackupFile,
|
||||
} from '@standardnotes/services'
|
||||
import {
|
||||
SNNote,
|
||||
@@ -133,6 +135,7 @@ import { GetAuthenticatorAuthenticationOptions } from '@Lib/Domain/UseCase/GetAu
|
||||
import { Dependencies } from './Dependencies/Dependencies'
|
||||
import { TYPES } from './Dependencies/Types'
|
||||
import { RegisterApplicationServicesEvents } from './Dependencies/DependencyEvents'
|
||||
import { Result } from '@standardnotes/domain-core'
|
||||
|
||||
/** How often to automatically sync, in milliseconds */
|
||||
const DEFAULT_AUTO_SYNC_INTERVAL = 30_000
|
||||
@@ -672,26 +675,6 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
return this.protections.authorizeAutolockIntervalChange()
|
||||
}
|
||||
|
||||
public async createEncryptedBackupFileForAutomatedDesktopBackups(): Promise<BackupFile | undefined> {
|
||||
return this.encryption.createEncryptedBackupFile()
|
||||
}
|
||||
|
||||
public async createEncryptedBackupFile(): Promise<BackupFile | undefined> {
|
||||
if (!(await this.protections.authorizeBackupCreation())) {
|
||||
return
|
||||
}
|
||||
|
||||
return this.encryption.createEncryptedBackupFile()
|
||||
}
|
||||
|
||||
public async createDecryptedBackupFile(): Promise<BackupFile | undefined> {
|
||||
if (!(await this.protections.authorizeBackupCreation())) {
|
||||
return
|
||||
}
|
||||
|
||||
return this.encryption.createDecryptedBackupFile()
|
||||
}
|
||||
|
||||
public isEphemeralSession(): boolean {
|
||||
return this.storage.isEphemeralSession()
|
||||
}
|
||||
@@ -842,8 +825,8 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
})
|
||||
}
|
||||
|
||||
public async importData(data: BackupFile, awaitSync = false): Promise<ImportDataReturnType> {
|
||||
const usecase = this.dependencies.get<ImportDataUseCase>(TYPES.ImportDataUseCase)
|
||||
public async importData(data: BackupFile, awaitSync = false): Promise<Result<ImportDataResult>> {
|
||||
const usecase = this.dependencies.get<ImportData>(TYPES.ImportData)
|
||||
return usecase.execute(data, awaitSync)
|
||||
}
|
||||
|
||||
@@ -1164,6 +1147,14 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
return this.dependencies.get<GenerateUuid>(TYPES.GenerateUuid)
|
||||
}
|
||||
|
||||
public get createDecryptedBackupFile(): CreateDecryptedBackupFile {
|
||||
return this.dependencies.get<CreateDecryptedBackupFile>(TYPES.CreateDecryptedBackupFile)
|
||||
}
|
||||
|
||||
public get createEncryptedBackupFile(): CreateEncryptedBackupFile {
|
||||
return this.dependencies.get<CreateEncryptedBackupFile>(TYPES.CreateEncryptedBackupFile)
|
||||
}
|
||||
|
||||
private get migrations(): MigrationService {
|
||||
return this.dependencies.get<MigrationService>(TYPES.MigrationService)
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ import {
|
||||
GetAllContacts,
|
||||
GetVault,
|
||||
HomeServerService,
|
||||
ImportDataUseCase,
|
||||
ImportData,
|
||||
InMemoryStore,
|
||||
IntegrityService,
|
||||
InternalEventBus,
|
||||
@@ -133,7 +133,13 @@ import {
|
||||
GenerateUuid,
|
||||
GetVaultItems,
|
||||
ValidateVaultPassword,
|
||||
DecryptBackupPayloads,
|
||||
DetermineKeyToUse,
|
||||
GetBackupFileType,
|
||||
GetFilePassword,
|
||||
IsApplicationUsingThirdPartyHost,
|
||||
CreateDecryptedBackupFile,
|
||||
CreateEncryptedBackupFile,
|
||||
} from '@standardnotes/services'
|
||||
import { ItemManager } from '../../Services/Items/ItemManager'
|
||||
import { PayloadManager } from '../../Services/Payloads/PayloadManager'
|
||||
@@ -160,7 +166,7 @@ import {
|
||||
WebSocketServer,
|
||||
} from '@standardnotes/api'
|
||||
import { TYPES } from './Types'
|
||||
import { Logger, isNotUndefined, isDeinitable } from '@standardnotes/utils'
|
||||
import { Logger, isNotUndefined, isDeinitable, LoggerInterface } from '@standardnotes/utils'
|
||||
import { EncryptionOperators } from '@standardnotes/encryption'
|
||||
import { AsymmetricMessagePayload, AsymmetricMessageSharedVaultInvite } from '@standardnotes/models'
|
||||
import { PureCryptoInterface } from '@standardnotes/sncrypto-common'
|
||||
@@ -219,6 +225,29 @@ export class Dependencies {
|
||||
}
|
||||
|
||||
private registerUseCaseMakers() {
|
||||
this.factory.set(TYPES.DecryptBackupPayloads, () => {
|
||||
return new DecryptBackupPayloads(
|
||||
this.get<EncryptionService>(TYPES.EncryptionService),
|
||||
this.get<DetermineKeyToUse>(TYPES.DetermineKeyToUse),
|
||||
this.get<LoggerInterface>(TYPES.Logger),
|
||||
)
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.DetermineKeyToUse, () => {
|
||||
return new DetermineKeyToUse(
|
||||
this.get<EncryptionService>(TYPES.EncryptionService),
|
||||
this.get<KeySystemKeyManager>(TYPES.KeySystemKeyManager),
|
||||
)
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.GetBackupFileType, () => {
|
||||
return new GetBackupFileType()
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.GetFilePassword, () => {
|
||||
return new GetFilePassword(this.get<ChallengeService>(TYPES.ChallengeService))
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.ValidateVaultPassword, () => {
|
||||
return new ValidateVaultPassword(
|
||||
this.get<EncryptionService>(TYPES.EncryptionService),
|
||||
@@ -273,16 +302,31 @@ export class Dependencies {
|
||||
)
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.ImportDataUseCase, () => {
|
||||
return new ImportDataUseCase(
|
||||
this.factory.set(TYPES.CreateDecryptedBackupFile, () => {
|
||||
return new CreateDecryptedBackupFile(
|
||||
this.get<PayloadManager>(TYPES.PayloadManager),
|
||||
this.get<ProtectionService>(TYPES.ProtectionService),
|
||||
)
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.CreateEncryptedBackupFile, () => {
|
||||
return new CreateEncryptedBackupFile(
|
||||
this.get<ItemManager>(TYPES.ItemManager),
|
||||
this.get<ProtectionService>(TYPES.ProtectionService),
|
||||
this.get<EncryptionService>(TYPES.EncryptionService),
|
||||
)
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.ImportData, () => {
|
||||
return new ImportData(
|
||||
this.get<ItemManager>(TYPES.ItemManager),
|
||||
this.get<SyncService>(TYPES.SyncService),
|
||||
this.get<ProtectionService>(TYPES.ProtectionService),
|
||||
this.get<EncryptionService>(TYPES.EncryptionService),
|
||||
this.get<PayloadManager>(TYPES.PayloadManager),
|
||||
this.get<ChallengeService>(TYPES.ChallengeService),
|
||||
this.get<HistoryManager>(TYPES.HistoryManager),
|
||||
this.get<DecryptBackupFile>(TYPES.DecryptBackupFile),
|
||||
this.get<GetFilePassword>(TYPES.GetFilePassword),
|
||||
)
|
||||
})
|
||||
|
||||
@@ -291,7 +335,12 @@ export class Dependencies {
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.DecryptBackupFile, () => {
|
||||
return new DecryptBackupFile(this.get<EncryptionService>(TYPES.EncryptionService), this.get<Logger>(TYPES.Logger))
|
||||
return new DecryptBackupFile(
|
||||
this.get<EncryptionService>(TYPES.EncryptionService),
|
||||
this.get<KeySystemKeyManager>(TYPES.KeySystemKeyManager),
|
||||
this.get<GetBackupFileType>(TYPES.GetBackupFileType),
|
||||
this.get<DecryptBackupPayloads>(TYPES.DecryptBackupPayloads),
|
||||
)
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.DiscardItemsLocally, () => {
|
||||
|
||||
@@ -89,7 +89,7 @@ export const TYPES = {
|
||||
ListRevisions: Symbol.for('ListRevisions'),
|
||||
GetRevision: Symbol.for('GetRevision'),
|
||||
DeleteRevision: Symbol.for('DeleteRevision'),
|
||||
ImportDataUseCase: Symbol.for('ImportDataUseCase'),
|
||||
ImportData: Symbol.for('ImportData'),
|
||||
DiscardItemsLocally: Symbol.for('DiscardItemsLocally'),
|
||||
FindContact: Symbol.for('FindContact'),
|
||||
GetAllContacts: Symbol.for('GetAllContacts'),
|
||||
@@ -163,7 +163,13 @@ export const TYPES = {
|
||||
GenerateUuid: Symbol.for('GenerateUuid'),
|
||||
GetVaultItems: Symbol.for('GetVaultItems'),
|
||||
ValidateVaultPassword: Symbol.for('ValidateVaultPassword'),
|
||||
DecryptBackupPayloads: Symbol.for('DecryptBackupPayloads'),
|
||||
DetermineKeyToUse: Symbol.for('DetermineKeyToUse'),
|
||||
GetBackupFileType: Symbol.for('GetBackupFileType'),
|
||||
GetFilePassword: Symbol.for('GetFilePassword'),
|
||||
AuthorizeVaultDeletion: Symbol.for('AuthorizeVaultDeletion'),
|
||||
CreateDecryptedBackupFile: Symbol.for('CreateDecryptedBackupFile'),
|
||||
CreateEncryptedBackupFile: Symbol.for('CreateEncryptedBackupFile'),
|
||||
|
||||
// Mappers
|
||||
SessionStorageMapper: Symbol.for('SessionStorageMapper'),
|
||||
|
||||
@@ -23,16 +23,16 @@ describe('backups', function () {
|
||||
})
|
||||
|
||||
it('backup file should have a version number', async function () {
|
||||
let data = await application.createDecryptedBackupFile()
|
||||
let data = (await application.createDecryptedBackupFile.execute()).getValue()
|
||||
expect(data.version).to.equal(application.encryption.getLatestVersion())
|
||||
await application.addPasscode('passcode')
|
||||
data = await application.createEncryptedBackupFileForAutomatedDesktopBackups()
|
||||
data = (await application.createEncryptedBackupFile.execute({ skipAuthorization: true })).getValue()
|
||||
expect(data.version).to.equal(application.encryption.getLatestVersion())
|
||||
})
|
||||
|
||||
it('no passcode + no account backup file should have correct number of items', async function () {
|
||||
await Promise.all([Factory.createSyncedNote(application), Factory.createSyncedNote(application)])
|
||||
const data = await application.createDecryptedBackupFile()
|
||||
const data = (await application.createDecryptedBackupFile.execute()).getValue()
|
||||
const offsetForNewItems = 2
|
||||
const offsetForNoItemsKey = -1
|
||||
expect(data.items.length).to.equal(BaseItemCounts.DefaultItems + offsetForNewItems + offsetForNoItemsKey)
|
||||
@@ -44,12 +44,12 @@ describe('backups', function () {
|
||||
await Promise.all([Factory.createSyncedNote(application), Factory.createSyncedNote(application)])
|
||||
|
||||
// Encrypted backup without authorization
|
||||
const encryptedData = await application.createEncryptedBackupFileForAutomatedDesktopBackups()
|
||||
const encryptedData = (await application.createEncryptedBackupFile.execute({ skipAuthorization: true })).getValue()
|
||||
expect(encryptedData.items.length).to.equal(BaseItemCounts.DefaultItems + 2)
|
||||
|
||||
// Encrypted backup with authorization
|
||||
Factory.handlePasswordChallenges(application, passcode)
|
||||
const authorizedEncryptedData = await application.createEncryptedBackupFile()
|
||||
const authorizedEncryptedData = (await application.createEncryptedBackupFile.execute()).getValue()
|
||||
expect(authorizedEncryptedData.items.length).to.equal(BaseItemCounts.DefaultItems + 2)
|
||||
})
|
||||
|
||||
@@ -63,17 +63,17 @@ describe('backups', function () {
|
||||
await Promise.all([Factory.createSyncedNote(application), Factory.createSyncedNote(application)])
|
||||
|
||||
// Encrypted backup without authorization
|
||||
const encryptedData = await application.createEncryptedBackupFileForAutomatedDesktopBackups()
|
||||
const encryptedData = (await application.createEncryptedBackupFile.execute({ skipAuthorization: true })).getValue()
|
||||
expect(encryptedData.items.length).to.equal(BaseItemCounts.DefaultItemsWithAccount + 2)
|
||||
|
||||
Factory.handlePasswordChallenges(application, password)
|
||||
|
||||
// Decrypted backup
|
||||
const decryptedData = await application.createDecryptedBackupFile()
|
||||
const decryptedData = (await application.createDecryptedBackupFile.execute()).getValue()
|
||||
expect(decryptedData.items.length).to.equal(BaseItemCounts.DefaultItemsWithAccountWithoutItemsKey + 2)
|
||||
|
||||
// Encrypted backup with authorization
|
||||
const authorizedEncryptedData = await application.createEncryptedBackupFile()
|
||||
const authorizedEncryptedData = (await application.createEncryptedBackupFile.execute()).getValue()
|
||||
expect(authorizedEncryptedData.items.length).to.equal(BaseItemCounts.DefaultItemsWithAccount + 2)
|
||||
})
|
||||
|
||||
@@ -85,23 +85,25 @@ describe('backups', function () {
|
||||
await Promise.all([Factory.createSyncedNote(application), Factory.createSyncedNote(application)])
|
||||
|
||||
// Encrypted backup without authorization
|
||||
const encryptedData = await application.createEncryptedBackupFileForAutomatedDesktopBackups()
|
||||
const encryptedData = (await application.createEncryptedBackupFile.execute({ skipAuthorization: true })).getValue()
|
||||
expect(encryptedData.items.length).to.equal(BaseItemCounts.DefaultItemsWithAccount + 2)
|
||||
|
||||
Factory.handlePasswordChallenges(application, passcode)
|
||||
|
||||
// Decrypted backup
|
||||
const decryptedData = await application.createDecryptedBackupFile()
|
||||
const decryptedData = (await application.createDecryptedBackupFile.execute()).getValue()
|
||||
expect(decryptedData.items.length).to.equal(BaseItemCounts.DefaultItemsWithAccountWithoutItemsKey + 2)
|
||||
|
||||
// Encrypted backup with authorization
|
||||
const authorizedEncryptedData = await application.createEncryptedBackupFileForAutomatedDesktopBackups()
|
||||
const authorizedEncryptedData = (
|
||||
await application.createEncryptedBackupFile.execute({ skipAuthorization: true })
|
||||
).getValue()
|
||||
expect(authorizedEncryptedData.items.length).to.equal(BaseItemCounts.DefaultItemsWithAccount + 2)
|
||||
}).timeout(10000)
|
||||
|
||||
it('backup file item should have correct fields', async function () {
|
||||
await Factory.createSyncedNote(application)
|
||||
let backupData = await application.createDecryptedBackupFile()
|
||||
let backupData = (await application.createDecryptedBackupFile.execute()).getValue()
|
||||
let rawItem = backupData.items.find((i) => i.content_type === ContentType.TYPES.Note)
|
||||
|
||||
expect(rawItem.fields).to.not.be.ok
|
||||
@@ -120,7 +122,7 @@ describe('backups', function () {
|
||||
password: password,
|
||||
})
|
||||
|
||||
backupData = await application.createEncryptedBackupFileForAutomatedDesktopBackups()
|
||||
backupData = (await application.createEncryptedBackupFile.execute({ skipAuthorization: true })).getValue()
|
||||
rawItem = backupData.items.find((i) => i.content_type === ContentType.TYPES.Note)
|
||||
|
||||
expect(rawItem.fields).to.not.be.ok
|
||||
@@ -155,13 +157,13 @@ describe('backups', function () {
|
||||
|
||||
expect(erroredItem.errorDecrypting).to.equal(true)
|
||||
|
||||
const backupData = await application.createDecryptedBackupFile()
|
||||
const backupData = (await application.createDecryptedBackupFile.execute()).getValue()
|
||||
|
||||
expect(backupData.items.length).to.equal(BaseItemCounts.DefaultItemsNoAccounNoItemsKey + 2)
|
||||
})
|
||||
|
||||
it('decrypted backup file should not have keyParams', async function () {
|
||||
const backup = await application.createDecryptedBackupFile()
|
||||
const backup = (await application.createDecryptedBackupFile.execute()).getValue()
|
||||
expect(backup).to.not.haveOwnProperty('keyParams')
|
||||
})
|
||||
|
||||
@@ -176,7 +178,7 @@ describe('backups', function () {
|
||||
|
||||
Factory.handlePasswordChallenges(application, password)
|
||||
|
||||
const backup = await application.createDecryptedBackupFile()
|
||||
const backup = (await application.createDecryptedBackupFile.execute()).getValue()
|
||||
|
||||
expect(backup).to.not.haveOwnProperty('keyParams')
|
||||
|
||||
@@ -185,30 +187,30 @@ describe('backups', function () {
|
||||
|
||||
it('encrypted backup file should have keyParams', async function () {
|
||||
await application.addPasscode('passcode')
|
||||
const backup = await application.createEncryptedBackupFileForAutomatedDesktopBackups()
|
||||
const backup = (await application.createEncryptedBackupFile.execute({ skipAuthorization: true })).getValue()
|
||||
expect(backup).to.haveOwnProperty('keyParams')
|
||||
})
|
||||
|
||||
it('decrypted backup file should not have itemsKeys', async function () {
|
||||
const backup = await application.createDecryptedBackupFile()
|
||||
const backup = (await application.createDecryptedBackupFile.execute()).getValue()
|
||||
expect(backup.items.some((item) => item.content_type === ContentType.TYPES.ItemsKey)).to.be.false
|
||||
})
|
||||
|
||||
it('encrypted backup file should have itemsKeys', async function () {
|
||||
await application.addPasscode('passcode')
|
||||
const backup = await application.createEncryptedBackupFileForAutomatedDesktopBackups()
|
||||
const backup = (await application.createEncryptedBackupFile.execute({ skipAuthorization: true })).getValue()
|
||||
expect(backup.items.some((item) => item.content_type === ContentType.TYPES.ItemsKey)).to.be.true
|
||||
})
|
||||
|
||||
it('backup file with no account and no passcode should be decrypted', async function () {
|
||||
const note = await Factory.createSyncedNote(application)
|
||||
const backup = await application.createDecryptedBackupFile()
|
||||
const backup = (await application.createDecryptedBackupFile.execute()).getValue()
|
||||
expect(backup).to.not.haveOwnProperty('keyParams')
|
||||
expect(backup.items.some((item) => item.content_type === ContentType.TYPES.ItemsKey)).to.be.false
|
||||
expect(backup.items.find((item) => item.content_type === ContentType.TYPES.Note).uuid).to.equal(note.uuid)
|
||||
let error
|
||||
try {
|
||||
await application.createEncryptedBackupFileForAutomatedDesktopBackups()
|
||||
;(await application.createEncryptedBackupFile.execute({ skipAuthorization: true })).getValue()
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ describe('importing', function () {
|
||||
version: '-1',
|
||||
items: [],
|
||||
})
|
||||
expect(result.error).to.exist
|
||||
expect(result.isFailed()).to.be.true
|
||||
})
|
||||
|
||||
it('should not import backups made from 004 into 003 account', async function () {
|
||||
@@ -57,7 +57,7 @@ describe('importing', function () {
|
||||
version: ProtocolVersion.V004,
|
||||
items: [],
|
||||
})
|
||||
expect(result.error).to.exist
|
||||
expect(result.isFailed()).to.be.true
|
||||
})
|
||||
|
||||
it('importing existing data should keep relationships valid', async function () {
|
||||
@@ -361,7 +361,7 @@ describe('importing', function () {
|
||||
Factory.createMappedTag(application),
|
||||
])
|
||||
|
||||
const backupData = await application.createEncryptedBackupFileForAutomatedDesktopBackups()
|
||||
const backupData = (await application.createEncryptedBackupFile.execute({ skipAuthorization: true })).getValue()
|
||||
|
||||
await application.sync.sync({ awaitAll: true })
|
||||
|
||||
@@ -394,7 +394,7 @@ describe('importing', function () {
|
||||
Factory.createMappedTag(application),
|
||||
])
|
||||
|
||||
const backupData = await application.createEncryptedBackupFileForAutomatedDesktopBackups()
|
||||
const backupData = (await application.createEncryptedBackupFile.execute({ skipAuthorization: true })).getValue()
|
||||
|
||||
await Factory.safeDeinit(application)
|
||||
application = await Factory.createInitAppWithFakeCrypto()
|
||||
@@ -421,7 +421,7 @@ describe('importing', function () {
|
||||
Factory.createMappedTag(application),
|
||||
])
|
||||
|
||||
const backupData = await application.createEncryptedBackupFileForAutomatedDesktopBackups()
|
||||
const backupData = (await application.createEncryptedBackupFile.execute({ skipAuthorization: true })).getValue()
|
||||
|
||||
await Factory.safeDeinit(application)
|
||||
application = await Factory.createInitAppWithFakeCrypto()
|
||||
@@ -449,14 +449,13 @@ describe('importing', function () {
|
||||
text: 'On protocol version 003.',
|
||||
})
|
||||
|
||||
const backupData = await application.createEncryptedBackupFileForAutomatedDesktopBackups()
|
||||
const backupData = (await application.createEncryptedBackupFile.execute({ skipAuthorization: true })).getValue()
|
||||
|
||||
await Factory.safeDeinit(application)
|
||||
application = await Factory.createInitAppWithFakeCrypto()
|
||||
Factory.handlePasswordChallenges(application, password)
|
||||
|
||||
const result = await application.importData(backupData, true)
|
||||
expect(result).to.not.be.undefined
|
||||
const result = (await application.importData(backupData, true)).getValue()
|
||||
expect(result.affectedItems.length).to.be.eq(backupData.items.length)
|
||||
expect(result.errorCount).to.be.eq(0)
|
||||
|
||||
@@ -478,14 +477,13 @@ describe('importing', function () {
|
||||
text: 'On protocol version 004.',
|
||||
})
|
||||
|
||||
const backupData = await application.createEncryptedBackupFileForAutomatedDesktopBackups()
|
||||
const backupData = (await application.createEncryptedBackupFile.execute({ skipAuthorization: true })).getValue()
|
||||
|
||||
await Factory.safeDeinit(application)
|
||||
application = await Factory.createInitAppWithFakeCrypto()
|
||||
Factory.handlePasswordChallenges(application, password)
|
||||
|
||||
const result = await application.importData(backupData, true)
|
||||
expect(result).to.not.be.undefined
|
||||
const result = (await application.importData(backupData, true)).getValue()
|
||||
expect(result.affectedItems.length).to.be.eq(backupData.items.length)
|
||||
expect(result.errorCount).to.be.eq(0)
|
||||
|
||||
@@ -507,7 +505,7 @@ describe('importing', function () {
|
||||
text: 'On protocol version 004.',
|
||||
})
|
||||
|
||||
const backupData = await application.createEncryptedBackupFileForAutomatedDesktopBackups()
|
||||
const backupData = (await application.createEncryptedBackupFile.execute({ skipAuthorization: true })).getValue()
|
||||
|
||||
await Factory.safeDeinit(application)
|
||||
application = await Factory.createInitAppWithFakeCrypto()
|
||||
@@ -523,8 +521,7 @@ describe('importing', function () {
|
||||
|
||||
backupData.items = [...backupData.items, madeUpPayload]
|
||||
|
||||
const result = await application.importData(backupData, true)
|
||||
expect(result).to.not.be.undefined
|
||||
const result = (await application.importData(backupData, true)).getValue()
|
||||
expect(result.affectedItems.length).to.be.eq(backupData.items.length - 1)
|
||||
expect(result.errorCount).to.be.eq(1)
|
||||
})
|
||||
@@ -543,7 +540,7 @@ describe('importing', function () {
|
||||
text: 'On protocol version 003.',
|
||||
})
|
||||
|
||||
const backupData = await application.createEncryptedBackupFileForAutomatedDesktopBackups()
|
||||
const backupData = (await application.createEncryptedBackupFile.execute({ skipAuthorization: true })).getValue()
|
||||
|
||||
await Factory.safeDeinit(application)
|
||||
application = await Factory.createInitAppWithFakeCrypto()
|
||||
@@ -559,8 +556,7 @@ describe('importing', function () {
|
||||
},
|
||||
})
|
||||
|
||||
const result = await application.importData(backupData, true)
|
||||
expect(result).to.not.be.undefined
|
||||
const result = (await application.importData(backupData, true)).getValue()
|
||||
|
||||
expect(result.affectedItems.length).to.be.eq(0)
|
||||
expect(result.errorCount).to.be.eq(backupData.items.length)
|
||||
@@ -579,7 +575,7 @@ describe('importing', function () {
|
||||
text: 'On protocol version 004.',
|
||||
})
|
||||
|
||||
const backupData = await application.createEncryptedBackupFileForAutomatedDesktopBackups()
|
||||
const backupData = (await application.createEncryptedBackupFile.execute({ skipAuthorization: true })).getValue()
|
||||
|
||||
await Factory.safeDeinit(application)
|
||||
application = await Factory.createInitAppWithFakeCrypto()
|
||||
@@ -590,8 +586,7 @@ describe('importing', function () {
|
||||
},
|
||||
})
|
||||
|
||||
const result = await application.importData(backupData, true)
|
||||
expect(result).to.not.be.undefined
|
||||
const result = (await application.importData(backupData, true)).getValue()
|
||||
expect(result.affectedItems.length).to.be.eq(0)
|
||||
expect(result.errorCount).to.be.eq(backupData.items.length)
|
||||
expect(application.items.getDisplayableNotes().length).to.equal(0)
|
||||
@@ -609,7 +604,7 @@ describe('importing', function () {
|
||||
text: 'On protocol version 004.',
|
||||
})
|
||||
|
||||
const backupData = await application.createEncryptedBackupFileForAutomatedDesktopBackups()
|
||||
const backupData = (await application.createEncryptedBackupFile.execute({ skipAuthorization: true })).getValue()
|
||||
delete backupData.keyParams
|
||||
|
||||
await Factory.safeDeinit(application)
|
||||
@@ -617,7 +612,7 @@ describe('importing', function () {
|
||||
|
||||
const result = await application.importData(backupData)
|
||||
|
||||
expect(result.error).to.be.ok
|
||||
expect(result.isFailed()).to.be.true
|
||||
})
|
||||
|
||||
it('should not import payloads if the corresponding ItemsKey is not present within the backup file', async function () {
|
||||
@@ -633,16 +628,14 @@ describe('importing', function () {
|
||||
text: 'On protocol version 004.',
|
||||
})
|
||||
|
||||
const backupData = await application.createEncryptedBackupFileForAutomatedDesktopBackups()
|
||||
const backupData = (await application.createEncryptedBackupFile.execute({ skipAuthorization: true })).getValue()
|
||||
backupData.items = backupData.items.filter((payload) => payload.content_type !== ContentType.TYPES.ItemsKey)
|
||||
|
||||
await Factory.safeDeinit(application)
|
||||
application = await Factory.createInitAppWithFakeCrypto()
|
||||
Factory.handlePasswordChallenges(application, password)
|
||||
|
||||
const result = await application.importData(backupData, true)
|
||||
|
||||
expect(result).to.not.be.undefined
|
||||
const result = (await application.importData(backupData, true)).getValue()
|
||||
|
||||
expect(result.affectedItems.length).to.equal(BaseItemCounts.BackupFileRootKeyEncryptedItems)
|
||||
|
||||
@@ -664,7 +657,7 @@ describe('importing', function () {
|
||||
|
||||
await application.sync.sync()
|
||||
|
||||
const backupData = await application.createEncryptedBackupFileForAutomatedDesktopBackups()
|
||||
const backupData = (await application.createEncryptedBackupFile.execute({ skipAuthorization: true })).getValue()
|
||||
|
||||
await Factory.safeDeinit(application)
|
||||
application = await Factory.createInitAppWithFakeCrypto()
|
||||
@@ -739,8 +732,7 @@ describe('importing', function () {
|
||||
|
||||
Factory.handlePasswordChallenges(application, 'password')
|
||||
|
||||
const result = await application.importData(backupData, true)
|
||||
expect(result).to.not.be.undefined
|
||||
const result = (await application.importData(backupData, true)).getValue()
|
||||
expect(result.affectedItems.length).to.be.eq(backupData.items.length)
|
||||
expect(result.errorCount).to.be.eq(0)
|
||||
})
|
||||
@@ -867,7 +859,7 @@ describe('importing', function () {
|
||||
},
|
||||
}
|
||||
|
||||
const result = await application.importData(backupFile, false)
|
||||
const result = (await application.importData(backupFile, false)).getValue()
|
||||
expect(result.errorCount).to.equal(0)
|
||||
await Factory.safeDeinit(application)
|
||||
})
|
||||
|
||||
@@ -778,7 +778,7 @@ describe('online conflict handling', function () {
|
||||
it('importing data belonging to another account should not result in duplication', async () => {
|
||||
/** Create primary account and export data */
|
||||
await createSyncedNoteWithTag(application)
|
||||
let backupFile = await application.createEncryptedBackupFileForAutomatedDesktopBackups()
|
||||
let backupFile = (await application.createEncryptedBackupFile.execute({ skipAuthorization: true })).getValue()
|
||||
/** Sort matters, and is the cause of the original issue, where tag comes before the note */
|
||||
backupFile.items = [
|
||||
backupFile.items.find((i) => i.content_type === ContentType.TYPES.ItemsKey),
|
||||
@@ -813,7 +813,7 @@ describe('online conflict handling', function () {
|
||||
await application.changeAndSaveItem.execute(tag, (mutator) => {
|
||||
mutator.e2ePendingRefactor_addItemAsRelationship(note2)
|
||||
})
|
||||
let backupFile = await application.createEncryptedBackupFileForAutomatedDesktopBackups()
|
||||
let backupFile = (await application.createEncryptedBackupFile.execute({ skipAuthorization: true })).getValue()
|
||||
backupFile.items = [
|
||||
backupFile.items.find((i) => i.content_type === ContentType.TYPES.ItemsKey),
|
||||
backupFile.items.filter((i) => i.content_type === ContentType.TYPES.Note)[0],
|
||||
|
||||
@@ -22,6 +22,7 @@ describe('asymmetric messages', function () {
|
||||
await context.deinit()
|
||||
localStorage.clear()
|
||||
sinon.restore()
|
||||
context = undefined
|
||||
})
|
||||
|
||||
it('should not trust message if the trusted payload data recipientUuid does not match the message user uuid', async () => {
|
||||
|
||||
@@ -22,6 +22,7 @@ describe('shared vault conflicts', function () {
|
||||
await context.deinit()
|
||||
localStorage.clear()
|
||||
sinon.restore()
|
||||
context = undefined
|
||||
})
|
||||
|
||||
it('after being removed from shared vault, attempting to sync previous vault item should result in SharedVaultNotMemberError. The item should be duplicated then removed.', async () => {
|
||||
|
||||
@@ -22,6 +22,7 @@ describe('contacts', function () {
|
||||
await context.deinit()
|
||||
localStorage.clear()
|
||||
sinon.restore()
|
||||
context = undefined
|
||||
})
|
||||
|
||||
it('should create contact', async () => {
|
||||
|
||||
@@ -22,6 +22,7 @@ describe('shared vault crypto', function () {
|
||||
await context.deinit()
|
||||
localStorage.clear()
|
||||
sinon.restore()
|
||||
context = undefined
|
||||
})
|
||||
|
||||
describe('root key', () => {
|
||||
|
||||
@@ -8,7 +8,6 @@ describe('shared vault deletion', function () {
|
||||
this.timeout(Factory.TwentySecondTimeout)
|
||||
|
||||
let context
|
||||
let sharedVaults
|
||||
|
||||
beforeEach(async function () {
|
||||
localStorage.clear()
|
||||
@@ -17,14 +16,13 @@ describe('shared vault deletion', function () {
|
||||
|
||||
await context.launch()
|
||||
await context.register()
|
||||
|
||||
sharedVaults = context.sharedVaults
|
||||
})
|
||||
|
||||
afterEach(async function () {
|
||||
await context.deinit()
|
||||
localStorage.clear()
|
||||
sinon.restore()
|
||||
context = undefined
|
||||
})
|
||||
|
||||
it('should remove item from all user devices when item is deleted permanently', async () => {
|
||||
@@ -72,7 +70,7 @@ describe('shared vault deletion', function () {
|
||||
const { sharedVault, note, contactContext, deinitContactContext } =
|
||||
await Collaboration.createSharedVaultWithAcceptedInviteAndNote(context)
|
||||
|
||||
await sharedVaults.deleteSharedVault(sharedVault)
|
||||
await context.sharedVaults.deleteSharedVault(sharedVault)
|
||||
await contactContext.sync()
|
||||
|
||||
const originatorNote = context.items.findItem(note.uuid)
|
||||
|
||||
@@ -9,7 +9,6 @@ describe('shared vault files', function () {
|
||||
this.timeout(Factory.TwentySecondTimeout)
|
||||
|
||||
let context
|
||||
let vaults
|
||||
|
||||
beforeEach(async function () {
|
||||
localStorage.clear()
|
||||
@@ -19,7 +18,6 @@ describe('shared vault files', function () {
|
||||
await context.launch()
|
||||
await context.register()
|
||||
|
||||
vaults = context.vaults
|
||||
await context.activatePaidSubscriptionForUser()
|
||||
})
|
||||
|
||||
@@ -27,6 +25,7 @@ describe('shared vault files', function () {
|
||||
await context.deinit()
|
||||
localStorage.clear()
|
||||
sinon.restore()
|
||||
context = undefined
|
||||
})
|
||||
|
||||
describe('private vaults', () => {
|
||||
@@ -68,7 +67,7 @@ describe('shared vault files', function () {
|
||||
const uploadedFile = await Files.uploadFile(context.files, buffer, 'my-file', 'md', 1000)
|
||||
|
||||
const sharedVault = await Collaboration.createSharedVault(context)
|
||||
const addedFile = await vaults.moveItemToVault(sharedVault, uploadedFile)
|
||||
const addedFile = await context.vaults.moveItemToVault(sharedVault, uploadedFile)
|
||||
|
||||
const downloadedBytes = await Files.downloadFile(context.files, addedFile)
|
||||
expect(downloadedBytes).to.eql(buffer)
|
||||
@@ -82,7 +81,7 @@ describe('shared vault files', function () {
|
||||
const uploadedFile = await Files.uploadFile(context.files, buffer, 'my-file', 'md', 1000, firstVault)
|
||||
|
||||
const secondVault = await Collaboration.createSharedVault(context)
|
||||
const movedFile = await vaults.moveItemToVault(secondVault, uploadedFile)
|
||||
const movedFile = await context.vaults.moveItemToVault(secondVault, uploadedFile)
|
||||
|
||||
const downloadedBytes = await Files.downloadFile(context.files, movedFile)
|
||||
expect(downloadedBytes).to.eql(buffer)
|
||||
@@ -96,7 +95,7 @@ describe('shared vault files', function () {
|
||||
const uploadedFile = await Files.uploadFile(context.files, buffer, 'my-file', 'md', 1000, firstVault)
|
||||
const privateVault = await Collaboration.createPrivateVault(context)
|
||||
|
||||
const addedFile = await vaults.moveItemToVault(privateVault, uploadedFile)
|
||||
const addedFile = await context.vaults.moveItemToVault(privateVault, uploadedFile)
|
||||
|
||||
const downloadedBytes = await Files.downloadFile(context.files, addedFile)
|
||||
expect(downloadedBytes).to.eql(buffer)
|
||||
@@ -112,14 +111,14 @@ describe('shared vault files', function () {
|
||||
|
||||
const sharedVault = await Collaboration.createSharedVault(context)
|
||||
|
||||
vaults.alerts.confirmV2 = () => Promise.resolve(true)
|
||||
context.vaults.alerts.confirmV2 = () => Promise.resolve(true)
|
||||
|
||||
await vaults.moveItemToVault(sharedVault, note)
|
||||
await context.vaults.moveItemToVault(sharedVault, note)
|
||||
|
||||
const latestFile = context.items.findItem(updatedFile.uuid)
|
||||
|
||||
expect(vaults.getItemVault(latestFile).uuid).to.equal(sharedVault.uuid)
|
||||
expect(vaults.getItemVault(context.items.findItem(note.uuid)).uuid).to.equal(sharedVault.uuid)
|
||||
expect(context.vaults.getItemVault(latestFile).uuid).to.equal(sharedVault.uuid)
|
||||
expect(context.vaults.getItemVault(context.items.findItem(note.uuid)).uuid).to.equal(sharedVault.uuid)
|
||||
|
||||
const downloadedBytes = await Files.downloadFile(context.files, latestFile)
|
||||
expect(downloadedBytes).to.eql(buffer)
|
||||
@@ -132,7 +131,7 @@ describe('shared vault files', function () {
|
||||
const sharedVault = await Collaboration.createSharedVault(context)
|
||||
const uploadedFile = await Files.uploadFile(context.files, buffer, 'my-file', 'md', 1000, sharedVault)
|
||||
|
||||
const removedFile = await vaults.removeItemFromVault(uploadedFile)
|
||||
const removedFile = await context.vaults.removeItemFromVault(uploadedFile)
|
||||
expect(removedFile.key_system_identifier).to.not.be.ok
|
||||
|
||||
const downloadedBytes = await Files.downloadFile(context.files, removedFile)
|
||||
@@ -226,7 +225,7 @@ describe('shared vault files', function () {
|
||||
const response = await fetch('/mocha/assets/small_file.md')
|
||||
const buffer = new Uint8Array(await response.arrayBuffer())
|
||||
const uploadedFile = await Files.uploadFile(context.files, buffer, 'my-file', 'md', 1000)
|
||||
const addedFile = await vaults.moveItemToVault(sharedVault, uploadedFile)
|
||||
const addedFile = await context.vaults.moveItemToVault(sharedVault, uploadedFile)
|
||||
|
||||
await contactContext.sync()
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import * as Collaboration from '../lib/Collaboration.js'
|
||||
chai.use(chaiAsPromised)
|
||||
const expect = chai.expect
|
||||
|
||||
describe.skip('vault importing', function () {
|
||||
describe('vault importing', function () {
|
||||
this.timeout(Factory.TwentySecondTimeout)
|
||||
|
||||
let context
|
||||
@@ -15,45 +15,181 @@ describe.skip('vault importing', function () {
|
||||
context = await Factory.createVaultsContextWithRealCrypto()
|
||||
|
||||
await context.launch()
|
||||
await context.register()
|
||||
})
|
||||
|
||||
afterEach(async function () {
|
||||
await context.deinit()
|
||||
localStorage.clear()
|
||||
sinon.restore()
|
||||
context = undefined
|
||||
})
|
||||
|
||||
it('should import vaulted items with synced root key', async () => {
|
||||
console.error('TODO: implement')
|
||||
describe('exports', () => {
|
||||
describe('no account and no passcode', () => {
|
||||
it('should throw if attempting to create encrypted backup', async () => {
|
||||
const vault = await context.vaults.createUserInputtedPasswordVault({
|
||||
name: 'test vault',
|
||||
userInputtedPassword: 'test password',
|
||||
storagePreference: KeySystemRootKeyStorageMode.Ephemeral,
|
||||
})
|
||||
|
||||
const note = await context.createSyncedNote('foo', 'bar')
|
||||
await Collaboration.moveItemToVault(context, vault, note)
|
||||
|
||||
await context.application.vaultLocks.lockNonPersistentVault(vault)
|
||||
|
||||
await Factory.expectThrowsAsync(
|
||||
() => context.application.createEncryptedBackupFile.execute(),
|
||||
'Attempting root key encryption with no root key',
|
||||
)
|
||||
})
|
||||
|
||||
it('decrypted backups should export unlocked password vaulted items as decrypted and locked as encrypted', async () => {
|
||||
const lockedVault = await context.vaults.createUserInputtedPasswordVault({
|
||||
name: 'test vault',
|
||||
userInputtedPassword: 'test password',
|
||||
storagePreference: KeySystemRootKeyStorageMode.Ephemeral,
|
||||
})
|
||||
const lockedVaultNote = await context.createSyncedNote('foo', 'bar')
|
||||
await Collaboration.moveItemToVault(context, lockedVault, lockedVaultNote)
|
||||
await context.application.vaultLocks.lockNonPersistentVault(lockedVault)
|
||||
|
||||
const unlockedVault = await context.vaults.createUserInputtedPasswordVault({
|
||||
name: 'test vault',
|
||||
userInputtedPassword: 'test password',
|
||||
storagePreference: KeySystemRootKeyStorageMode.Ephemeral,
|
||||
})
|
||||
const unlockedVaultNote = await context.createSyncedNote('har', 'zar')
|
||||
await Collaboration.moveItemToVault(context, unlockedVault, unlockedVaultNote)
|
||||
|
||||
const backupData = (await context.application.createDecryptedBackupFile.execute()).getValue()
|
||||
|
||||
const backupLockedVaultNote = backupData.items.find((item) => item.uuid === lockedVaultNote.uuid)
|
||||
expect(isEncryptedPayload(backupLockedVaultNote)).to.be.true
|
||||
|
||||
const backupUnlockedVaultNote = backupData.items.find((item) => item.uuid === unlockedVaultNote.uuid)
|
||||
expect(isEncryptedPayload(backupUnlockedVaultNote)).to.be.false
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('should import vaulted items with non-present root key', async () => {
|
||||
const vault = await context.vaults.createUserInputtedPasswordVault({
|
||||
name: 'test vault',
|
||||
userInputtedPassword: 'test password',
|
||||
storagePreference: KeySystemRootKeyStorageMode.Ephemeral,
|
||||
describe('imports', () => {
|
||||
describe('password vaults', () => {
|
||||
it('should import password vaulted items with non-present root key as-is without decrypting', async () => {
|
||||
await context.register()
|
||||
|
||||
const vault = await context.vaults.createUserInputtedPasswordVault({
|
||||
name: 'test vault',
|
||||
userInputtedPassword: 'test password',
|
||||
storagePreference: KeySystemRootKeyStorageMode.Ephemeral,
|
||||
})
|
||||
|
||||
const note = await context.createSyncedNote('foo', 'bar')
|
||||
await Collaboration.moveItemToVault(context, vault, note)
|
||||
|
||||
const backupData = (
|
||||
await context.application.createEncryptedBackupFile.execute({ skipAuthorization: true })
|
||||
).getValue()
|
||||
|
||||
const otherContext = await Factory.createVaultsContextWithRealCrypto()
|
||||
otherContext.password = context.password
|
||||
await otherContext.launch()
|
||||
|
||||
await otherContext.application.importData(backupData)
|
||||
|
||||
const expectedImportedItems = ['vault-items-key', 'note']
|
||||
const invalidItems = otherContext.items.invalidItems
|
||||
expect(invalidItems.length).to.equal(expectedImportedItems.length)
|
||||
|
||||
const encryptedItemsKey = invalidItems.find((item) => item.content_type === ContentType.TYPES.KeySystemItemsKey)
|
||||
expect(encryptedItemsKey.key_system_identifier).to.equal(vault.systemIdentifier)
|
||||
expect(encryptedItemsKey.errorDecrypting).to.be.true
|
||||
|
||||
const encryptedNote = invalidItems.find((item) => item.content_type === ContentType.TYPES.Note)
|
||||
expect(encryptedNote.key_system_identifier).to.equal(vault.systemIdentifier)
|
||||
expect(encryptedNote.errorDecrypting).to.be.true
|
||||
expect(encryptedNote.uuid).to.equal(note.uuid)
|
||||
|
||||
await otherContext.deinit()
|
||||
})
|
||||
})
|
||||
|
||||
const note = await context.createSyncedNote('foo', 'bar')
|
||||
await Collaboration.moveItemToVault(context, vault, note)
|
||||
describe('randomized vaults', () => {
|
||||
it('should import backup file for randomized vault created without account or passcode', async () => {
|
||||
const vault = await context.vaults.createRandomizedVault({
|
||||
name: 'test vault',
|
||||
})
|
||||
|
||||
const backupData = await context.application.createEncryptedBackupFileForAutomatedDesktopBackups()
|
||||
const note = await context.createSyncedNote('foo', 'bar')
|
||||
await Collaboration.moveItemToVault(context, vault, note)
|
||||
|
||||
const otherContext = await Factory.createVaultsContextWithRealCrypto()
|
||||
await otherContext.launch()
|
||||
const backupData = (await context.application.createDecryptedBackupFile.execute()).getValue()
|
||||
|
||||
await otherContext.application.importData(backupData)
|
||||
const otherContext = await Factory.createVaultsContextWithRealCrypto()
|
||||
otherContext.password = context.password
|
||||
await otherContext.launch()
|
||||
|
||||
const expectedImportedItems = ['vault-items-key', 'note']
|
||||
const invalidItems = otherContext.items.invalidItems
|
||||
expect(invalidItems.length).to.equal(expectedImportedItems.length)
|
||||
const result = (await otherContext.application.importData(backupData)).getValue()
|
||||
|
||||
const encryptedItem = invalidItems[0]
|
||||
expect(encryptedItem.key_system_identifier).to.equal(vault.systemIdentifier)
|
||||
expect(encryptedItem.errorDecrypting).to.be.true
|
||||
expect(encryptedItem.uuid).to.equal(note.uuid)
|
||||
const invalidItems = otherContext.items.invalidItems
|
||||
expect(invalidItems.length).to.equal(0)
|
||||
|
||||
await otherContext.deinit()
|
||||
expect(result.affectedItems.length).to.equal(backupData.items.length)
|
||||
|
||||
const itemsKey = result.affectedItems.find((item) => item.content_type === ContentType.TYPES.KeySystemItemsKey)
|
||||
expect(itemsKey.key_system_identifier).to.equal(vault.systemIdentifier)
|
||||
|
||||
const importedNote = result.affectedItems.find((item) => item.content_type === ContentType.TYPES.Note)
|
||||
expect(importedNote.key_system_identifier).to.equal(vault.systemIdentifier)
|
||||
expect(importedNote.uuid).to.equal(note.uuid)
|
||||
|
||||
const importedRootKey = result.affectedItems.find(
|
||||
(item) => item.content_type === ContentType.TYPES.KeySystemRootKey,
|
||||
)
|
||||
expect(importedRootKey.systemIdentifier).to.equal(vault.systemIdentifier)
|
||||
|
||||
await otherContext.deinit()
|
||||
})
|
||||
|
||||
it('should import synced-key vaulted items by decrypting', async () => {
|
||||
await context.register()
|
||||
|
||||
const vault = await context.vaults.createRandomizedVault({
|
||||
name: 'test vault',
|
||||
})
|
||||
|
||||
const note = await context.createSyncedNote('foo', 'bar')
|
||||
await Collaboration.moveItemToVault(context, vault, note)
|
||||
|
||||
const backupData = (
|
||||
await context.application.createEncryptedBackupFile.execute({ skipAuthorization: true })
|
||||
).getValue()
|
||||
|
||||
const otherContext = await Factory.createVaultsContextWithRealCrypto()
|
||||
otherContext.password = context.password
|
||||
await otherContext.launch()
|
||||
|
||||
const result = (await otherContext.application.importData(backupData)).getValue()
|
||||
|
||||
const invalidItems = otherContext.items.invalidItems
|
||||
expect(invalidItems.length).to.equal(0)
|
||||
|
||||
expect(result.affectedItems.length).to.equal(backupData.items.length)
|
||||
|
||||
const itemsKey = result.affectedItems.find((item) => item.content_type === ContentType.TYPES.KeySystemItemsKey)
|
||||
expect(itemsKey.key_system_identifier).to.equal(vault.systemIdentifier)
|
||||
|
||||
const importedNote = result.affectedItems.find((item) => item.content_type === ContentType.TYPES.Note)
|
||||
expect(importedNote.key_system_identifier).to.equal(vault.systemIdentifier)
|
||||
expect(importedNote.uuid).to.equal(note.uuid)
|
||||
|
||||
const importedRootKey = result.affectedItems.find(
|
||||
(item) => item.content_type === ContentType.TYPES.KeySystemRootKey,
|
||||
)
|
||||
expect(importedRootKey.systemIdentifier).to.equal(vault.systemIdentifier)
|
||||
|
||||
await otherContext.deinit()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -21,6 +21,7 @@ describe('shared vault invites', function () {
|
||||
await context.deinit()
|
||||
localStorage.clear()
|
||||
sinon.restore()
|
||||
context = undefined
|
||||
})
|
||||
|
||||
it('should invite contact to vault', async () => {
|
||||
|
||||
@@ -22,6 +22,7 @@ describe('shared vault items', function () {
|
||||
await context.deinit()
|
||||
localStorage.clear()
|
||||
sinon.restore()
|
||||
context = undefined
|
||||
})
|
||||
|
||||
it('should add item to shared vault with no other members', async () => {
|
||||
|
||||
@@ -21,6 +21,7 @@ describe('vault key management', function () {
|
||||
await context.deinit()
|
||||
localStorage.clear()
|
||||
sinon.restore()
|
||||
context = undefined
|
||||
})
|
||||
|
||||
describe('locking', () => {
|
||||
|
||||
@@ -22,6 +22,7 @@ describe('vault key rotation', function () {
|
||||
await context.deinit()
|
||||
localStorage.clear()
|
||||
sinon.restore()
|
||||
context = undefined
|
||||
})
|
||||
|
||||
it('should reencrypt all items keys belonging to key system', async () => {
|
||||
|
||||
@@ -22,6 +22,7 @@ describe('vault key sharing', function () {
|
||||
await context.deinit()
|
||||
localStorage.clear()
|
||||
sinon.restore()
|
||||
context = undefined
|
||||
})
|
||||
|
||||
it('sharing a vault with user inputted and ephemeral password should share the key as synced for the recipient', async () => {
|
||||
|
||||
@@ -22,6 +22,7 @@ describe('keypair change', function () {
|
||||
await context.deinit()
|
||||
localStorage.clear()
|
||||
sinon.restore()
|
||||
context = undefined
|
||||
})
|
||||
|
||||
it('contacts should be able to handle receiving multiple keypair changed messages and trust them in order', async () => {
|
||||
|
||||
@@ -22,6 +22,7 @@ describe('shared vault limits', function () {
|
||||
await context.deinit()
|
||||
localStorage.clear()
|
||||
sinon.restore()
|
||||
context = undefined
|
||||
})
|
||||
|
||||
describe('free users', () => {
|
||||
|
||||
@@ -22,6 +22,7 @@ describe('shared vault permissions', function () {
|
||||
await context.deinit()
|
||||
localStorage.clear()
|
||||
sinon.restore()
|
||||
context = undefined
|
||||
})
|
||||
|
||||
it('non-admin user should not be able to invite user', async () => {
|
||||
|
||||
@@ -20,9 +20,7 @@ describe('public key cryptography', function () {
|
||||
afterEach(async () => {
|
||||
await context.deinit()
|
||||
localStorage.clear()
|
||||
|
||||
sinon.restore()
|
||||
|
||||
context = undefined
|
||||
})
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ describe('shared vaults', function () {
|
||||
this.timeout(Factory.TwentySecondTimeout)
|
||||
|
||||
let context
|
||||
let vaults
|
||||
|
||||
beforeEach(async function () {
|
||||
localStorage.clear()
|
||||
@@ -17,8 +16,6 @@ describe('shared vaults', function () {
|
||||
|
||||
await context.launch()
|
||||
await context.register()
|
||||
|
||||
vaults = context.vaults
|
||||
})
|
||||
|
||||
afterEach(async function () {
|
||||
@@ -39,7 +36,7 @@ describe('shared vaults', function () {
|
||||
description: 'new vault description',
|
||||
})
|
||||
|
||||
const updatedVault = vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
|
||||
const updatedVault = context.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
|
||||
expect(updatedVault.name).to.equal('new vault name')
|
||||
expect(updatedVault.description).to.equal('new vault description')
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ describe('vaults', function () {
|
||||
this.timeout(Factory.TwentySecondTimeout)
|
||||
|
||||
let context
|
||||
let vaults
|
||||
|
||||
beforeEach(async function () {
|
||||
localStorage.clear()
|
||||
@@ -15,8 +14,6 @@ describe('vaults', function () {
|
||||
context = await Factory.createVaultsContextWithFakeCrypto()
|
||||
|
||||
await context.launch()
|
||||
|
||||
vaults = context.vaults
|
||||
})
|
||||
|
||||
afterEach(async function () {
|
||||
@@ -24,12 +21,11 @@ describe('vaults', function () {
|
||||
localStorage.clear()
|
||||
sinon.restore()
|
||||
context = undefined
|
||||
vaults = undefined
|
||||
})
|
||||
|
||||
describe('offline', function () {
|
||||
it('should be able to create an offline vault', async () => {
|
||||
const vault = await vaults.createRandomizedVault({
|
||||
const vault = await context.vaults.createRandomizedVault({
|
||||
name: 'My Vault',
|
||||
})
|
||||
|
||||
@@ -45,7 +41,7 @@ describe('vaults', function () {
|
||||
|
||||
it('should be able to create an offline vault with app passcode', async () => {
|
||||
await context.application.addPasscode('123')
|
||||
const vault = await vaults.createRandomizedVault({
|
||||
const vault = await context.vaults.createRandomizedVault({
|
||||
name: 'My Vault',
|
||||
})
|
||||
|
||||
@@ -60,12 +56,12 @@ describe('vaults', function () {
|
||||
})
|
||||
|
||||
it('should add item to offline vault', async () => {
|
||||
const vault = await vaults.createRandomizedVault({
|
||||
const vault = await context.vaults.createRandomizedVault({
|
||||
name: 'My Vault',
|
||||
})
|
||||
const item = await context.createSyncedNote()
|
||||
|
||||
await vaults.moveItemToVault(vault, item)
|
||||
await context.vaults.moveItemToVault(vault, item)
|
||||
|
||||
const updatedItem = context.items.findItem(item.uuid)
|
||||
expect(updatedItem.key_system_identifier).to.equal(vault.systemIdentifier)
|
||||
@@ -73,11 +69,11 @@ describe('vaults', function () {
|
||||
|
||||
it('should load data in the correct order at startup to allow vault items and their keys to decrypt', async () => {
|
||||
const appIdentifier = context.identifier
|
||||
const vault = await vaults.createRandomizedVault({
|
||||
const vault = await context.vaults.createRandomizedVault({
|
||||
name: 'My Vault',
|
||||
})
|
||||
const note = await context.createSyncedNote('foo', 'bar')
|
||||
await vaults.moveItemToVault(vault, note)
|
||||
await context.vaults.moveItemToVault(vault, note)
|
||||
await context.deinit()
|
||||
|
||||
const recreatedContext = await Factory.createVaultsContextWithFakeCrypto(appIdentifier)
|
||||
@@ -93,11 +89,11 @@ describe('vaults', function () {
|
||||
describe('porting from offline to online', () => {
|
||||
it('should maintain vault system identifiers across items after registration', async () => {
|
||||
const appIdentifier = context.identifier
|
||||
const vault = await vaults.createRandomizedVault({
|
||||
const vault = await context.vaults.createRandomizedVault({
|
||||
name: 'My Vault',
|
||||
})
|
||||
const note = await context.createSyncedNote('foo', 'bar')
|
||||
await vaults.moveItemToVault(vault, note)
|
||||
await context.vaults.moveItemToVault(vault, note)
|
||||
|
||||
await context.register()
|
||||
await context.sync()
|
||||
@@ -120,11 +116,11 @@ describe('vaults', function () {
|
||||
|
||||
it('should decrypt vault items', async () => {
|
||||
const appIdentifier = context.identifier
|
||||
const vault = await vaults.createRandomizedVault({
|
||||
const vault = await context.vaults.createRandomizedVault({
|
||||
name: 'My Vault',
|
||||
})
|
||||
const note = await context.createSyncedNote('foo', 'bar')
|
||||
await vaults.moveItemToVault(vault, note)
|
||||
await context.vaults.moveItemToVault(vault, note)
|
||||
|
||||
await context.register()
|
||||
await context.sync()
|
||||
@@ -149,7 +145,7 @@ describe('vaults', function () {
|
||||
})
|
||||
|
||||
it('should create a vault', async () => {
|
||||
const vault = await vaults.createRandomizedVault({
|
||||
const vault = await context.vaults.createRandomizedVault({
|
||||
name: 'My Vault',
|
||||
})
|
||||
expect(vault).to.not.be.undefined
|
||||
@@ -164,11 +160,11 @@ describe('vaults', function () {
|
||||
|
||||
it('should add item to vault', async () => {
|
||||
const note = await context.createSyncedNote('foo', 'bar')
|
||||
const vault = await vaults.createRandomizedVault({
|
||||
const vault = await context.vaults.createRandomizedVault({
|
||||
name: 'My Vault',
|
||||
})
|
||||
|
||||
await vaults.moveItemToVault(vault, note)
|
||||
await context.vaults.moveItemToVault(vault, note)
|
||||
|
||||
const updatedNote = context.items.findItem(note.uuid)
|
||||
expect(updatedNote.key_system_identifier).to.equal(vault.systemIdentifier)
|
||||
@@ -177,11 +173,11 @@ describe('vaults', function () {
|
||||
describe('client timing', () => {
|
||||
it('should load data in the correct order at startup to allow vault items and their keys to decrypt', async () => {
|
||||
const appIdentifier = context.identifier
|
||||
const vault = await vaults.createRandomizedVault({
|
||||
const vault = await context.vaults.createRandomizedVault({
|
||||
name: 'My Vault',
|
||||
})
|
||||
const note = await context.createSyncedNote('foo', 'bar')
|
||||
await vaults.moveItemToVault(vault, note)
|
||||
await context.vaults.moveItemToVault(vault, note)
|
||||
await context.deinit()
|
||||
|
||||
const recreatedContext = await Factory.createVaultsContextWithFakeCrypto(appIdentifier)
|
||||
@@ -197,13 +193,13 @@ describe('vaults', function () {
|
||||
|
||||
describe('key system root key rotation', () => {
|
||||
it('rotating a key system root key should create a new vault items key', async () => {
|
||||
const vault = await vaults.createRandomizedVault({
|
||||
const vault = await context.vaults.createRandomizedVault({
|
||||
name: 'My Vault',
|
||||
})
|
||||
|
||||
const keySystemItemsKey = context.keys.getKeySystemItemsKeys(vault.systemIdentifier)[0]
|
||||
|
||||
await vaults.rotateVaultRootKey(vault)
|
||||
await context.vaults.rotateVaultRootKey(vault)
|
||||
|
||||
const updatedKeySystemItemsKey = context.keys.getKeySystemItemsKeys(vault.systemIdentifier)[0]
|
||||
|
||||
@@ -212,13 +208,13 @@ describe('vaults', function () {
|
||||
})
|
||||
|
||||
it('deleting a vault should delete all its items', async () => {
|
||||
const vault = await vaults.createRandomizedVault({
|
||||
const vault = await context.vaults.createRandomizedVault({
|
||||
name: 'My Vault',
|
||||
})
|
||||
const note = await context.createSyncedNote('foo', 'bar')
|
||||
await vaults.moveItemToVault(vault, note)
|
||||
await context.vaults.moveItemToVault(vault, note)
|
||||
|
||||
await vaults.deleteVault(vault)
|
||||
await context.vaults.deleteVault(vault)
|
||||
|
||||
const updatedNote = context.items.findItem(note.uuid)
|
||||
expect(updatedNote).to.be.undefined
|
||||
|
||||
Reference in New Issue
Block a user