1 import { VERIFICATION_STATUS } from '@proton/srp/lib/constants';
3 import type { SignatureIssues } from '../store';
4 import { hasValidAnonymousSignature } from './hasValidAnonymousSignature';
6 describe('hasValidAnonymousSignature', () => {
9 jest.spyOn(console, 'warn').mockImplementation(() => {});
16 it('should return true when thumbnail and blocks are NOT signed and others are valid', () => {
17 const signatureIssues: SignatureIssues = {
18 manifest: VERIFICATION_STATUS.SIGNED_AND_VALID,
19 thumbnail: VERIFICATION_STATUS.NOT_SIGNED,
20 blocks: VERIFICATION_STATUS.NOT_SIGNED,
21 passphrase: VERIFICATION_STATUS.SIGNED_AND_VALID,
24 expect(hasValidAnonymousSignature(signatureIssues)).toBe(true);
27 it('should return false when thumbnail is signed', () => {
28 const signatureIssues: SignatureIssues = {
29 manifest: VERIFICATION_STATUS.SIGNED_AND_VALID,
30 thumbnail: VERIFICATION_STATUS.SIGNED_AND_VALID,
31 blocks: VERIFICATION_STATUS.NOT_SIGNED,
32 passphrase: VERIFICATION_STATUS.SIGNED_AND_VALID,
35 expect(hasValidAnonymousSignature(signatureIssues)).toBe(false);
36 expect(console.warn).toHaveBeenCalledWith(
37 'thumbnail signature should not be signed in case of anonymous upload'
41 it('should return false when blocks are signed', () => {
42 const signatureIssues: SignatureIssues = {
43 manifest: VERIFICATION_STATUS.SIGNED_AND_VALID,
44 thumbnail: VERIFICATION_STATUS.NOT_SIGNED,
45 blocks: VERIFICATION_STATUS.SIGNED_AND_VALID,
46 passphrase: VERIFICATION_STATUS.SIGNED_AND_VALID,
49 expect(hasValidAnonymousSignature(signatureIssues)).toBe(false);
50 expect(console.warn).toHaveBeenCalledWith('blocks signature should not be signed in case of anonymous upload');
53 it('should return false when non-thumbnail/blocks signatures are invalid', () => {
54 const signatureIssues: SignatureIssues = {
55 manifest: VERIFICATION_STATUS.SIGNED_AND_INVALID,
56 thumbnail: VERIFICATION_STATUS.NOT_SIGNED,
57 blocks: VERIFICATION_STATUS.NOT_SIGNED,
58 passphrase: VERIFICATION_STATUS.SIGNED_AND_VALID,
61 expect(hasValidAnonymousSignature(signatureIssues)).toBe(false);
64 it('should return false when non-thumbnail/blocks signatures are not signed', () => {
65 const signatureIssues: SignatureIssues = {
66 manifest: VERIFICATION_STATUS.NOT_SIGNED,
67 thumbnail: VERIFICATION_STATUS.NOT_SIGNED,
68 blocks: VERIFICATION_STATUS.NOT_SIGNED,
69 passphrase: VERIFICATION_STATUS.SIGNED_AND_VALID,
72 expect(hasValidAnonymousSignature(signatureIssues)).toBe(false);
75 it('should handle empty signature issues object', () => {
76 const signatureIssues: SignatureIssues = {};
78 expect(hasValidAnonymousSignature(signatureIssues)).toBe(true);