internal: incomplete vault systems behind feature flag (#2340)
This commit is contained in:
@@ -9,10 +9,12 @@ describe('download and decrypt', () => {
|
||||
let apiService: FilesApiInterface
|
||||
let operation: DownloadAndDecryptFileOperation
|
||||
let file: {
|
||||
uuid: string
|
||||
encryptedChunkSizes: FileContent['encryptedChunkSizes']
|
||||
encryptionHeader: FileContent['encryptionHeader']
|
||||
remoteIdentifier: FileContent['remoteIdentifier']
|
||||
key: FileContent['key']
|
||||
shared_vault_uuid: string | undefined
|
||||
}
|
||||
let crypto: PureCryptoInterface
|
||||
|
||||
@@ -26,16 +28,16 @@ describe('download and decrypt', () => {
|
||||
apiService.downloadFile = jest
|
||||
.fn()
|
||||
.mockImplementation(
|
||||
(
|
||||
_file: string,
|
||||
_chunkIndex: number,
|
||||
_apiToken: string,
|
||||
_rangeStart: number,
|
||||
onBytesReceived: (bytes: Uint8Array) => void,
|
||||
) => {
|
||||
(params: {
|
||||
_file: string
|
||||
_chunkIndex: number
|
||||
_apiToken: string
|
||||
_rangeStart: number
|
||||
onBytesReceived: (bytes: Uint8Array) => void
|
||||
}) => {
|
||||
const receiveFile = async () => {
|
||||
for (let i = 0; i < NumChunks; i++) {
|
||||
onBytesReceived(chunkOfSize(size))
|
||||
params.onBytesReceived(chunkOfSize(size))
|
||||
|
||||
await sleep(100, false)
|
||||
}
|
||||
@@ -50,7 +52,7 @@ describe('download and decrypt', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
apiService = {} as jest.Mocked<FilesApiInterface>
|
||||
apiService.createFileValetToken = jest.fn()
|
||||
apiService.createUserFileValetToken = jest.fn()
|
||||
downloadChunksOfSize(5)
|
||||
|
||||
crypto = {} as jest.Mocked<PureCryptoInterface>
|
||||
@@ -62,17 +64,19 @@ describe('download and decrypt', () => {
|
||||
crypto.xchacha20StreamDecryptorPush = jest.fn().mockReturnValue({ message: new Uint8Array([0xaa]), tag: 0 })
|
||||
|
||||
file = {
|
||||
uuid: '123',
|
||||
encryptedChunkSizes: [100_000],
|
||||
remoteIdentifier: '123',
|
||||
key: 'secret',
|
||||
encryptionHeader: 'some-header',
|
||||
shared_vault_uuid: undefined,
|
||||
}
|
||||
})
|
||||
|
||||
it('run should resolve when operation is complete', async () => {
|
||||
let receivedBytes = new Uint8Array()
|
||||
|
||||
operation = new DownloadAndDecryptFileOperation(file, crypto, apiService)
|
||||
operation = new DownloadAndDecryptFileOperation(file, crypto, apiService, 'own')
|
||||
|
||||
await operation.run(async (result) => {
|
||||
if (result) {
|
||||
@@ -87,15 +91,17 @@ describe('download and decrypt', () => {
|
||||
|
||||
it('should correctly report progress', async () => {
|
||||
file = {
|
||||
uuid: '123',
|
||||
encryptedChunkSizes: [100_000, 200_000, 200_000],
|
||||
remoteIdentifier: '123',
|
||||
key: 'secret',
|
||||
encryptionHeader: 'some-header',
|
||||
shared_vault_uuid: undefined,
|
||||
}
|
||||
|
||||
downloadChunksOfSize(100_000)
|
||||
|
||||
operation = new DownloadAndDecryptFileOperation(file, crypto, apiService)
|
||||
operation = new DownloadAndDecryptFileOperation(file, crypto, apiService, 'own')
|
||||
|
||||
const progress: FileDownloadProgress = await new Promise((resolve) => {
|
||||
// eslint-disable-next-line @typescript-eslint/require-await
|
||||
|
||||
@@ -21,6 +21,8 @@ export class DownloadAndDecryptFileOperation {
|
||||
|
||||
constructor(
|
||||
private readonly file: {
|
||||
uuid: string
|
||||
shared_vault_uuid: string | undefined
|
||||
encryptedChunkSizes: FileContent['encryptedChunkSizes']
|
||||
encryptionHeader: FileContent['encryptionHeader']
|
||||
remoteIdentifier: FileContent['remoteIdentifier']
|
||||
@@ -28,8 +30,9 @@ export class DownloadAndDecryptFileOperation {
|
||||
},
|
||||
private readonly crypto: PureCryptoInterface,
|
||||
private readonly api: FilesApiInterface,
|
||||
valetToken: string,
|
||||
) {
|
||||
this.downloader = new FileDownloader(this.file, this.api)
|
||||
this.downloader = new FileDownloader(this.file, this.api, valetToken)
|
||||
}
|
||||
|
||||
private createDecryptor(): FileDecryptor {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { FileUploadResult } from '../Types/FileUploadResult'
|
||||
import { FileUploader } from '../UseCase/FileUploader'
|
||||
import { PureCryptoInterface } from '@standardnotes/sncrypto-common'
|
||||
import { FileEncryptor } from '../UseCase/FileEncryptor'
|
||||
import { FileContent } from '@standardnotes/models'
|
||||
import { FileContent, VaultListingInterface } from '@standardnotes/models'
|
||||
import { FilesApiInterface } from '../Api/FilesApiInterface'
|
||||
|
||||
export class EncryptAndUploadFileOperation {
|
||||
@@ -22,9 +22,10 @@ export class EncryptAndUploadFileOperation {
|
||||
key: FileContent['key']
|
||||
remoteIdentifier: FileContent['remoteIdentifier']
|
||||
},
|
||||
private apiToken: string,
|
||||
private valetToken: string,
|
||||
private crypto: PureCryptoInterface,
|
||||
private api: FilesApiInterface,
|
||||
public readonly vault?: VaultListingInterface,
|
||||
) {
|
||||
this.encryptor = new FileEncryptor(file, this.crypto)
|
||||
this.uploader = new FileUploader(this.api)
|
||||
@@ -32,8 +33,8 @@ export class EncryptAndUploadFileOperation {
|
||||
this.encryptionHeader = this.encryptor.initializeHeader()
|
||||
}
|
||||
|
||||
public getApiToken(): string {
|
||||
return this.apiToken
|
||||
public getValetToken(): string {
|
||||
return this.valetToken
|
||||
}
|
||||
|
||||
public getProgress(): FileUploadProgress {
|
||||
@@ -79,7 +80,12 @@ export class EncryptAndUploadFileOperation {
|
||||
}
|
||||
|
||||
private async uploadBytes(encryptedBytes: Uint8Array, chunkId: number): Promise<boolean> {
|
||||
const success = await this.uploader.uploadBytes(encryptedBytes, chunkId, this.apiToken)
|
||||
const success = await this.uploader.uploadBytes(
|
||||
encryptedBytes,
|
||||
this.vault && this.vault.sharing ? 'shared-vault' : 'user',
|
||||
chunkId,
|
||||
this.valetToken,
|
||||
)
|
||||
|
||||
return success
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user