12 changed files with 4 additions and 1617 deletions
@ -1,69 +0,0 @@
@@ -1,69 +0,0 @@
|
||||
import { Arg, Substitute, SubstituteOf } from "@fluffy-spoon/substitute"; |
||||
|
||||
import { ApiService } from "@/jslib/common/src/abstractions/api.service"; |
||||
import { CryptoService } from "@/jslib/common/src/abstractions/crypto.service"; |
||||
import { FileUploadService } from "@/jslib/common/src/abstractions/fileUpload.service"; |
||||
import { I18nService } from "@/jslib/common/src/abstractions/i18n.service"; |
||||
import { LogService } from "@/jslib/common/src/abstractions/log.service"; |
||||
import { SearchService } from "@/jslib/common/src/abstractions/search.service"; |
||||
import { SettingsService } from "@/jslib/common/src/abstractions/settings.service"; |
||||
import { StateService } from "@/jslib/common/src/abstractions/state.service"; |
||||
import { Utils } from "@/jslib/common/src/misc/utils"; |
||||
import { Cipher } from "@/jslib/common/src/models/domain/cipher"; |
||||
import { EncArrayBuffer } from "@/jslib/common/src/models/domain/encArrayBuffer"; |
||||
import { EncString } from "@/jslib/common/src/models/domain/encString"; |
||||
import { SymmetricCryptoKey } from "@/jslib/common/src/models/domain/symmetricCryptoKey"; |
||||
import { CipherService } from "@/jslib/common/src/services/cipher.service"; |
||||
|
||||
const ENCRYPTED_TEXT = "This data has been encrypted"; |
||||
const ENCRYPTED_BYTES = new EncArrayBuffer(Utils.fromUtf8ToArray(ENCRYPTED_TEXT).buffer); |
||||
|
||||
describe("Cipher Service", () => { |
||||
let cryptoService: SubstituteOf<CryptoService>; |
||||
let stateService: SubstituteOf<StateService>; |
||||
let settingsService: SubstituteOf<SettingsService>; |
||||
let apiService: SubstituteOf<ApiService>; |
||||
let fileUploadService: SubstituteOf<FileUploadService>; |
||||
let i18nService: SubstituteOf<I18nService>; |
||||
let searchService: SubstituteOf<SearchService>; |
||||
let logService: SubstituteOf<LogService>; |
||||
|
||||
let cipherService: CipherService; |
||||
|
||||
beforeEach(() => { |
||||
cryptoService = Substitute.for<CryptoService>(); |
||||
stateService = Substitute.for<StateService>(); |
||||
settingsService = Substitute.for<SettingsService>(); |
||||
apiService = Substitute.for<ApiService>(); |
||||
fileUploadService = Substitute.for<FileUploadService>(); |
||||
i18nService = Substitute.for<I18nService>(); |
||||
searchService = Substitute.for<SearchService>(); |
||||
logService = Substitute.for<LogService>(); |
||||
|
||||
cryptoService.encryptToBytes(Arg.any(), Arg.any()).resolves(ENCRYPTED_BYTES); |
||||
cryptoService.encrypt(Arg.any(), Arg.any()).resolves(new EncString(ENCRYPTED_TEXT)); |
||||
|
||||
cipherService = new CipherService( |
||||
cryptoService, |
||||
settingsService, |
||||
apiService, |
||||
fileUploadService, |
||||
i18nService, |
||||
() => searchService, |
||||
logService, |
||||
stateService, |
||||
); |
||||
}); |
||||
|
||||
it("attachments upload encrypted file contents", async () => { |
||||
const fileName = "filename"; |
||||
const fileData = new Uint8Array(10).buffer; |
||||
cryptoService.getOrgKey(Arg.any()).resolves(new SymmetricCryptoKey(new Uint8Array(32).buffer)); |
||||
|
||||
await cipherService.saveAttachmentRawWithServer(new Cipher(), fileName, fileData); |
||||
|
||||
fileUploadService |
||||
.received(1) |
||||
.uploadCipherAttachment(Arg.any(), Arg.any(), new EncString(ENCRYPTED_TEXT), ENCRYPTED_BYTES); |
||||
}); |
||||
}); |
||||
@ -1,79 +0,0 @@
@@ -1,79 +0,0 @@
|
||||
import { CipherType } from "../enums/cipherType"; |
||||
import { UriMatchType } from "../enums/uriMatchType"; |
||||
import { CipherData } from "../models/data/cipherData"; |
||||
import { Cipher } from "../models/domain/cipher"; |
||||
import { Field } from "../models/domain/field"; |
||||
import { SymmetricCryptoKey } from "../models/domain/symmetricCryptoKey"; |
||||
import { CipherView } from "../models/view/cipherView"; |
||||
import { FieldView } from "../models/view/fieldView"; |
||||
|
||||
export abstract class CipherService { |
||||
clearCache: (userId?: string) => Promise<void>; |
||||
encrypt: ( |
||||
model: CipherView, |
||||
key?: SymmetricCryptoKey, |
||||
originalCipher?: Cipher, |
||||
) => Promise<Cipher>; |
||||
encryptFields: (fieldsModel: FieldView[], key: SymmetricCryptoKey) => Promise<Field[]>; |
||||
encryptField: (fieldModel: FieldView, key: SymmetricCryptoKey) => Promise<Field>; |
||||
get: (id: string) => Promise<Cipher>; |
||||
getAll: () => Promise<Cipher[]>; |
||||
getAllDecrypted: () => Promise<CipherView[]>; |
||||
getAllDecryptedForGrouping: (groupingId: string, folder?: boolean) => Promise<CipherView[]>; |
||||
getAllDecryptedForUrl: ( |
||||
url: string, |
||||
includeOtherTypes?: CipherType[], |
||||
defaultMatch?: UriMatchType, |
||||
) => Promise<CipherView[]>; |
||||
getAllFromApiForOrganization: (organizationId: string) => Promise<CipherView[]>; |
||||
getLastUsedForUrl: (url: string, autofillOnPageLoad: boolean) => Promise<CipherView>; |
||||
getLastLaunchedForUrl: (url: string, autofillOnPageLoad: boolean) => Promise<CipherView>; |
||||
getNextCipherForUrl: (url: string) => Promise<CipherView>; |
||||
updateLastUsedIndexForUrl: (url: string) => void; |
||||
updateLastUsedDate: (id: string) => Promise<void>; |
||||
updateLastLaunchedDate: (id: string) => Promise<void>; |
||||
saveNeverDomain: (domain: string) => Promise<void>; |
||||
saveWithServer: (cipher: Cipher) => Promise<any>; |
||||
shareWithServer: ( |
||||
cipher: CipherView, |
||||
organizationId: string, |
||||
collectionIds: string[], |
||||
) => Promise<any>; |
||||
shareManyWithServer: ( |
||||
ciphers: CipherView[], |
||||
organizationId: string, |
||||
collectionIds: string[], |
||||
) => Promise<any>; |
||||
saveAttachmentWithServer: ( |
||||
cipher: Cipher, |
||||
unencryptedFile: any, |
||||
admin?: boolean, |
||||
) => Promise<Cipher>; |
||||
saveAttachmentRawWithServer: ( |
||||
cipher: Cipher, |
||||
filename: string, |
||||
data: ArrayBuffer, |
||||
admin?: boolean, |
||||
) => Promise<Cipher>; |
||||
saveCollectionsWithServer: (cipher: Cipher) => Promise<any>; |
||||
upsert: (cipher: CipherData | CipherData[]) => Promise<any>; |
||||
replace: (ciphers: { [id: string]: CipherData }) => Promise<any>; |
||||
clear: (userId: string) => Promise<any>; |
||||
moveManyWithServer: (ids: string[], folderId: string) => Promise<any>; |
||||
delete: (id: string | string[]) => Promise<any>; |
||||
deleteWithServer: (id: string) => Promise<any>; |
||||
deleteManyWithServer: (ids: string[]) => Promise<any>; |
||||
deleteAttachment: (id: string, attachmentId: string) => Promise<void>; |
||||
deleteAttachmentWithServer: (id: string, attachmentId: string) => Promise<void>; |
||||
sortCiphersByLastUsed: (a: any, b: any) => number; |
||||
sortCiphersByLastUsedThenName: (a: any, b: any) => number; |
||||
getLocaleSortingFunction: () => (a: CipherView, b: CipherView) => number; |
||||
softDelete: (id: string | string[]) => Promise<any>; |
||||
softDeleteWithServer: (id: string) => Promise<any>; |
||||
softDeleteManyWithServer: (ids: string[]) => Promise<any>; |
||||
restore: ( |
||||
cipher: { id: string; revisionDate: string } | { id: string; revisionDate: string }[], |
||||
) => Promise<any>; |
||||
restoreWithServer: (id: string) => Promise<any>; |
||||
restoreManyWithServer: (ids: string[]) => Promise<any>; |
||||
} |
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue