refactor: root key manager (#2344)
This commit is contained in:
@@ -17,9 +17,9 @@ import { GetRevision } from './GetRevision'
|
||||
|
||||
describe('GetRevision', () => {
|
||||
let revisionManager: RevisionClientInterface
|
||||
let protocolService: EncryptionProviderInterface
|
||||
let encryptionService: EncryptionProviderInterface
|
||||
|
||||
const createUseCase = () => new GetRevision(revisionManager, protocolService)
|
||||
const createUseCase = () => new GetRevision(revisionManager, encryptionService)
|
||||
|
||||
beforeEach(() => {
|
||||
revisionManager = {} as jest.Mocked<RevisionClientInterface>
|
||||
@@ -35,13 +35,13 @@ describe('GetRevision', () => {
|
||||
updated_at: '2021-01-01T00:00:00.000Z'
|
||||
} as jest.Mocked<Revision>)
|
||||
|
||||
protocolService = {} as jest.Mocked<EncryptionProviderInterface>
|
||||
protocolService.getEmbeddedPayloadAuthenticatedData = jest.fn().mockReturnValue({ u: '00000000-0000-0000-0000-000000000000' })
|
||||
encryptionService = {} as jest.Mocked<EncryptionProviderInterface>
|
||||
encryptionService.getEmbeddedPayloadAuthenticatedData = jest.fn().mockReturnValue({ u: '00000000-0000-0000-0000-000000000000' })
|
||||
const encryptedPayload = {
|
||||
content: 'foobar',
|
||||
} as jest.Mocked<EncryptedPayloadInterface>
|
||||
encryptedPayload.copy = jest.fn().mockReturnValue(encryptedPayload)
|
||||
protocolService.decryptSplitSingle = jest.fn().mockReturnValue(encryptedPayload)
|
||||
encryptionService.decryptSplitSingle = jest.fn().mockReturnValue(encryptedPayload)
|
||||
|
||||
isRemotePayloadAllowed.mockImplementation(() => true)
|
||||
})
|
||||
@@ -59,7 +59,7 @@ describe('GetRevision', () => {
|
||||
})
|
||||
|
||||
it('it should get a revision without uuid from embedded params', async () => {
|
||||
protocolService.getEmbeddedPayloadAuthenticatedData = jest.fn().mockReturnValue({ u: undefined })
|
||||
encryptionService.getEmbeddedPayloadAuthenticatedData = jest.fn().mockReturnValue({ u: undefined })
|
||||
|
||||
const useCase = createUseCase()
|
||||
|
||||
@@ -73,7 +73,7 @@ describe('GetRevision', () => {
|
||||
})
|
||||
|
||||
it('it should get a revision without embedded params', async () => {
|
||||
protocolService.getEmbeddedPayloadAuthenticatedData = jest.fn().mockReturnValue(undefined)
|
||||
encryptionService.getEmbeddedPayloadAuthenticatedData = jest.fn().mockReturnValue(undefined)
|
||||
|
||||
const useCase = createUseCase()
|
||||
|
||||
@@ -130,7 +130,7 @@ describe('GetRevision', () => {
|
||||
errorDecrypting: true,
|
||||
} as jest.Mocked<EncryptedPayloadInterface>
|
||||
encryptedPayload.copy = jest.fn().mockReturnValue(encryptedPayload)
|
||||
protocolService.decryptSplitSingle = jest.fn().mockReturnValue(encryptedPayload)
|
||||
encryptionService.decryptSplitSingle = jest.fn().mockReturnValue(encryptedPayload)
|
||||
|
||||
const useCase = createUseCase()
|
||||
|
||||
|
||||
@@ -15,7 +15,10 @@ import { EncryptionProviderInterface } from '@standardnotes/encryption'
|
||||
import { GetRevisionDTO } from './GetRevisionDTO'
|
||||
|
||||
export class GetRevision implements UseCaseInterface<HistoryEntry> {
|
||||
constructor(private revisionManager: RevisionClientInterface, private protocolService: EncryptionProviderInterface) {}
|
||||
constructor(
|
||||
private revisionManager: RevisionClientInterface,
|
||||
private encryptionService: EncryptionProviderInterface,
|
||||
) {}
|
||||
|
||||
async execute(dto: GetRevisionDTO): Promise<Result<HistoryEntry>> {
|
||||
const itemUuidOrError = Uuid.create(dto.itemUuid)
|
||||
@@ -63,7 +66,7 @@ export class GetRevision implements UseCaseInterface<HistoryEntry> {
|
||||
* these olders revisions (which have not been mutated after copy) with the source item's
|
||||
* uuid.
|
||||
*/
|
||||
const embeddedParams = this.protocolService.getEmbeddedPayloadAuthenticatedData(serverPayload)
|
||||
const embeddedParams = this.encryptionService.getEmbeddedPayloadAuthenticatedData(serverPayload)
|
||||
const sourceItemUuid = embeddedParams?.u as string | undefined
|
||||
|
||||
const payload = serverPayload.copy({
|
||||
@@ -76,7 +79,7 @@ export class GetRevision implements UseCaseInterface<HistoryEntry> {
|
||||
|
||||
const encryptedPayload = new EncryptedPayload(payload)
|
||||
|
||||
const decryptedPayload = await this.protocolService.decryptSplitSingle<NoteContent>({
|
||||
const decryptedPayload = await this.encryptionService.decryptSplitSingle<NoteContent>({
|
||||
usesItemsKeyWithKeyLookup: { items: [encryptedPayload] },
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user