chore: fix getting vault method (#2547)

* chore: fix getting vault method

* remove only attribute

* fix checking for vaults

* fix expected missing vaults
This commit is contained in:
Karol Sójko
2023-09-28 14:18:48 +02:00
committed by GitHub
parent 397d33285c
commit 4b1140d8f0
13 changed files with 60 additions and 60 deletions

View File

@@ -85,22 +85,8 @@ export class VaultService
return this._getVaults.execute().getValue()
}
public getVault(dto: { keySystemIdentifier: KeySystemIdentifier }): VaultListingInterface | undefined {
const result = this._getVault.execute(dto)
if (result.isFailed()) {
return undefined
}
return result.getValue()
}
public getSureVault(dto: { keySystemIdentifier: KeySystemIdentifier }): VaultListingInterface {
const vault = this.getVault(dto)
if (!vault) {
throw new Error('Vault not found')
}
return vault
getVault(dto: { keySystemIdentifier: KeySystemIdentifier }): Result<VaultListingInterface> {
return this._getVault.execute(dto)
}
async createRandomizedVault(dto: {
@@ -293,7 +279,12 @@ export class VaultService
return undefined
}
return this.getVault({ keySystemIdentifier: latestItem.key_system_identifier })
const vault = this.getVault({ keySystemIdentifier: latestItem.key_system_identifier })
if (vault.isFailed()) {
throw new Error('Cannot find vault for item')
}
return vault.getValue()
}
async changeVaultKeyOptions(dto: ChangeVaultKeyOptionsDTO): Promise<Result<void>> {

View File

@@ -28,7 +28,7 @@ export interface VaultServiceInterface
}): Promise<VaultListingInterface>
getVaults(): VaultListingInterface[]
getVault(dto: { keySystemIdentifier: KeySystemIdentifier }): VaultListingInterface | undefined
getVault(dto: { keySystemIdentifier: KeySystemIdentifier }): Result<VaultListingInterface>
authorizeVaultDeletion(vault: VaultListingInterface): Promise<Result<boolean>>
deleteVault(vault: VaultListingInterface): Promise<boolean>

View File

@@ -79,7 +79,11 @@ export const createSharedVaultWithAcceptedInvite = async (
await Utils.awaitPromiseOrThrow(promise, 2.0, 'Waiting for vault to sync')
const contactVault = contactContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
const contactVaultOrError = contactContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
if (contactVaultOrError.isFailed()) {
throw new Error(contactVaultOrError.getError())
}
const contactVault = contactVaultOrError.getValue()
return { sharedVault, contact, contactVault, contactContext, deinitContactContext }
}

View File

@@ -112,7 +112,11 @@ export class VaultsContext extends AppContext {
await Collaboration.acceptAllInvites(thirdPartyContext)
const contactVault = thirdPartyContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
const contactVaultOrError = thirdPartyContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
if (contactVaultOrError.isFailed()) {
throw new Error(contactVaultOrError.getError())
}
const contactVault = contactVaultOrError.getValue()
return { contactVault, sharedVault, thirdPartyContext, deinitThirdPartyContext }
}

View File

@@ -43,7 +43,7 @@ describe('asymmetric messages', function () {
contactContext.unlockSyncing()
await contactContext.syncAndAwaitMessageProcessing()
const updatedVault = contactContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
const updatedVault = contactContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier }).getValue()
expect(updatedVault.name).to.not.equal('new vault name')
expect(updatedVault.description).to.not.equal('new vault description')
@@ -225,7 +225,7 @@ describe('asymmetric messages', function () {
expect(firstPartySpy.callCount).to.equal(0)
expect(secondPartySpy.callCount).to.equal(1)
const updatedVault = contactContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
const updatedVault = contactContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier }).getValue()
expect(updatedVault.name).to.equal('New Name')
expect(updatedVault.description).to.equal('New Description')
@@ -268,7 +268,7 @@ describe('asymmetric messages', function () {
await contactContext.syncAndAwaitMessageProcessing()
const updatedVault = contactContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
const updatedVault = contactContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier }).getValue()
expect(updatedVault.name).to.equal('New Name')
expect(updatedVault.description).to.equal('New Description')
@@ -389,7 +389,7 @@ describe('asymmetric messages', function () {
const messages = await contactContext.asymmetric.getInboundMessages()
expect(messages.getValue().length).to.equal(0)
const updatedVault = contactContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
const updatedVault = contactContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier }).getValue()
expect(updatedVault.name).to.not.equal('New Name')
expect(updatedVault.description).to.not.equal('New Description')

View File

@@ -110,14 +110,14 @@ describe('shared vault deletion', function () {
const originalNote = contactContext.items.findItem(note.uuid)
expect(originalNote).to.not.be.undefined
const contactVault = contactContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
const contactVault = contactContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier }).getValue()
await contactContext.vaultUsers.leaveSharedVault(contactVault)
const updatedContactNote = contactContext.items.findItem(note.uuid)
expect(updatedContactNote).to.be.undefined
const vault = await contactContext.vaults.getVault({ keySystemIdentifier: contactVault.systemIdentifier })
expect(vault).to.be.undefined
const vaultOrError = await contactContext.vaults.getVault({ keySystemIdentifier: contactVault.systemIdentifier })
expect(vaultOrError.isFailed()).to.be.true
await deinitContactContext()
})
@@ -163,8 +163,8 @@ describe('shared vault deletion', function () {
await contactContext.sync()
const vault = contactContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
expect(vault).to.be.undefined
const vaultOrError = contactContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
expect(vaultOrError.isFailed()).to.be.true
await deinitContactContext()
})

View File

@@ -474,7 +474,7 @@ describe('vault key management', function () {
const storedKey = context.keys.getRootKeyFromStorageForVault(vault.systemIdentifier)
expect(storedKey).to.be.undefined
const updatedVault = context.vaults.getVault({ keySystemIdentifier: vault.systemIdentifier })
const updatedVault = context.vaults.getVault({ keySystemIdentifier: vault.systemIdentifier }).getValue()
expect(updatedVault.keyStorageMode).to.equal(KeySystemRootKeyStorageMode.Synced)
})

View File

@@ -127,7 +127,7 @@ describe('vault key rotation', function () {
contactContext.unlockSyncing()
await contactContext.sync()
const vault = await contactContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
const vault = await contactContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier }).getValue()
expect(vault.rootKeyParams).to.eql(rootKey.keyParams)
await deinitContactContext()

View File

@@ -101,7 +101,7 @@ describe('keypair change', function () {
contactContext.unlockSyncing()
await contactContext.syncAndAwaitMessageProcessing()
const updatedVault = contactContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
const updatedVault = contactContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier }).getValue()
expect(updatedVault.name).to.equal(sharedVault.name)
expect(updatedVault.description).to.equal(sharedVault.description)
expect(updatedVault.name).to.not.equal('New Name')

View File

@@ -37,7 +37,7 @@ describe('shared vault quota', function () {
await context.syncAndAwaitNotificationsProcessing()
const updatedVault = context.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
const updatedVault = context.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier }).getValue()
expect(updatedVault.sharing.fileBytesUsed).to.equal(1374)
const bytesUsedSetting = await context.application.settings.getSubscriptionSetting(
@@ -80,7 +80,7 @@ describe('shared vault quota', function () {
await context.syncAndAwaitNotificationsProcessing()
const updatedVault = context.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
const updatedVault = context.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier }).getValue()
expect(updatedVault.sharing.fileBytesUsed).to.equal(1374)
const bytesUsedSetting = await context.application.settings.getSubscriptionSetting(
@@ -106,7 +106,7 @@ describe('shared vault quota', function () {
await context.syncAndAwaitNotificationsProcessing()
await contactContext.syncAndAwaitNotificationsProcessing()
const updatedVault = context.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
const updatedVault = context.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier }).getValue()
expect(updatedVault.sharing.fileBytesUsed).to.equal(1374)
const myBytesUsedSetting = await context.application.settings.getSubscriptionSetting(
@@ -170,10 +170,10 @@ describe('shared vault quota', function () {
await context.syncAndAwaitNotificationsProcessing()
await contactContext.syncAndAwaitNotificationsProcessing()
let updatedSharedVault = context.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
let updatedSharedVault = context.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier }).getValue()
expect(updatedSharedVault.sharing.fileBytesUsed).to.equal(0)
let updatedSecondVault = contactContext.vaults.getVault({ keySystemIdentifier: secondVault.systemIdentifier })
let updatedSecondVault = contactContext.vaults.getVault({ keySystemIdentifier: secondVault.systemIdentifier }).getValue()
expect(updatedSecondVault.sharing.fileBytesUsed).to.equal(1374)
let myBytesUsedSetting = await context.application.settings.getSubscriptionSetting(
@@ -191,10 +191,10 @@ describe('shared vault quota', function () {
await context.syncAndAwaitNotificationsProcessing()
await contactContext.syncAndAwaitNotificationsProcessing()
updatedSharedVault = context.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
updatedSharedVault = context.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier }).getValue()
expect(updatedSharedVault.sharing.fileBytesUsed).to.equal(1374)
updatedSecondVault = contactContext.vaults.getVault({ keySystemIdentifier: secondVault.systemIdentifier })
updatedSecondVault = contactContext.vaults.getVault({ keySystemIdentifier: secondVault.systemIdentifier }).getValue()
expect(updatedSecondVault.sharing.fileBytesUsed).to.equal(0)
myBytesUsedSetting = await context.application.settings.getSubscriptionSetting(

View File

@@ -36,14 +36,14 @@ describe('shared vaults', function () {
description: 'new vault description',
})
const updatedVault = context.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
const updatedVault = context.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier }).getValue()
expect(updatedVault.name).to.equal('new vault name')
expect(updatedVault.description).to.equal('new vault description')
contactContext.unlockSyncing()
await contactContext.syncAndAwaitMessageProcessing()
const contactVault = contactContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
const contactVault = contactContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier }).getValue()
expect(contactVault.name).to.equal('new vault name')
expect(contactVault.description).to.equal('new vault description')
@@ -59,14 +59,14 @@ describe('shared vaults', function () {
await contactContext.syncAndAwaitNotificationsProcessing()
expect(contactContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })).to.be.undefined
expect(contactContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier }).isFailed()).to.be.true
expect(contactContext.keys.getPrimaryKeySystemRootKey(sharedVault.systemIdentifier)).to.be.undefined
expect(contactContext.keys.getKeySystemItemsKeys(sharedVault.systemIdentifier)).to.be.empty
const recreatedContext = await Factory.createVaultsContextWithRealCrypto(contactContext.identifier)
await recreatedContext.launch()
expect(recreatedContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })).to.be.undefined
expect(recreatedContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier }).isFailed()).to.be.true
expect(recreatedContext.keys.getPrimaryKeySystemRootKey(sharedVault.systemIdentifier)).to.be.undefined
expect(recreatedContext.keys.getKeySystemItemsKeys(sharedVault.systemIdentifier)).to.be.empty
@@ -84,14 +84,14 @@ describe('shared vaults', function () {
await contactContext.syncAndAwaitNotificationsProcessing()
expect(contactContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })).to.be.undefined
expect(contactContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier }).isFailed()).to.be.true
expect(contactContext.keys.getPrimaryKeySystemRootKey(sharedVault.systemIdentifier)).to.be.undefined
expect(contactContext.keys.getKeySystemItemsKeys(sharedVault.systemIdentifier)).to.be.empty
const recreatedContext = await Factory.createVaultsContextWithRealCrypto(contactContext.identifier)
await recreatedContext.launch()
expect(recreatedContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })).to.be.undefined
expect(recreatedContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier }).isFailed()).to.be.true
expect(recreatedContext.keys.getPrimaryKeySystemRootKey(sharedVault.systemIdentifier)).to.be.undefined
expect(recreatedContext.keys.getKeySystemItemsKeys(sharedVault.systemIdentifier)).to.be.empty

View File

@@ -6,7 +6,7 @@ chai.use(chaiAsPromised)
const expect = chai.expect
describe('designated survival', function () {
this.timeout(Factory.TwentySecondTimeout)
this.timeout(Factory.ThirtySecondTimeout)
let context
let secondContext
@@ -41,14 +41,14 @@ describe('designated survival', function () {
await Collaboration.createSharedVaultWithAcceptedInvite(context)
secondContext = contactContext
let vault = context.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
let vault = context.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier }).getValue()
expect(vault.sharing.designatedSurvivor).to.be.null
await Collaboration.designateSharedVaultSurvior(context, sharedVault, contactContext.userUuid)
await context.syncAndAwaitNotificationsProcessing()
vault = context.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
vault = context.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier }).getValue()
expect(vault.sharing.designatedSurvivor).to.equal(contactContext.userUuid)
})
@@ -77,15 +77,15 @@ describe('designated survival', function () {
const sharedVaultUsers = await secondContext.vaultUsers.getSharedVaultUsersFromServer(sharedVault)
expect(sharedVaultUsers.length).to.equal(2)
expect(context.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })).to.be.undefined
expect(context.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier }).isFailed()).to.be.true
expect(context.keys.getPrimaryKeySystemRootKey(sharedVault.systemIdentifier)).to.be.undefined
expect(context.keys.getKeySystemItemsKeys(sharedVault.systemIdentifier)).to.be.empty
expect(secondContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })).to.not.be.undefined
expect(secondContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier }).getValue()).to.not.be.undefined
expect(secondContext.keys.getPrimaryKeySystemRootKey(sharedVault.systemIdentifier)).to.not.be.undefined
expect(secondContext.keys.getKeySystemItemsKeys(sharedVault.systemIdentifier)).to.not.be.empty
expect(thirdContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })).to.not.be.undefined
expect(thirdContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier }).getValue()).to.not.be.undefined
expect(thirdContext.keys.getPrimaryKeySystemRootKey(sharedVault.systemIdentifier)).to.not.be.undefined
expect(thirdContext.keys.getKeySystemItemsKeys(sharedVault.systemIdentifier)).to.not.be.empty
})
@@ -184,11 +184,11 @@ describe('designated survival', function () {
await secondContext.syncAndAwaitNotificationsProcessing()
await thirdContext.syncAndAwaitNotificationsProcessing()
const contactVault = secondContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
const contactVault = secondContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier }).getValue()
expect(contactVault.sharing.ownerUserUuid).to.not.equal(context.userUuid)
expect(contactVault.sharing.ownerUserUuid).to.equal(secondContext.userUuid)
const thirdPartyVault = thirdContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
const thirdPartyVault = thirdContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier }).getValue()
expect(thirdPartyVault.sharing.ownerUserUuid).to.not.equal(context.userUuid)
expect(thirdPartyVault.sharing.ownerUserUuid).to.equal(secondContext.userUuid)
})
@@ -219,11 +219,11 @@ describe('designated survival', function () {
const sharedVaultUsers = await secondContext.vaultUsers.getSharedVaultUsersFromServer(sharedVault)
expect(sharedVaultUsers.length).to.equal(2)
expect(secondContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })).to.not.be.undefined
expect(secondContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier }).getValue()).to.not.be.undefined
expect(secondContext.keys.getPrimaryKeySystemRootKey(sharedVault.systemIdentifier)).to.not.be.undefined
expect(secondContext.keys.getKeySystemItemsKeys(sharedVault.systemIdentifier)).to.not.be.empty
expect(thirdContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })).to.not.be.undefined
expect(thirdContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier }).getValue()).to.not.be.undefined
expect(thirdContext.keys.getPrimaryKeySystemRootKey(sharedVault.systemIdentifier)).to.not.be.undefined
expect(thirdContext.keys.getKeySystemItemsKeys(sharedVault.systemIdentifier)).to.not.be.empty
})
@@ -325,10 +325,10 @@ describe('designated survival', function () {
await secondContext.syncAndAwaitNotificationsProcessing()
await thirdContext.syncAndAwaitNotificationsProcessing()
const contactVault = secondContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
const contactVault = secondContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier }).getValue()
expect(contactVault.sharing.ownerUserUuid).to.equal(secondContext.userUuid)
const thirdPartyVault = thirdContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
const thirdPartyVault = thirdContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier }).getValue()
expect(thirdPartyVault.sharing.ownerUserUuid).to.equal(secondContext.userUuid)
})
})
@@ -351,11 +351,11 @@ describe('designated survival', function () {
await secondContext.syncAndAwaitNotificationsProcessing()
await thirdContext.syncAndAwaitNotificationsProcessing()
expect(secondContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })).to.be.undefined
expect(secondContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier }).isFailed()).to.be.true
expect(secondContext.keys.getPrimaryKeySystemRootKey(sharedVault.systemIdentifier)).to.be.undefined
expect(secondContext.keys.getKeySystemItemsKeys(sharedVault.systemIdentifier)).to.be.empty
expect(thirdContext.vaults.getVault({ keySystemIdentifier: secondSharedVault.systemIdentifier })).to.be.undefined
expect(thirdContext.vaults.getVault({ keySystemIdentifier: secondSharedVault.systemIdentifier }).isFailed()).to.be.true
expect(thirdContext.keys.getPrimaryKeySystemRootKey(secondSharedVault.systemIdentifier)).to.be.undefined
expect(thirdContext.keys.getKeySystemItemsKeys(secondSharedVault.systemIdentifier)).to.be.empty
})

View File

@@ -222,9 +222,10 @@ export class VaultDisplayService
}
if (this.isInExclusiveDisplayMode()) {
this.exclusivelyShownVault = this.application.vaults.getVault({
const vaultOrError = this.application.vaults.getVault({
keySystemIdentifier: this.options.getExclusivelyShownVault(),
})
this.exclusivelyShownVault = vaultOrError.isFailed() ? undefined : vaultOrError.getValue()
} else {
this.exclusivelyShownVault = undefined
}