1 import { MAX_CHARS_API } from '../../lib/calendar/constants';
8 } from '../../lib/calendar/helper';
10 describe('getSupportedUID', () => {
11 it('should retain short UIDs', () => {
12 const uid = 'stmyce9lb3ef@domain.com';
13 expect(getSupportedUID(uid)).toEqual(uid);
16 it('should crop long UIDs', () => {
18 '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890@domaine.com';
19 expect(getSupportedUID(uid)).toEqual(
20 '23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890@domaine.com'
25 describe('getVeventHashUID', () => {
26 const binaryString = 'some random words for the test';
27 const shortUid = 'stmyce9lb3ef@domain.com';
29 'Cm5XpErjCp4syBD1zI0whscVHuQklN3tvXxxXpaewdBGEpOFTcMCqM8WDLLYDM6kuXAqdTqL1y98SRrf5thkyceT01boWtEeCkrep75kRiKnHE5YnBKYvEFmcWKJ0q0eeNWIN4OLZ8yJnSDdC8DT9CndSxOnnPC47VWjQHu0psXB25lZuCt4EWsWAtgmCPWe1Wa0AIL0y8rlPn0qbB05u3WuyOst8XYkJNWz6gYx@domaine.com';
31 it('should generate new UIDs', async () => {
32 expect(await generateVeventHashUID(binaryString)).toEqual('sha1-uid-b8ae0238d0011a4961a2d259e33bd383672b9229');
35 it('should generate the same UID with or without legacy format', async () => {
36 expect(await generateVeventHashUID(binaryString)).toEqual(await generateVeventHashUID(binaryString, '', true));
39 it('should keep short UIDs before the hash', async () => {
40 expect(await generateVeventHashUID(binaryString, shortUid)).toEqual(
41 'original-uid-stmyce9lb3ef@domain.com-sha1-uid-b8ae0238d0011a4961a2d259e33bd383672b9229'
45 it('should crop long UIDs before the hash', async () => {
46 const hashUID = await generateVeventHashUID(binaryString, longUid);
47 expect(hashUID.length).toEqual(MAX_CHARS_API.UID);
48 expect(hashUID).toEqual(
49 'original-uid-vEFmcWKJ0q0eeNWIN4OLZ8yJnSDdC8DT9CndSxOnnPC47VWjQHu0psXB25lZuCt4EWsWAtgmCPWe1Wa0AIL0y8rlPn0qbB05u3WuyOst8XYkJNWz6gYx@domaine.com-sha1-uid-b8ae0238d0011a4961a2d259e33bd383672b9229'
53 it('should keep short UIDs after the hash when using legacy format', async () => {
54 expect(await generateVeventHashUID(binaryString, shortUid, true)).toEqual(
55 'sha1-uid-b8ae0238d0011a4961a2d259e33bd383672b9229-original-uid-stmyce9lb3ef@domain.com'
59 it('should crop long UIDs after the hash when using legacy format', async () => {
60 const hashUID = await generateVeventHashUID(binaryString, longUid, true);
61 expect(hashUID.length).toEqual(MAX_CHARS_API.UID);
62 expect(hashUID).toEqual(
63 'sha1-uid-b8ae0238d0011a4961a2d259e33bd383672b9229-original-uid-vEFmcWKJ0q0eeNWIN4OLZ8yJnSDdC8DT9CndSxOnnPC47VWjQHu0psXB25lZuCt4EWsWAtgmCPWe1Wa0AIL0y8rlPn0qbB05u3WuyOst8XYkJNWz6gYx@domaine.com'
68 describe('getOriginalUID', () => {
69 const binaryString = 'some random words for the test';
70 const shortUid = 'stmyce9lb3ef@domain.com';
72 'Cm5XpErjCp4syBD1zI0whscVHuQklN3tvXxxXpaewdBGEpOFTcMCqM8WDLLYDM6kuXAqdTqL1y98SRrf5thkyceT01boWtEeCkrep75kRiKnHE5YnBKYvEFmcWKJ0q0eeNWIN4OLZ8yJnSDdC8DT9CndSxOnnPC47VWjQHu0psXB25lZuCt4EWsWAtgmCPWe1Wa0AIL0y8rlPn0qbB05u3WuyOst8XYkJNWz6gYx@domaine.com';
73 const longUidLength = longUid.length;
75 it('should return the empty string if passed nothing', () => {
76 expect(getOriginalUID()).toEqual('');
79 it('should retrieve the original short UIDs after the hash operation (legacy or not)', async () => {
80 expect(getOriginalUID(await generateVeventHashUID(binaryString, shortUid))).toEqual(shortUid);
81 expect(getOriginalUID(await generateVeventHashUID(binaryString, shortUid, true))).toEqual(shortUid);
84 it('should retrieve no UID after the hash operation if there was none before', async () => {
85 expect(getOriginalUID(await generateVeventHashUID(binaryString))).toEqual('');
88 it('should retrieve a cropped version of long UIDs after the hash operation (legacy or not)', async () => {
89 expect(getOriginalUID(await generateVeventHashUID(binaryString, longUid))).toEqual(
90 longUid.substring(longUidLength - 128, longUidLength)
92 expect(getOriginalUID(await generateVeventHashUID(binaryString, longUid, true))).toEqual(
93 longUid.substring(longUidLength - 128, longUidLength)
97 it('should return the uid if it is not a hash', async () => {
98 expect(getOriginalUID('random-uid')).toEqual('random-uid');
102 describe('getHasLegacyHashUID', () => {
103 const binaryString = 'some random words for the test';
104 const shortUid = 'stmyce9lb3ef@domain.com';
106 'Cm5XpErjCp4syBD1zI0whscVHuQklN3tvXxxXpaewdBGEpOFTcMCqM8WDLLYDM6kuXAqdTqL1y98SRrf5thkyceT01boWtEeCkrep75kRiKnHE5YnBKYvEFmcWKJ0q0eeNWIN4OLZ8yJnSDdC8DT9CndSxOnnPC47VWjQHu0psXB25lZuCt4EWsWAtgmCPWe1Wa0AIL0y8rlPn0qbB05u3WuyOst8XYkJNWz6gYx@domaine.com';
108 it('should return false if the empty string is passed', () => {
109 expect(getHasLegacyHashUID('')).toEqual(false);
112 it('should return false if a new hash uid is passed', async () => {
113 expect(getHasLegacyHashUID(await generateVeventHashUID(binaryString, shortUid))).toEqual(false);
114 expect(getHasLegacyHashUID(await generateVeventHashUID(binaryString, longUid))).toEqual(false);
117 it('should return true if a legacy uid is passed', async () => {
118 expect(getHasLegacyHashUID(await generateVeventHashUID(binaryString, shortUid, true))).toEqual(true);
119 expect(getHasLegacyHashUID(await generateVeventHashUID(binaryString, longUid, true))).toEqual(true);
123 describe('getNaiveDomainFromUID', () => {
124 it('should return the domain when the uid has the expected format', () => {
126 'wETnJu3LPvN66KXRDJMYFxmq77Ys@proton.me',
127 'qkbndaqtgkuj4nfr21adr86etk@google.com',
128 '2022-01-04GB-SCT1027lieuregion@www.officeholidays.com',
130 const expected = ['proton.me', 'google.com', 'www.officeholidays.com'];
132 expect(uids.map((uid) => getNaiveDomainFromUID(uid))).toEqual(expected);
135 it("should return the domain when the uid has multiple @'s", () => {
136 const uids = ['9O@8@8yk@google.com'];
137 const expected = ['google.com'];
139 expect(uids.map((uid) => getNaiveDomainFromUID(uid))).toEqual(expected);
142 it('should return an empty string when the uid has a Proton legacy format', () => {
143 expect(getNaiveDomainFromUID('proton-calendar-350095ea-4368-26f0-4fc9-60a56015b02e')).toEqual('');
146 it('should return an empty string for the domain', () => {
147 expect(getNaiveDomainFromUID('')).toEqual('');
148 expect(getNaiveDomainFromUID('something')).toEqual('');
149 expect(getNaiveDomainFromUID('something@')).toEqual('');