|
8 | 8 | executeRequest, |
9 | 9 | formatRequestParams, |
10 | 10 | getClientEnvVars, |
11 | | - isSafeKey, |
12 | | - safeAssign, |
13 | 11 | validateRequiredParametersAfterMerge, |
14 | 12 | } from '@/tools/utils' |
15 | 13 |
|
@@ -41,98 +39,6 @@ afterEach(() => { |
41 | 39 | vi.clearAllMocks() |
42 | 40 | }) |
43 | 41 |
|
44 | | -describe('isSafeKey', () => { |
45 | | - it.concurrent('should return false for __proto__', () => { |
46 | | - expect(isSafeKey('__proto__')).toBe(false) |
47 | | - }) |
48 | | - |
49 | | - it.concurrent('should return false for constructor', () => { |
50 | | - expect(isSafeKey('constructor')).toBe(false) |
51 | | - }) |
52 | | - |
53 | | - it.concurrent('should return false for prototype', () => { |
54 | | - expect(isSafeKey('prototype')).toBe(false) |
55 | | - }) |
56 | | - |
57 | | - it.concurrent('should return true for normal keys', () => { |
58 | | - expect(isSafeKey('name')).toBe(true) |
59 | | - expect(isSafeKey('email')).toBe(true) |
60 | | - expect(isSafeKey('customField')).toBe(true) |
61 | | - expect(isSafeKey('data')).toBe(true) |
62 | | - expect(isSafeKey('__internal')).toBe(true) |
63 | | - }) |
64 | | -}) |
65 | | - |
66 | | -describe('safeAssign', () => { |
67 | | - it.concurrent('should assign safe properties', () => { |
68 | | - const target = { a: 1 } |
69 | | - const source = { b: 2, c: 3 } |
70 | | - const result = safeAssign(target, source) |
71 | | - |
72 | | - expect(result).toEqual({ a: 1, b: 2, c: 3 }) |
73 | | - expect(result).toBe(target) |
74 | | - }) |
75 | | - |
76 | | - it.concurrent('should filter out __proto__ key', () => { |
77 | | - const target = { a: 1 } |
78 | | - const source = { b: 2, __proto__: { polluted: true } } as Record<string, unknown> |
79 | | - const result = safeAssign(target, source) |
80 | | - |
81 | | - expect(result).toEqual({ a: 1, b: 2 }) |
82 | | - expect((result as any).__proto__).toBe(Object.prototype) |
83 | | - expect((Object.prototype as any).polluted).toBeUndefined() |
84 | | - }) |
85 | | - |
86 | | - it.concurrent('should filter out constructor key', () => { |
87 | | - const target = { a: 1 } |
88 | | - const source = { b: 2, constructor: { prototype: { polluted: true } } } |
89 | | - const result = safeAssign(target, source) |
90 | | - |
91 | | - expect(result).toEqual({ a: 1, b: 2 }) |
92 | | - expect((Object.prototype as any).polluted).toBeUndefined() |
93 | | - }) |
94 | | - |
95 | | - it.concurrent('should filter out prototype key', () => { |
96 | | - const target = { a: 1 } |
97 | | - const source = { b: 2, prototype: { polluted: true } } |
98 | | - const result = safeAssign(target, source) |
99 | | - |
100 | | - expect(result).toEqual({ a: 1, b: 2 }) |
101 | | - expect((Object.prototype as any).polluted).toBeUndefined() |
102 | | - }) |
103 | | - |
104 | | - it.concurrent('should handle null source', () => { |
105 | | - const target = { a: 1 } |
106 | | - const result = safeAssign(target, null as any) |
107 | | - |
108 | | - expect(result).toEqual({ a: 1 }) |
109 | | - }) |
110 | | - |
111 | | - it.concurrent('should handle undefined source', () => { |
112 | | - const target = { a: 1 } |
113 | | - const result = safeAssign(target, undefined as any) |
114 | | - |
115 | | - expect(result).toEqual({ a: 1 }) |
116 | | - }) |
117 | | - |
118 | | - it.concurrent('should handle non-object source', () => { |
119 | | - const target = { a: 1 } |
120 | | - const result = safeAssign(target, 'string' as any) |
121 | | - |
122 | | - expect(result).toEqual({ a: 1 }) |
123 | | - }) |
124 | | - |
125 | | - it.concurrent('should prevent prototype pollution attack', () => { |
126 | | - const maliciousPayload = JSON.parse('{"__proto__": {"isAdmin": true}, "normal": "value"}') |
127 | | - const target = {} |
128 | | - safeAssign(target, maliciousPayload) |
129 | | - |
130 | | - const newObj = {} |
131 | | - expect((newObj as any).isAdmin).toBeUndefined() |
132 | | - expect((target as any).normal).toBe('value') |
133 | | - }) |
134 | | -}) |
135 | | - |
136 | 42 | describe('transformTable', () => { |
137 | 43 | it.concurrent('should return empty object for null input', () => { |
138 | 44 | const result = transformTable(null) |
|
0 commit comments