refactor: break up vault services (#2364)
This commit is contained in:
@@ -71,6 +71,10 @@ import {
|
||||
HistoryServiceInterface,
|
||||
InternalEventPublishStrategy,
|
||||
EncryptionProviderInterface,
|
||||
VaultUserServiceInterface,
|
||||
VaultInviteServiceInterface,
|
||||
UserEventServiceEvent,
|
||||
VaultServiceEvent,
|
||||
} from '@standardnotes/services'
|
||||
import {
|
||||
PayloadEmitSource,
|
||||
@@ -1130,7 +1134,15 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
this.events.addEventHandler(this.dependencies.get(TYPES.UserService), AccountEvent.SignedInOrRegistered)
|
||||
this.events.addEventHandler(this.dependencies.get(TYPES.SessionManager), ApiServiceEvent.SessionRefreshed)
|
||||
|
||||
this.events.addEventHandler(this.dependencies.get(TYPES.SharedVaultService), SyncEvent.ReceivedSharedVaultInvites)
|
||||
this.events.addEventHandler(this.dependencies.get(TYPES.VaultInviteService), SyncEvent.ReceivedSharedVaultInvites)
|
||||
this.events.addEventHandler(this.dependencies.get(TYPES.VaultInviteService), SessionEvent.UserKeyPairChanged)
|
||||
|
||||
this.events.addEventHandler(this.dependencies.get(TYPES.SharedVaultService), SessionEvent.UserKeyPairChanged)
|
||||
this.events.addEventHandler(
|
||||
this.dependencies.get(TYPES.SharedVaultService),
|
||||
UserEventServiceEvent.UserEventReceived,
|
||||
)
|
||||
this.events.addEventHandler(this.dependencies.get(TYPES.SharedVaultService), VaultServiceEvent.VaultRootKeyRotated)
|
||||
this.events.addEventHandler(this.dependencies.get(TYPES.SharedVaultService), SyncEvent.ReceivedRemoteSharedVaults)
|
||||
|
||||
this.events.addEventHandler(
|
||||
@@ -1332,14 +1344,26 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
return this.dependencies.get<HistoryServiceInterface>(TYPES.HistoryManager)
|
||||
}
|
||||
|
||||
private get migrations(): MigrationService {
|
||||
return this.dependencies.get<MigrationService>(TYPES.MigrationService)
|
||||
}
|
||||
|
||||
public get encryption(): EncryptionProviderInterface {
|
||||
return this.dependencies.get<EncryptionProviderInterface>(TYPES.EncryptionService)
|
||||
}
|
||||
|
||||
public get events(): InternalEventBusInterface {
|
||||
return this.dependencies.get<InternalEventBusInterface>(TYPES.InternalEventBus)
|
||||
}
|
||||
|
||||
public get vaultUsers(): VaultUserServiceInterface {
|
||||
return this.dependencies.get<VaultUserServiceInterface>(TYPES.VaultUserService)
|
||||
}
|
||||
|
||||
public get vaultInvites(): VaultInviteServiceInterface {
|
||||
return this.dependencies.get<VaultInviteServiceInterface>(TYPES.VaultInviteService)
|
||||
}
|
||||
|
||||
private get migrations(): MigrationService {
|
||||
return this.dependencies.get<MigrationService>(TYPES.MigrationService)
|
||||
}
|
||||
|
||||
private get legacyApi(): LegacyApiService {
|
||||
return this.dependencies.get<LegacyApiService>(TYPES.LegacyApiService)
|
||||
}
|
||||
@@ -1352,10 +1376,6 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
return this.dependencies.get<WebSocketsService>(TYPES.WebSocketsService)
|
||||
}
|
||||
|
||||
public get events(): InternalEventBusInterface {
|
||||
return this.dependencies.get<InternalEventBusInterface>(TYPES.InternalEventBus)
|
||||
}
|
||||
|
||||
private get mfa(): SNMfaService {
|
||||
return this.dependencies.get<SNMfaService>(TYPES.MfaService)
|
||||
}
|
||||
|
||||
@@ -108,6 +108,9 @@ import {
|
||||
RootKeyManager,
|
||||
ItemsEncryptionService,
|
||||
DecryptBackupFile,
|
||||
VaultUserService,
|
||||
IsVaultAdmin,
|
||||
VaultInviteService,
|
||||
} from '@standardnotes/services'
|
||||
import { ItemManager } from '../../Services/Items/ItemManager'
|
||||
import { PayloadManager } from '../../Services/Payloads/PayloadManager'
|
||||
@@ -204,6 +207,10 @@ export class Dependencies {
|
||||
)
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.IsVaultAdmin, () => {
|
||||
return new IsVaultAdmin()
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.DecryptBackupFile, () => {
|
||||
return new DecryptBackupFile(this.get(TYPES.EncryptionService))
|
||||
})
|
||||
@@ -608,6 +615,39 @@ export class Dependencies {
|
||||
return new SharedVaultUsersServer(this.get(TYPES.HttpService))
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.VaultUserService, () => {
|
||||
return new VaultUserService(
|
||||
this.get(TYPES.SessionManager),
|
||||
this.get(TYPES.VaultService),
|
||||
this.get(TYPES.GetVaultUsers),
|
||||
this.get(TYPES.RemoveVaultMember),
|
||||
this.get(TYPES.IsVaultAdmin),
|
||||
this.get(TYPES.GetVault),
|
||||
this.get(TYPES.LeaveVault),
|
||||
this.get(TYPES.InternalEventBus),
|
||||
)
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.VaultInviteService, () => {
|
||||
return new VaultInviteService(
|
||||
this.get(TYPES.ItemManager),
|
||||
this.get(TYPES.SessionManager),
|
||||
this.get(TYPES.VaultUserService),
|
||||
this.get(TYPES.SyncService),
|
||||
this.get(TYPES.EncryptionService),
|
||||
this.get(TYPES.SharedVaultInvitesServer),
|
||||
this.get(TYPES.GetAllContacts),
|
||||
this.get(TYPES.GetVault),
|
||||
this.get(TYPES.GetVaultContacts),
|
||||
this.get(TYPES.InviteToVault),
|
||||
this.get(TYPES.GetTrustedPayload),
|
||||
this.get(TYPES.GetUntrustedPayload),
|
||||
this.get(TYPES.FindContact),
|
||||
this.get(TYPES.AcceptVaultInvite),
|
||||
this.get(TYPES.InternalEventBus),
|
||||
)
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.AsymmetricMessageService, () => {
|
||||
return new AsymmetricMessageService(
|
||||
this.get(TYPES.AsymmetricMessageServer),
|
||||
@@ -630,31 +670,21 @@ export class Dependencies {
|
||||
|
||||
this.factory.set(TYPES.SharedVaultService, () => {
|
||||
return new SharedVaultService(
|
||||
this.get(TYPES.SyncService),
|
||||
this.get(TYPES.ItemManager),
|
||||
this.get(TYPES.EncryptionService),
|
||||
this.get(TYPES.SessionManager),
|
||||
this.get(TYPES.VaultService),
|
||||
this.get(TYPES.SharedVaultInvitesServer),
|
||||
this.get(TYPES.GetVault),
|
||||
this.get(TYPES.CreateSharedVault),
|
||||
this.get(TYPES.HandleKeyPairChange),
|
||||
this.get(TYPES.NotifyVaultUsersOfKeyRotation),
|
||||
this.get(TYPES.SendVaultDataChangedMessage),
|
||||
this.get(TYPES.GetTrustedPayload),
|
||||
this.get(TYPES.GetUntrustedPayload),
|
||||
this.get(TYPES.FindContact),
|
||||
this.get(TYPES.GetAllContacts),
|
||||
this.get(TYPES.GetVaultContacts),
|
||||
this.get(TYPES.AcceptVaultInvite),
|
||||
this.get(TYPES.InviteToVault),
|
||||
this.get(TYPES.LeaveVault),
|
||||
this.get(TYPES.DeleteThirdPartyVault),
|
||||
this.get(TYPES.ShareContactWithVault),
|
||||
this.get(TYPES.ConvertToSharedVault),
|
||||
this.get(TYPES.DeleteSharedVault),
|
||||
this.get(TYPES.RemoveVaultMember),
|
||||
this.get(TYPES.GetVaultUsers),
|
||||
this.get(TYPES.IsVaultAdmin),
|
||||
this.get(TYPES.InternalEventBus),
|
||||
)
|
||||
})
|
||||
|
||||
@@ -59,6 +59,8 @@ export const TYPES = {
|
||||
EncryptionOperators: Symbol.for('EncryptionOperators'),
|
||||
RootKeyManager: Symbol.for('RootKeyManager'),
|
||||
ItemsEncryptionService: Symbol.for('ItemsEncryptionService'),
|
||||
VaultUserService: Symbol.for('VaultUserService'),
|
||||
VaultInviteService: Symbol.for('VaultInviteService'),
|
||||
|
||||
// Servers
|
||||
RevisionServer: Symbol.for('RevisionServer'),
|
||||
@@ -140,6 +142,7 @@ export const TYPES = {
|
||||
EncryptTypeAPayload: Symbol.for('EncryptTypeAPayload'),
|
||||
EncryptTypeAPayloadWithKeyLookup: Symbol.for('EncryptTypeAPayloadWithKeyLookup'),
|
||||
DecryptBackupFile: Symbol.for('DecryptBackupFile'),
|
||||
IsVaultAdmin: Symbol.for('IsVaultAdmin'),
|
||||
|
||||
// Mappers
|
||||
SessionStorageMapper: Symbol.for('SessionStorageMapper'),
|
||||
|
||||
@@ -97,6 +97,14 @@ export class AppContext {
|
||||
return this.application.sharedVaults
|
||||
}
|
||||
|
||||
get vaultUsers() {
|
||||
return this.application.vaultUsers
|
||||
}
|
||||
|
||||
get vaultInvites() {
|
||||
return this.application.vaultInvites
|
||||
}
|
||||
|
||||
get files() {
|
||||
return this.application.files
|
||||
}
|
||||
@@ -210,16 +218,6 @@ export class AppContext {
|
||||
})
|
||||
}
|
||||
|
||||
resolveWhenSharedVaultUserKeysResolved() {
|
||||
return new Promise((resolve) => {
|
||||
this.application.vaults.collaboration.addEventObserver((eventName) => {
|
||||
if (eventName === SharedVaultServiceEvent.SharedVaultStatusChanged) {
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
async awaitSignInEvent() {
|
||||
return new Promise((resolve) => {
|
||||
this.application.user.addEventObserver((eventName) => {
|
||||
@@ -394,7 +392,7 @@ export class AppContext {
|
||||
|
||||
resolveWhenAllInboundSharedVaultInvitesAreDeleted() {
|
||||
return new Promise((resolve) => {
|
||||
const objectToSpy = this.application.sharedVaults.invitesServer
|
||||
const objectToSpy = this.application.vaultInvites.invitesServer
|
||||
sinon.stub(objectToSpy, 'deleteAllInboundInvites').callsFake(async (params) => {
|
||||
objectToSpy.deleteAllInboundInvites.restore()
|
||||
const result = await objectToSpy.deleteAllInboundInvites(params)
|
||||
|
||||
@@ -26,13 +26,13 @@ export const createTrustedContactForUserOfContext = async (
|
||||
}
|
||||
|
||||
export const acceptAllInvites = async (context) => {
|
||||
const inviteRecords = context.sharedVaults.getCachedPendingInviteRecords()
|
||||
const inviteRecords = context.vaultInvites.getCachedPendingInviteRecords()
|
||||
if (inviteRecords.length === 0) {
|
||||
throw new Error('No pending invites to accept')
|
||||
}
|
||||
|
||||
for (const record of inviteRecords) {
|
||||
await context.sharedVaults.acceptPendingSharedVaultInvite(record)
|
||||
await context.vaultInvites.acceptInvite(record)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ export const createSharedVaultWithUnacceptedButTrustedInvite = async (
|
||||
const contact = await createTrustedContactForUserOfContext(context, contactContext)
|
||||
await createTrustedContactForUserOfContext(contactContext, context)
|
||||
|
||||
const invite = (await context.sharedVaults.inviteContactToSharedVault(sharedVault, contact, permissions)).getValue()
|
||||
const invite = (await context.vaultInvites.inviteContactToSharedVault(sharedVault, contact, permissions)).getValue()
|
||||
await contactContext.sync()
|
||||
|
||||
return { sharedVault, contact, contactContext, deinitContactContext, invite }
|
||||
@@ -91,7 +91,7 @@ export const createSharedVaultWithUnacceptedAndUntrustedInvite = async (
|
||||
const { contactContext, deinitContactContext } = await createContactContext()
|
||||
const contact = await createTrustedContactForUserOfContext(context, contactContext)
|
||||
|
||||
const invite = (await context.sharedVaults.inviteContactToSharedVault(sharedVault, contact, permissions)).getValue()
|
||||
const invite = (await context.vaultInvites.inviteContactToSharedVault(sharedVault, contact, permissions)).getValue()
|
||||
await contactContext.sync()
|
||||
|
||||
return { sharedVault, contact, contactContext, deinitContactContext, invite }
|
||||
@@ -103,7 +103,7 @@ export const inviteNewPartyToSharedVault = async (context, sharedVault, permissi
|
||||
|
||||
const thirdPartyContact = await createTrustedContactForUserOfContext(context, thirdPartyContext)
|
||||
await createTrustedContactForUserOfContext(thirdPartyContext, context)
|
||||
await context.sharedVaults.inviteContactToSharedVault(sharedVault, thirdPartyContact, permissions)
|
||||
await context.vaultInvites.inviteContactToSharedVault(sharedVault, thirdPartyContact, permissions)
|
||||
|
||||
await thirdPartyContext.sync()
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ describe('shared vault conflicts', function () {
|
||||
await Collaboration.createSharedVaultWithAcceptedInviteAndNote(context)
|
||||
|
||||
contactContext.lockSyncing()
|
||||
await context.sharedVaults.removeUserFromSharedVault(sharedVault, contactContext.userUuid)
|
||||
await context.vaultUsers.removeUserFromSharedVault(sharedVault, contactContext.userUuid)
|
||||
const promise = contactContext.resolveWithConflicts()
|
||||
contactContext.unlockSyncing()
|
||||
await contactContext.changeNoteTitleAndSync(note, 'new title')
|
||||
@@ -98,7 +98,7 @@ describe('shared vault conflicts', function () {
|
||||
const { sharedVault, note, contactContext, deinitContactContext } =
|
||||
await Collaboration.createSharedVaultWithAcceptedInviteAndNote(context)
|
||||
|
||||
await context.sharedVaults.removeUserFromSharedVault(sharedVault, contactContext.userUuid)
|
||||
await context.vaultUsers.removeUserFromSharedVault(sharedVault, contactContext.userUuid)
|
||||
await contactContext.changeNoteTitleAndSync(note, 'new title')
|
||||
const notes = contactContext.notes
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ describe('shared vault deletion', function () {
|
||||
const contactNote = contactContext.items.findItem(note.uuid)
|
||||
expect(contactNote).to.not.be.undefined
|
||||
|
||||
await context.sharedVaults.removeUserFromSharedVault(sharedVault, contactContext.userUuid)
|
||||
await context.vaultUsers.removeUserFromSharedVault(sharedVault, contactContext.userUuid)
|
||||
|
||||
await contactContext.sync()
|
||||
|
||||
@@ -108,7 +108,7 @@ describe('shared vault deletion', function () {
|
||||
expect(originalNote).to.not.be.undefined
|
||||
|
||||
const contactVault = contactContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
|
||||
await contactContext.sharedVaults.leaveSharedVault(contactVault)
|
||||
await contactContext.vaultUsers.leaveSharedVault(contactVault)
|
||||
|
||||
const updatedContactNote = contactContext.items.findItem(note.uuid)
|
||||
expect(updatedContactNote).to.be.undefined
|
||||
@@ -140,14 +140,13 @@ describe('shared vault deletion', function () {
|
||||
const { sharedVault, contactContext, deinitContactContext } =
|
||||
await Collaboration.createSharedVaultWithAcceptedInvite(context)
|
||||
|
||||
const originalSharedVaultUsers = await sharedVaults.getSharedVaultUsers(sharedVault)
|
||||
const originalSharedVaultUsers = await context.vaultUsers.getSharedVaultUsers(sharedVault)
|
||||
expect(originalSharedVaultUsers.length).to.equal(2)
|
||||
|
||||
const result = await sharedVaults.removeUserFromSharedVault(sharedVault, contactContext.userUuid)
|
||||
const result = await context.vaultUsers.removeUserFromSharedVault(sharedVault, contactContext.userUuid)
|
||||
expect(result.isFailed()).to.be.false
|
||||
|
||||
expect(isClientDisplayableError(result)).to.be.false
|
||||
|
||||
const updatedSharedVaultUsers = await sharedVaults.getSharedVaultUsers(sharedVault)
|
||||
const updatedSharedVaultUsers = await context.vaultUsers.getSharedVaultUsers(sharedVault)
|
||||
expect(updatedSharedVaultUsers.length).to.equal(1)
|
||||
|
||||
await deinitContactContext()
|
||||
|
||||
@@ -249,7 +249,7 @@ describe('shared vault files', function () {
|
||||
const uploadedFile = await Files.uploadFile(context.files, buffer, 'my-file', 'md', 1000, sharedVault)
|
||||
await contactContext.sync()
|
||||
|
||||
await context.sharedVaults.removeUserFromSharedVault(sharedVault, contactContext.userUuid)
|
||||
await context.vaultUsers.removeUserFromSharedVault(sharedVault, contactContext.userUuid)
|
||||
|
||||
const file = contactContext.items.findItem(uploadedFile.uuid)
|
||||
await Factory.expectThrowsAsync(() => Files.downloadFile(contactContext.files, file), 'Could not download file')
|
||||
|
||||
@@ -8,7 +8,6 @@ describe('shared vault invites', function () {
|
||||
this.timeout(Factory.TwentySecondTimeout)
|
||||
|
||||
let context
|
||||
let sharedVaults
|
||||
|
||||
afterEach(async function () {
|
||||
await context.deinit()
|
||||
@@ -21,8 +20,6 @@ describe('shared vault invites', function () {
|
||||
context = await Factory.createAppContextWithRealCrypto()
|
||||
await context.launch()
|
||||
await context.register()
|
||||
|
||||
sharedVaults = context.sharedVaults
|
||||
})
|
||||
|
||||
it('should invite contact to vault', async () => {
|
||||
@@ -31,7 +28,7 @@ describe('shared vault invites', function () {
|
||||
const contact = await Collaboration.createTrustedContactForUserOfContext(context, contactContext)
|
||||
|
||||
const vaultInvite = (
|
||||
await sharedVaults.inviteContactToSharedVault(sharedVault, contact, SharedVaultPermission.Write)
|
||||
await context.vaultInvites.inviteContactToSharedVault(sharedVault, contact, SharedVaultPermission.Write)
|
||||
).getValue()
|
||||
|
||||
expect(vaultInvite).to.not.be.undefined
|
||||
@@ -49,7 +46,7 @@ describe('shared vault invites', function () {
|
||||
const { contactContext, deinitContactContext } =
|
||||
await Collaboration.createSharedVaultWithUnacceptedButTrustedInvite(context)
|
||||
|
||||
const invites = contactContext.sharedVaults.getCachedPendingInviteRecords()
|
||||
const invites = contactContext.vaultInvites.getCachedPendingInviteRecords()
|
||||
|
||||
expect(invites[0].trusted).to.be.true
|
||||
|
||||
@@ -60,7 +57,7 @@ describe('shared vault invites', function () {
|
||||
const { contactContext, deinitContactContext } =
|
||||
await Collaboration.createSharedVaultWithUnacceptedAndUntrustedInvite(context)
|
||||
|
||||
const invites = contactContext.sharedVaults.getCachedPendingInviteRecords()
|
||||
const invites = contactContext.vaultInvites.getCachedPendingInviteRecords()
|
||||
|
||||
expect(invites[0].trusted).to.be.false
|
||||
|
||||
@@ -76,7 +73,7 @@ describe('shared vault invites', function () {
|
||||
sharedVault,
|
||||
)
|
||||
|
||||
const invites = thirdPartyContext.sharedVaults.getCachedPendingInviteRecords()
|
||||
const invites = thirdPartyContext.vaultInvites.getCachedPendingInviteRecords()
|
||||
|
||||
const message = invites[0].message
|
||||
const delegatedContacts = message.data.trustedContacts
|
||||
@@ -103,7 +100,7 @@ describe('shared vault invites', function () {
|
||||
/** Sync the contact context so that they wouldn't naturally receive changes made before this point */
|
||||
await contactContext.sync()
|
||||
|
||||
await sharedVaults.inviteContactToSharedVault(sharedVault, contact, SharedVaultPermission.Write)
|
||||
await context.vaultInvites.inviteContactToSharedVault(sharedVault, contact, SharedVaultPermission.Write)
|
||||
|
||||
/** Contact should now sync and expect to find note */
|
||||
const promise = contactContext.awaitNextSyncSharedVaultFromScratchEvent()
|
||||
@@ -125,10 +122,14 @@ describe('shared vault invites', function () {
|
||||
const sharedVault = await Collaboration.createSharedVault(context)
|
||||
|
||||
const currentContextContact = await Collaboration.createTrustedContactForUserOfContext(context, contactContext)
|
||||
await sharedVaults.inviteContactToSharedVault(sharedVault, currentContextContact, SharedVaultPermission.Write)
|
||||
await context.vaultInvites.inviteContactToSharedVault(
|
||||
sharedVault,
|
||||
currentContextContact,
|
||||
SharedVaultPermission.Write,
|
||||
)
|
||||
|
||||
await contactContext.sharedVaults.downloadInboundInvites()
|
||||
expect(contactContext.sharedVaults.getCachedPendingInviteRecords()[0].trusted).to.be.false
|
||||
await contactContext.vaultInvites.downloadInboundInvites()
|
||||
expect(contactContext.vaultInvites.getCachedPendingInviteRecords()[0].trusted).to.be.false
|
||||
|
||||
await deinitContactContext()
|
||||
})
|
||||
@@ -139,14 +140,18 @@ describe('shared vault invites', function () {
|
||||
const sharedVault = await Collaboration.createSharedVault(context)
|
||||
|
||||
const currentContextContact = await Collaboration.createTrustedContactForUserOfContext(context, contactContext)
|
||||
await sharedVaults.inviteContactToSharedVault(sharedVault, currentContextContact, SharedVaultPermission.Write)
|
||||
await context.vaultInvites.inviteContactToSharedVault(
|
||||
sharedVault,
|
||||
currentContextContact,
|
||||
SharedVaultPermission.Write,
|
||||
)
|
||||
|
||||
await contactContext.sharedVaults.downloadInboundInvites()
|
||||
expect(contactContext.sharedVaults.getCachedPendingInviteRecords()[0].trusted).to.be.false
|
||||
await contactContext.vaultInvites.downloadInboundInvites()
|
||||
expect(contactContext.vaultInvites.getCachedPendingInviteRecords()[0].trusted).to.be.false
|
||||
|
||||
await Collaboration.createTrustedContactForUserOfContext(contactContext, context)
|
||||
|
||||
expect(contactContext.sharedVaults.getCachedPendingInviteRecords()[0].trusted).to.be.true
|
||||
expect(contactContext.vaultInvites.getCachedPendingInviteRecords()[0].trusted).to.be.true
|
||||
|
||||
await deinitContactContext()
|
||||
})
|
||||
@@ -184,12 +189,12 @@ describe('shared vault invites', function () {
|
||||
const { invite, contactContext, deinitContactContext } =
|
||||
await Collaboration.createSharedVaultWithUnacceptedButTrustedInvite(context)
|
||||
|
||||
const preInvites = await contactContext.sharedVaults.downloadInboundInvites()
|
||||
const preInvites = await contactContext.vaultInvites.downloadInboundInvites()
|
||||
expect(preInvites.length).to.equal(1)
|
||||
|
||||
await sharedVaults.deleteInvite(invite)
|
||||
await context.vaultInvites.deleteInvite(invite)
|
||||
|
||||
const postInvites = await contactContext.sharedVaults.downloadInboundInvites()
|
||||
const postInvites = await contactContext.vaultInvites.downloadInboundInvites()
|
||||
expect(postInvites.length).to.equal(0)
|
||||
|
||||
await deinitContactContext()
|
||||
@@ -208,7 +213,7 @@ describe('shared vault invites', function () {
|
||||
await contactContext.changePassword('new-password')
|
||||
await promise
|
||||
|
||||
const invites = await contactContext.sharedVaults.downloadInboundInvites()
|
||||
const invites = await contactContext.vaultInvites.downloadInboundInvites()
|
||||
expect(invites.length).to.equal(0)
|
||||
|
||||
await deinitContactContext()
|
||||
|
||||
@@ -8,7 +8,6 @@ describe('shared vault items', function () {
|
||||
this.timeout(Factory.TwentySecondTimeout)
|
||||
|
||||
let context
|
||||
let sharedVaults
|
||||
|
||||
afterEach(async function () {
|
||||
await context.deinit()
|
||||
@@ -22,8 +21,6 @@ describe('shared vault items', function () {
|
||||
|
||||
await context.launch()
|
||||
await context.register()
|
||||
|
||||
sharedVaults = context.sharedVaults
|
||||
})
|
||||
|
||||
it('should add item to shared vault with no other members', async () => {
|
||||
@@ -60,7 +57,11 @@ describe('shared vault items', function () {
|
||||
const currentContextContact = await Collaboration.createTrustedContactForUserOfContext(context, contactContext)
|
||||
|
||||
contactContext.lockSyncing()
|
||||
await sharedVaults.inviteContactToSharedVault(sharedVault, currentContextContact, SharedVaultPermission.Write)
|
||||
await context.vaultInvites.inviteContactToSharedVault(
|
||||
sharedVault,
|
||||
currentContextContact,
|
||||
SharedVaultPermission.Write,
|
||||
)
|
||||
await Collaboration.moveItemToVault(context, sharedVault, note)
|
||||
|
||||
const promise = contactContext.awaitNextSyncSharedVaultFromScratchEvent()
|
||||
|
||||
@@ -8,8 +8,6 @@ describe('shared vault key rotation', function () {
|
||||
this.timeout(Factory.TwentySecondTimeout)
|
||||
|
||||
let context
|
||||
let vaults
|
||||
let sharedVaults
|
||||
|
||||
afterEach(async function () {
|
||||
await context.deinit()
|
||||
@@ -23,9 +21,6 @@ describe('shared vault key rotation', function () {
|
||||
|
||||
await context.launch()
|
||||
await context.register()
|
||||
|
||||
vaults = context.vaults
|
||||
sharedVaults = context.sharedVaults
|
||||
})
|
||||
|
||||
it('should reencrypt all items keys belonging to key system', async () => {
|
||||
@@ -37,7 +32,7 @@ describe('shared vault key rotation', function () {
|
||||
const spy = sinon.spy(context.keys, 'reencryptKeySystemItemsKeysForVault')
|
||||
|
||||
const promise = context.resolveWhenSharedVaultKeyRotationInvitesGetSent(sharedVault)
|
||||
await vaults.rotateVaultRootKey(sharedVault)
|
||||
await context.vaults.rotateVaultRootKey(sharedVault)
|
||||
await promise
|
||||
|
||||
expect(spy.callCount).to.equal(1)
|
||||
@@ -52,7 +47,7 @@ describe('shared vault key rotation', function () {
|
||||
contactContext.lockSyncing()
|
||||
|
||||
const promise = context.resolveWhenSharedVaultKeyRotationInvitesGetSent(sharedVault)
|
||||
await vaults.rotateVaultRootKey(sharedVault)
|
||||
await context.vaults.rotateVaultRootKey(sharedVault)
|
||||
await promise
|
||||
|
||||
const outboundMessages = await context.asymmetric.getOutboundMessages()
|
||||
@@ -79,7 +74,7 @@ describe('shared vault key rotation', function () {
|
||||
contactContext.lockSyncing()
|
||||
|
||||
const promise = context.resolveWhenSharedVaultKeyRotationInvitesGetSent(sharedVault)
|
||||
await vaults.rotateVaultRootKey(sharedVault)
|
||||
await context.vaults.rotateVaultRootKey(sharedVault)
|
||||
await promise
|
||||
|
||||
const rootKey = context.keys.getPrimaryKeySystemRootKey(sharedVault.systemIdentifier)
|
||||
@@ -107,7 +102,7 @@ describe('shared vault key rotation', function () {
|
||||
expect(previousPrimaryItemsKey).to.not.be.undefined
|
||||
|
||||
const promise = context.resolveWhenSharedVaultKeyRotationInvitesGetSent(sharedVault)
|
||||
await vaults.rotateVaultRootKey(sharedVault)
|
||||
await context.vaults.rotateVaultRootKey(sharedVault)
|
||||
await promise
|
||||
|
||||
const contactPromise = contactContext.resolveWhenAsymmetricMessageProcessingCompletes()
|
||||
@@ -129,15 +124,15 @@ describe('shared vault key rotation', function () {
|
||||
await Collaboration.createSharedVaultWithUnacceptedButTrustedInvite(context)
|
||||
contactContext.lockSyncing()
|
||||
|
||||
const originalOutboundInvites = await sharedVaults.getOutboundInvites()
|
||||
const originalOutboundInvites = await context.vaultInvites.getOutboundInvites()
|
||||
expect(originalOutboundInvites.length).to.equal(1)
|
||||
const originalInviteMessage = originalOutboundInvites[0].encrypted_message
|
||||
|
||||
const promise = context.resolveWhenSharedVaultKeyRotationInvitesGetSent(sharedVault)
|
||||
await vaults.rotateVaultRootKey(sharedVault)
|
||||
await context.vaults.rotateVaultRootKey(sharedVault)
|
||||
await promise
|
||||
|
||||
const updatedOutboundInvites = await sharedVaults.getOutboundInvites()
|
||||
const updatedOutboundInvites = await context.vaultInvites.getOutboundInvites()
|
||||
expect(updatedOutboundInvites.length).to.equal(1)
|
||||
|
||||
const joinInvite = updatedOutboundInvites[0]
|
||||
@@ -150,7 +145,7 @@ describe('shared vault key rotation', function () {
|
||||
it('new key system items key in rotated shared vault should belong to shared vault', async () => {
|
||||
const sharedVault = await Collaboration.createSharedVault(context)
|
||||
|
||||
await vaults.rotateVaultRootKey(sharedVault)
|
||||
await context.vaults.rotateVaultRootKey(sharedVault)
|
||||
|
||||
const keySystemItemsKeys = context.keys
|
||||
.getAllKeySystemItemsKeys()
|
||||
@@ -170,7 +165,7 @@ describe('shared vault key rotation', function () {
|
||||
contactContext.lockSyncing()
|
||||
|
||||
const firstPromise = context.resolveWhenSharedVaultKeyRotationInvitesGetSent(sharedVault)
|
||||
await vaults.rotateVaultRootKey(sharedVault)
|
||||
await context.vaults.rotateVaultRootKey(sharedVault)
|
||||
await firstPromise
|
||||
|
||||
const asymmetricMessageAfterFirstChange = await context.asymmetric.getOutboundMessages()
|
||||
@@ -180,7 +175,7 @@ describe('shared vault key rotation', function () {
|
||||
const messageAfterFirstChange = asymmetricMessageAfterFirstChange[0]
|
||||
|
||||
const secondPromise = context.resolveWhenSharedVaultKeyRotationInvitesGetSent(sharedVault)
|
||||
await vaults.rotateVaultRootKey(sharedVault)
|
||||
await context.vaults.rotateVaultRootKey(sharedVault)
|
||||
await secondPromise
|
||||
|
||||
const asymmetricMessageAfterSecondChange = await context.asymmetric.getOutboundMessages()
|
||||
@@ -204,7 +199,7 @@ describe('shared vault key rotation', function () {
|
||||
contactContext.lockSyncing()
|
||||
|
||||
const promise = context.resolveWhenSharedVaultKeyRotationInvitesGetSent(sharedVault)
|
||||
await vaults.rotateVaultRootKey(sharedVault)
|
||||
await context.vaults.rotateVaultRootKey(sharedVault)
|
||||
await promise
|
||||
|
||||
const acceptMessage = sinon.spy(contactContext.asymmetric, 'handleTrustedSharedVaultRootKeyChangedMessage')
|
||||
@@ -223,7 +218,7 @@ describe('shared vault key rotation', function () {
|
||||
|
||||
const originalKeySystemRootKey = context.keys.getPrimaryKeySystemRootKey(sharedVault.systemIdentifier)
|
||||
|
||||
await sharedVaults.removeUserFromSharedVault(sharedVault, contactContext.userUuid)
|
||||
await context.vaultUsers.removeUserFromSharedVault(sharedVault, contactContext.userUuid)
|
||||
|
||||
const newKeySystemRootKey = context.keys.getPrimaryKeySystemRootKey(sharedVault.systemIdentifier)
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ describe('shared vault permissions', function () {
|
||||
this.timeout(Factory.TwentySecondTimeout)
|
||||
|
||||
let context
|
||||
let sharedVaults
|
||||
|
||||
afterEach(async function () {
|
||||
await context.deinit()
|
||||
@@ -22,8 +21,6 @@ describe('shared vault permissions', function () {
|
||||
|
||||
await context.launch()
|
||||
await context.register()
|
||||
|
||||
sharedVaults = context.sharedVaults
|
||||
})
|
||||
|
||||
it('non-admin user should not be able to invite user', async () => {
|
||||
@@ -37,7 +34,7 @@ describe('shared vault permissions', function () {
|
||||
contactContext,
|
||||
thirdParty.contactContext,
|
||||
)
|
||||
const result = await contactContext.sharedVaults.inviteContactToSharedVault(
|
||||
const result = await contactContext.vaultInvites.inviteContactToSharedVault(
|
||||
sharedVault,
|
||||
thirdPartyContact,
|
||||
SharedVaultPermission.Write,
|
||||
@@ -53,16 +50,15 @@ describe('shared vault permissions', function () {
|
||||
|
||||
const sharedVault = await Collaboration.createSharedVault(context)
|
||||
|
||||
const result = await sharedVaults.removeUserFromSharedVault(sharedVault, context.userUuid)
|
||||
|
||||
expect(isClientDisplayableError(result)).to.be.true
|
||||
const result = await context.vaultUsers.removeUserFromSharedVault(sharedVault, context.userUuid)
|
||||
expect(result.isFailed()).to.be.true
|
||||
})
|
||||
|
||||
it('should be able to leave shared vault as added admin', async () => {
|
||||
const { contactVault, contactContext, deinitContactContext } =
|
||||
await Collaboration.createSharedVaultWithAcceptedInvite(context, SharedVaultPermission.Admin)
|
||||
|
||||
const result = await contactContext.sharedVaults.leaveSharedVault(contactVault)
|
||||
const result = await contactContext.vaultUsers.leaveSharedVault(contactVault)
|
||||
|
||||
expect(isClientDisplayableError(result)).to.be.false
|
||||
|
||||
|
||||
@@ -54,9 +54,8 @@ describe('shared vaults', function () {
|
||||
const { sharedVault, contactContext, deinitContactContext } =
|
||||
await Collaboration.createSharedVaultWithAcceptedInvite(context)
|
||||
|
||||
const result = await context.sharedVaults.removeUserFromSharedVault(sharedVault, contactContext.userUuid)
|
||||
|
||||
expect(result).to.be.undefined
|
||||
const result = await context.vaultUsers.removeUserFromSharedVault(sharedVault, contactContext.userUuid)
|
||||
expect(result.isFailed()).to.be.false
|
||||
|
||||
const promise = contactContext.resolveWhenUserMessagesProcessingCompletes()
|
||||
await contactContext.sync()
|
||||
|
||||
Reference in New Issue
Block a user