@futdevpro/fsm-dynamo 1.14.20 → 1.14.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/build/_modules/crypto/_collections/crypto.util.d.ts.map +1 -1
  2. package/build/_modules/crypto/_collections/crypto.util.edge.spec.d.ts +2 -0
  3. package/build/_modules/crypto/_collections/crypto.util.edge.spec.d.ts.map +1 -0
  4. package/build/_modules/crypto/_collections/crypto.util.edge.spec.js +551 -0
  5. package/build/_modules/crypto/_collections/crypto.util.edge.spec.js.map +1 -0
  6. package/build/_modules/crypto/_collections/crypto.util.extra.spec.d.ts +2 -0
  7. package/build/_modules/crypto/_collections/crypto.util.extra.spec.d.ts.map +1 -0
  8. package/build/_modules/crypto/_collections/crypto.util.extra.spec.js +555 -0
  9. package/build/_modules/crypto/_collections/crypto.util.extra.spec.js.map +1 -0
  10. package/build/_modules/crypto/_collections/crypto.util.js +33 -3
  11. package/build/_modules/crypto/_collections/crypto.util.js.map +1 -1
  12. package/build/_modules/crypto/_collections/crypto.util.simple.spec.d.ts +2 -0
  13. package/build/_modules/crypto/_collections/crypto.util.simple.spec.d.ts.map +1 -0
  14. package/build/_modules/crypto/_collections/crypto.util.simple.spec.js +429 -0
  15. package/build/_modules/crypto/_collections/crypto.util.simple.spec.js.map +1 -0
  16. package/futdevpro-fsm-dynamo-01.14.21.tgz +0 -0
  17. package/package.json +2 -2
  18. package/src/_modules/crypto/_collections/crypto.util.edge.spec.ts +606 -0
  19. package/src/_modules/crypto/_collections/crypto.util.extra.spec.ts +643 -0
  20. package/src/_modules/crypto/_collections/crypto.util.simple.spec.ts +513 -0
  21. package/src/_modules/crypto/_collections/crypto.util.ts +81 -48
  22. package/build/_modules/crypto/_collections/crypto.util.spec.d.ts +0 -2
  23. package/build/_modules/crypto/_collections/crypto.util.spec.d.ts.map +0 -1
  24. package/build/_modules/crypto/_collections/crypto.util.spec.js +0 -1180
  25. package/build/_modules/crypto/_collections/crypto.util.spec.js.map +0 -1
  26. package/futdevpro-fsm-dynamo-01.14.20.tgz +0 -0
  27. package/src/_modules/crypto/_collections/crypto.util.spec.ts +0 -1370
@@ -0,0 +1,513 @@
1
+ import { DyFM_Crypto } from './crypto.util';
2
+
3
+ describe('| DyFM_Crypto basic tests', () => {
4
+ const testKey = 'test-secret-key-123';
5
+ const testData = { id: 1, name: 'test' };
6
+
7
+ describe('| encrypt', () => {
8
+ it('| should successfully encrypt data', () => {
9
+ const encrypted = DyFM_Crypto.encrypt(testData, testKey);
10
+
11
+ expect(encrypted).toBeDefined();
12
+ expect(typeof encrypted).toBe('string');
13
+ expect(encrypted).toMatch(/^[A-Za-z0-9\-_]+$/);
14
+ });
15
+
16
+ it('| should encrypt different data with different results', () => {
17
+ const data1 = { id: 1 };
18
+ const data2 = { id: 2 };
19
+
20
+ const encrypted1 = DyFM_Crypto.encrypt(data1, testKey);
21
+ const encrypted2 = DyFM_Crypto.encrypt(data2, testKey);
22
+
23
+ expect(encrypted1).not.toEqual(encrypted2);
24
+ });
25
+
26
+ it('| should throw DyFM_Error when encryption fails', () => {
27
+ // @ts-ignore - Testing invalid input
28
+ expect(() => DyFM_Crypto.encrypt(undefined, testKey)).toThrow();
29
+ });
30
+
31
+ it('| should handle complex objects', () => {
32
+ const complexData = {
33
+ id: 1,
34
+ name: 'test',
35
+ nested: {
36
+ value: 'nested-value',
37
+ array: [1, 2, 3]
38
+ }
39
+ };
40
+
41
+ const encrypted = DyFM_Crypto.encrypt(complexData, testKey);
42
+ const decrypted = DyFM_Crypto.decrypt(encrypted, testKey);
43
+
44
+ expect(decrypted).toEqual(complexData);
45
+ });
46
+
47
+ it('| should get the same result with the same input', () => {
48
+ const complexData = {
49
+ id: 2,
50
+ name: 'test',
51
+ nested: {
52
+ value: 'nested-value',
53
+ array: [1, 2, 3]
54
+ }
55
+ };
56
+ const expectedResult = JSON.stringify(complexData);
57
+
58
+ const encrypted = DyFM_Crypto.encrypt(complexData, testKey);
59
+ const decrypted = DyFM_Crypto.decrypt(encrypted, testKey);
60
+
61
+ const result = JSON.stringify(decrypted);
62
+ expect(result).toBe(expectedResult);
63
+ });
64
+
65
+ it('| should not effect the original object', () => {
66
+ const complexData = {
67
+ id: 1,
68
+ name: 'test',
69
+ nested: { value: 'nested-value', array: [1, 2, 3] }
70
+ };
71
+ const originalData = JSON.stringify(complexData);
72
+
73
+ const encrypted = DyFM_Crypto.encrypt(complexData, testKey);
74
+ const decrypted = DyFM_Crypto.decrypt(encrypted, testKey);
75
+
76
+ const result = JSON.stringify(decrypted);
77
+ expect(result).toBe(originalData);
78
+ });
79
+
80
+ it('| should handle arrays', () => {
81
+ const arrayData = [1, 'test', { nested: true }];
82
+ const encrypted = DyFM_Crypto.encrypt(arrayData, testKey);
83
+ const decrypted = DyFM_Crypto.decrypt(encrypted, testKey);
84
+
85
+ expect(decrypted).toEqual(arrayData);
86
+ });
87
+
88
+ it('| should handle primitive values', () => {
89
+ const stringData = 'test string';
90
+ const numberData = 42;
91
+ const booleanData = true;
92
+
93
+ const encryptedString = DyFM_Crypto.encrypt(stringData, testKey);
94
+ const encryptedNumber = DyFM_Crypto.encrypt(numberData, testKey);
95
+ const encryptedBoolean = DyFM_Crypto.encrypt(booleanData, testKey);
96
+
97
+ expect(DyFM_Crypto.decrypt(encryptedString, testKey)).toBe(stringData);
98
+ expect(DyFM_Crypto.decrypt(encryptedNumber, testKey)).toBe(numberData);
99
+ expect(DyFM_Crypto.decrypt(encryptedBoolean, testKey)).toBe(booleanData);
100
+ });
101
+ });
102
+
103
+ describe('| decrypt', () => {
104
+ it('| should successfully decrypt encrypted data', () => {
105
+ const encrypted = DyFM_Crypto.encrypt(testData, testKey);
106
+ const decrypted = DyFM_Crypto.decrypt(encrypted, testKey);
107
+
108
+ expect(decrypted).toEqual(testData);
109
+ });
110
+
111
+ it('| should throw DyFM_Error when decryption fails', () => {
112
+ expect(() => DyFM_Crypto.decrypt('invalid-encrypted-data', testKey)).toThrow();
113
+ });
114
+
115
+ it('| should throw DyFM_Error when using wrong key', () => {
116
+ const encrypted = DyFM_Crypto.encrypt(testData, testKey);
117
+ expect(() => DyFM_Crypto.decrypt(encrypted, 'wrong-key')).toThrow();
118
+ });
119
+
120
+ it('| should throw DyFM_Error when encrypted data is modified', () => {
121
+ const encrypted = DyFM_Crypto.encrypt(testData, testKey);
122
+ const modified = encrypted.slice(0, -1) + 'A';
123
+ expect(() => DyFM_Crypto.decrypt(modified, testKey)).toThrow();
124
+ });
125
+ });
126
+
127
+ describe('| URL-safe encryption', () => {
128
+ it('| should produce URL-safe strings', () => {
129
+ const encrypted = DyFM_Crypto.encrypt(testData, testKey);
130
+ expect(encrypted).toMatch(/^[A-Za-z0-9\-_]+$/);
131
+ });
132
+
133
+ it('| should work in HTTP headers', () => {
134
+ const encrypted = DyFM_Crypto.encrypt(testData, testKey);
135
+ const header = `Bearer ${encrypted}`;
136
+ const extracted = header.split(' ')[1];
137
+ const decrypted = DyFM_Crypto.decrypt(extracted, testKey);
138
+ expect(decrypted).toEqual(testData);
139
+ });
140
+
141
+ it('| should work in URLs', () => {
142
+ const encrypted = DyFM_Crypto.encrypt(testData, testKey);
143
+ const url = `https://example.com/api?token=${encrypted}`;
144
+ const params = new URLSearchParams(url.split('?')[1]);
145
+ const extracted = params.get('token');
146
+ const decrypted = DyFM_Crypto.decrypt(extracted!, testKey);
147
+ expect(decrypted).toEqual(testData);
148
+ });
149
+ });
150
+
151
+ describe('| LONG-TERM STABILITY TESTS - Cross-platform compatibility', () => {
152
+ describe('| Deterministic encryption consistency', () => {
153
+ it('| should produce identical encrypted output for identical input across multiple calls', () => {
154
+ const testData = { id: 1, name: 'test', timestamp: '2024-01-01T00:00:00Z' };
155
+ const key = 'stable-test-key-123';
156
+
157
+ // Multiple encryption calls should produce identical results
158
+ const encrypted1 = DyFM_Crypto.encrypt(testData, key);
159
+ const encrypted2 = DyFM_Crypto.encrypt(testData, key);
160
+ const encrypted3 = DyFM_Crypto.encrypt(testData, key);
161
+
162
+ expect(encrypted1).toBe(encrypted2);
163
+ expect(encrypted2).toBe(encrypted3);
164
+ expect(encrypted1).toBe(encrypted3);
165
+
166
+ // All should decrypt to the same data
167
+ const decrypted1 = DyFM_Crypto.decrypt(encrypted1, key);
168
+ const decrypted2 = DyFM_Crypto.decrypt(encrypted2, key);
169
+ const decrypted3 = DyFM_Crypto.decrypt(encrypted3, key);
170
+
171
+ expect(decrypted1).toEqual(decrypted2);
172
+ expect(decrypted2).toEqual(decrypted3);
173
+ expect(decrypted1).toEqual(testData);
174
+ });
175
+
176
+ it('| should maintain consistency with different data types and structures', () => {
177
+ const testCases = [
178
+ { data: { id: 1, name: 'simple' }, key: 'key1' },
179
+ { data: 'plain string', key: 'key2' },
180
+ { data: [1, 2, 3, 'array'], key: 'key3' },
181
+ { data: { nested: { deep: { value: true } } }, key: 'key4' },
182
+ { data: { empty: {}, null: null }, key: 'key5' } // Removed undefined as it gets filtered out
183
+ ];
184
+
185
+ testCases.forEach(({ data, key }) => {
186
+ const encrypted1 = DyFM_Crypto.encrypt(data, key);
187
+ const encrypted2 = DyFM_Crypto.encrypt(data, key);
188
+ expect(encrypted1).toBe(encrypted2);
189
+
190
+ const decrypted = DyFM_Crypto.decrypt(encrypted1, key);
191
+ expect(decrypted).toEqual(data);
192
+ });
193
+ });
194
+
195
+ it('| should handle edge cases consistently', () => {
196
+ const edgeCases = [
197
+ { data: 'non-empty', key: 'non-empty-string-key' },
198
+ { data: 0, key: 'zero-number-key' },
199
+ { data: false, key: 'false-boolean-key' },
200
+ { data: { a: 0, b: false, c: 'non-empty' }, key: 'mixed-edge-key' }
201
+ ];
202
+
203
+ edgeCases.forEach(({ data, key }) => {
204
+ const encrypted1 = DyFM_Crypto.encrypt(data, key);
205
+ const encrypted2 = DyFM_Crypto.encrypt(data, key);
206
+ expect(encrypted1).toBe(encrypted2);
207
+
208
+ const decrypted = DyFM_Crypto.decrypt(encrypted1, key);
209
+ expect(decrypted).toEqual(data);
210
+ });
211
+ });
212
+ });
213
+
214
+ describe('| Cross-version compatibility simulation', () => {
215
+ it('| should handle data encrypted with different configurations consistently', () => {
216
+ const testData = { id: 1, name: 'config-test' };
217
+ const key = 'config-test-key';
218
+
219
+ // Test with default config
220
+ const defaultEncrypted = DyFM_Crypto.encrypt(testData, key);
221
+ const defaultDecrypted = DyFM_Crypto.decrypt(defaultEncrypted, key);
222
+ expect(defaultDecrypted).toEqual(testData);
223
+
224
+ // Test with custom config
225
+ const customConfig = { keyIterations: 500, keySize: 6 };
226
+ const customEncrypted = DyFM_Crypto.encrypt(testData, key, customConfig);
227
+ const customDecrypted = DyFM_Crypto.decrypt(customEncrypted, key, customConfig);
228
+ expect(customDecrypted).toEqual(testData);
229
+
230
+ // Test that different configs produce different encrypted results
231
+ expect(defaultEncrypted).not.toBe(customEncrypted);
232
+ });
233
+
234
+ it('| should maintain backward compatibility with existing encrypted data', () => {
235
+ // Simulate data that was encrypted with previous version
236
+ const legacyData = { id: 1, name: 'legacy-test', version: '1.0' };
237
+ const key = 'legacy-key';
238
+
239
+ // Encrypt with current implementation
240
+ const encrypted = DyFM_Crypto.encrypt(legacyData, key);
241
+
242
+ // Simulate system restart/reload
243
+ const decrypted = DyFM_Crypto.decrypt(encrypted, key);
244
+ expect(decrypted).toEqual(legacyData);
245
+
246
+ // Re-encrypt should produce same result
247
+ const reEncrypted = DyFM_Crypto.encrypt(decrypted, key);
248
+ expect(reEncrypted).toBe(encrypted);
249
+ });
250
+ });
251
+
252
+ describe('| Platform independence tests', () => {
253
+ it('| should handle different character encodings consistently', () => {
254
+ const unicodeData = {
255
+ hungarian: 'árvíztűrő tükörfúrógép',
256
+ chinese: '你好世界',
257
+ emoji: '🚀💻🔒',
258
+ special: '!@#$%^&*()_+-=[]{}|;:,.<>?'
259
+ };
260
+ const key = 'unicode-test-key';
261
+
262
+ const encrypted = DyFM_Crypto.encrypt(unicodeData, key);
263
+ const decrypted = DyFM_Crypto.decrypt(encrypted, key);
264
+ expect(decrypted).toEqual(unicodeData);
265
+
266
+ // Multiple encryptions should be identical
267
+ const encrypted2 = DyFM_Crypto.encrypt(unicodeData, key);
268
+ expect(encrypted).toBe(encrypted2);
269
+ });
270
+
271
+ it('| should handle large data objects consistently', () => {
272
+ // Create a large object with many properties
273
+ const largeData: any = { id: 1 };
274
+ for (let i = 0; i < 100; i++) {
275
+ largeData[`prop${i}`] = `value${i}`;
276
+ }
277
+ const key = 'large-data-key';
278
+
279
+ const encrypted1 = DyFM_Crypto.encrypt(largeData, key);
280
+ const encrypted2 = DyFM_Crypto.encrypt(largeData, key);
281
+ expect(encrypted1).toBe(encrypted2);
282
+
283
+ const decrypted = DyFM_Crypto.decrypt(encrypted1, key);
284
+ expect(decrypted).toEqual(largeData);
285
+ });
286
+
287
+ it('| should handle nested circular references gracefully', () => {
288
+ const circularData: any = { id: 1, name: 'circular' };
289
+ circularData.self = circularData;
290
+ const key = 'circular-key';
291
+
292
+ // Should handle circular references without crashing
293
+ expect(() => {
294
+ const encrypted = DyFM_Crypto.encrypt(circularData, key);
295
+ // Note: JSON.stringify will fail on circular refs, so this test ensures graceful handling
296
+ }).toThrow(); // Expected to throw due to circular reference
297
+ });
298
+ });
299
+
300
+ describe('| Time-based stability tests', () => {
301
+ it('| should maintain consistency across time-based operations', () => {
302
+ const timeData = {
303
+ timestamp: new Date().toISOString(),
304
+ id: 1,
305
+ name: 'time-test'
306
+ };
307
+ const key = 'time-test-key';
308
+
309
+ // Encrypt same data multiple times
310
+ const encrypted1 = DyFM_Crypto.encrypt(timeData, key);
311
+
312
+ // Simulate time passing
313
+ setTimeout(() => {
314
+ const encrypted2 = DyFM_Crypto.encrypt(timeData, key);
315
+ expect(encrypted1).toBe(encrypted2);
316
+ }, 100);
317
+ });
318
+
319
+ it('| should handle date objects consistently', () => {
320
+ const dateData = {
321
+ created: new Date('2024-01-01T00:00:00Z'),
322
+ updated: new Date('2024-12-31T23:59:59Z'),
323
+ id: 1
324
+ };
325
+ const key = 'date-test-key';
326
+
327
+ const encrypted1 = DyFM_Crypto.encrypt(dateData, key);
328
+ const encrypted2 = DyFM_Crypto.encrypt(dateData, key);
329
+ expect(encrypted1).toBe(encrypted2);
330
+
331
+ const decrypted = DyFM_Crypto.decrypt(encrypted1, key) as any;
332
+ // Compare ISO strings since JSON serialization converts dates to strings
333
+ expect(decrypted.created).toEqual(dateData.created.toISOString());
334
+ expect(decrypted.updated).toEqual(dateData.updated.toISOString());
335
+ expect(decrypted.id).toBe(dateData.id);
336
+ });
337
+ });
338
+
339
+ describe('| Memory and performance stability', () => {
340
+ it('| should handle multiple encryption/decryption cycles without memory leaks', () => {
341
+ const testData = { id: 1, name: 'memory-test' };
342
+ const key = 'memory-test-key';
343
+
344
+ // Perform many encryption/decryption cycles
345
+ for (let i = 0; i < 1000; i++) {
346
+ const encrypted = DyFM_Crypto.encrypt(testData, key);
347
+ const decrypted = DyFM_Crypto.decrypt(encrypted, key);
348
+ expect(decrypted).toEqual(testData);
349
+ }
350
+ });
351
+
352
+ it('| should maintain consistent performance across multiple operations', () => {
353
+ const testData = { id: 1, name: 'performance-test' };
354
+ const key = 'performance-test-key';
355
+
356
+ const startTime = Date.now();
357
+
358
+ // Perform multiple operations
359
+ for (let i = 0; i < 100; i++) {
360
+ const encrypted = DyFM_Crypto.encrypt(testData, key);
361
+ const decrypted = DyFM_Crypto.decrypt(encrypted, key);
362
+ expect(decrypted).toEqual(testData);
363
+ }
364
+
365
+ const endTime = Date.now();
366
+ const duration = endTime - startTime;
367
+
368
+ // Should complete within reasonable time (adjust threshold as needed)
369
+ expect(duration).toBeLessThan(5000); // 5 seconds max
370
+ });
371
+ });
372
+ });
373
+
374
+ describe('| URL-safe base64 transmission edge cases', () => {
375
+ it('| should handle encrypted data that loses padding during URL transmission', () => {
376
+ const encrypted = DyFM_Crypto.encrypt(testData, testKey);
377
+ // Simulate padding loss during URL transmission
378
+ // Encrypted data already has no padding (removed in encrypt), so this tests normal behavior
379
+ expect(() => DyFM_Crypto.decrypt(encrypted, testKey)).not.toThrow();
380
+ const decrypted = DyFM_Crypto.decrypt(encrypted, testKey);
381
+ expect(decrypted).toEqual(testData);
382
+ });
383
+
384
+ it('| should handle encrypted data with 0 padding characters (normal case)', () => {
385
+ const encrypted = DyFM_Crypto.encrypt(testData, testKey);
386
+ // Encrypted data has no padding (removed by .replace(/=+$/, ''))
387
+ expect(encrypted).not.toContain('=');
388
+ expect(() => DyFM_Crypto.decrypt(encrypted, testKey)).not.toThrow();
389
+ const decrypted = DyFM_Crypto.decrypt(encrypted, testKey);
390
+ expect(decrypted).toEqual(testData);
391
+ });
392
+
393
+ it('| should handle encrypted data that would need 1 padding character', () => {
394
+ // Create a scenario where base64 would need 1 padding char
395
+ // This is tested by encrypting and verifying it works without padding
396
+ const encrypted = DyFM_Crypto.encrypt(testData, testKey);
397
+ // If the encrypted string length % 4 === 3, it would need 1 padding char
398
+ // But since padding is removed, we verify it still works
399
+ expect(() => DyFM_Crypto.decrypt(encrypted, testKey)).not.toThrow();
400
+ });
401
+
402
+ it('| should handle encrypted data that would need 2 padding characters', () => {
403
+ // Create a scenario where base64 would need 2 padding chars
404
+ const encrypted = DyFM_Crypto.encrypt(testData, testKey);
405
+ // If the encrypted string length % 4 === 2, it would need 2 padding chars
406
+ // Verify it works without explicit padding
407
+ expect(() => DyFM_Crypto.decrypt(encrypted, testKey)).not.toThrow();
408
+ });
409
+
410
+ it('| should handle encrypted data that would need 3 padding characters', () => {
411
+ // Create a scenario where base64 would need 3 padding chars
412
+ const encrypted = DyFM_Crypto.encrypt(testData, testKey);
413
+ // If the encrypted string length % 4 === 1, it would need 3 padding chars
414
+ // Verify it works without explicit padding
415
+ expect(() => DyFM_Crypto.decrypt(encrypted, testKey)).not.toThrow();
416
+ });
417
+
418
+ it('| should handle base64 strings that are valid but too short after parsing', () => {
419
+ // Create a valid URL-safe base64 string that's too short
420
+ const validButShort = 'ABCDEFGHIJKLMNOPQRSTUVWXY'; // 25 chars, valid format but too short
421
+ expect(() => DyFM_Crypto.decrypt(validButShort, testKey)).toThrow();
422
+ });
423
+
424
+ it('| should handle round-trip encryption/decryption with padding edge cases', () => {
425
+ // Test that encryption/decryption works correctly even when padding is removed
426
+ const testCases = [
427
+ { id: 1, name: 'test' },
428
+ { id: 2, data: 'short' },
429
+ { id: 3, data: 'A'.repeat(100) }, // Longer data
430
+ { id: 4, nested: { value: true } }
431
+ ];
432
+
433
+ testCases.forEach(testCase => {
434
+ const encrypted = DyFM_Crypto.encrypt(testCase, testKey);
435
+ // Verify no padding in encrypted string
436
+ expect(encrypted).not.toContain('=');
437
+ // Verify round-trip works
438
+ const decrypted = DyFM_Crypto.decrypt(encrypted, testKey);
439
+ expect(decrypted).toEqual(testCase);
440
+ });
441
+ });
442
+
443
+ it('| should handle URL-safe base64 conversion correctly', () => {
444
+ const encrypted = DyFM_Crypto.encrypt(testData, testKey);
445
+ // Verify it's URL-safe (no +, /, or =)
446
+ expect(encrypted).not.toContain('+');
447
+ expect(encrypted).not.toContain('/');
448
+ expect(encrypted).not.toContain('=');
449
+ // Verify it can be decrypted
450
+ expect(() => DyFM_Crypto.decrypt(encrypted, testKey)).not.toThrow();
451
+ });
452
+
453
+ it('| should handle base64 strings with various padding scenarios in transmission', () => {
454
+ const encrypted = DyFM_Crypto.encrypt(testData, testKey);
455
+
456
+ // Simulate different padding scenarios that might occur during transmission
457
+ // Even though encrypted data has no padding, test that decryption handles it
458
+ const scenarios = [
459
+ encrypted, // No padding (normal)
460
+ encrypted + '=', // 1 padding char added
461
+ encrypted + '==', // 2 padding chars added
462
+ encrypted + '===' // 3 padding chars added
463
+ ];
464
+
465
+ // The first one should work (no padding)
466
+ expect(() => DyFM_Crypto.decrypt(scenarios[0], testKey)).not.toThrow();
467
+
468
+ // Others might work or fail depending on base64 parsing
469
+ scenarios.slice(1).forEach((scenario, index) => {
470
+ // These might work if CryptoJS handles padding, or fail if data is corrupted
471
+ try {
472
+ const decrypted = DyFM_Crypto.decrypt(scenario, testKey);
473
+ expect(decrypted).toEqual(testData);
474
+ } catch {
475
+ // If it fails, that's also acceptable as extra padding shouldn't be there
476
+ expect(() => DyFM_Crypto.decrypt(scenario, testKey)).toThrow();
477
+ }
478
+ });
479
+ });
480
+
481
+ it('| should handle URL encoding/decoding edge cases', () => {
482
+ const encrypted = DyFM_Crypto.encrypt(testData, testKey);
483
+
484
+ // Simulate URL encoding (though encrypted data should already be URL-safe)
485
+ // Test that the encrypted string works in URL contexts
486
+ const urlEncoded = encodeURIComponent(encrypted);
487
+ const urlDecoded = decodeURIComponent(urlEncoded);
488
+
489
+ // Should be able to decrypt after URL encoding/decoding
490
+ expect(() => DyFM_Crypto.decrypt(urlDecoded, testKey)).not.toThrow();
491
+ const decrypted = DyFM_Crypto.decrypt(urlDecoded, testKey);
492
+ expect(decrypted).toEqual(testData);
493
+ });
494
+
495
+ it('| should handle base64 strings that are valid format but truncated', () => {
496
+ const encrypted = DyFM_Crypto.encrypt(testData, testKey);
497
+ // Truncate to various lengths that are still valid base64 format
498
+ const truncationPoints = [
499
+ Math.floor(encrypted.length * 0.5),
500
+ Math.floor(encrypted.length * 0.75),
501
+ encrypted.length - 5,
502
+ encrypted.length - 10
503
+ ];
504
+
505
+ truncationPoints.forEach(point => {
506
+ const truncated = encrypted.substring(0, point);
507
+ // Should throw error for truncated data
508
+ expect(() => DyFM_Crypto.decrypt(truncated, testKey)).toThrow();
509
+ });
510
+ });
511
+ });
512
+
513
+ });