1 import { ADDRESS_FLAGS, ADDRESS_TYPE, KEY_FLAG } from '@proton/shared/lib/constants';
2 import { hasBit } from '@proton/shared/lib/helpers/bitset';
3 import type { Address } from '@proton/shared/lib/interfaces';
5 import { getDefaultKeyFlags } from '../../lib/keys/keyFlags';
7 describe('getDefaultKeyFlags', () => {
8 it('default key flags should be not obsolete and not compromised', () => {
9 const defaultFlags = getDefaultKeyFlags(undefined);
10 expect(hasBit(defaultFlags, KEY_FLAG.FLAG_NOT_OBSOLETE)).toBe(true);
11 expect(hasBit(defaultFlags, KEY_FLAG.FLAG_NOT_COMPROMISED)).toBe(true);
14 it('should set external flags for external address', () => {
15 const defaultFlags = getDefaultKeyFlags({ Type: ADDRESS_TYPE.TYPE_EXTERNAL } as Address);
16 expect(hasBit(defaultFlags, KEY_FLAG.FLAG_NOT_OBSOLETE)).toBe(true);
17 expect(hasBit(defaultFlags, KEY_FLAG.FLAG_NOT_COMPROMISED)).toBe(true);
18 expect(hasBit(defaultFlags, KEY_FLAG.FLAG_EMAIL_NO_ENCRYPT)).toBe(true);
21 it('should set email no encrypt flag for address with disable e2ee flag', () => {
22 const defaultFlags = getDefaultKeyFlags({ Flags: ADDRESS_FLAGS.FLAG_DISABLE_E2EE } as Address);
23 expect(hasBit(defaultFlags, KEY_FLAG.FLAG_NOT_OBSOLETE)).toBe(true);
24 expect(hasBit(defaultFlags, KEY_FLAG.FLAG_NOT_COMPROMISED)).toBe(true);
25 expect(hasBit(defaultFlags, KEY_FLAG.FLAG_EMAIL_NO_ENCRYPT)).toBe(true);
28 it('should set email no sign flag for address with disable expected signed flag', () => {
29 const defaultFlags = getDefaultKeyFlags({ Flags: ADDRESS_FLAGS.FLAG_DISABLE_EXPECTED_SIGNED } as Address);
30 expect(hasBit(defaultFlags, KEY_FLAG.FLAG_NOT_OBSOLETE)).toBe(true);
31 expect(hasBit(defaultFlags, KEY_FLAG.FLAG_NOT_COMPROMISED)).toBe(true);
32 expect(hasBit(defaultFlags, KEY_FLAG.FLAG_EMAIL_NO_SIGN)).toBe(true);