• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import {
17  readProjectPropertiesByCollectedPaths,
18  ReseverdSetForArkguard,
19  scanProjectConfig,
20  initScanProjectConfig
21} from '../../../src/common/ApiReader';
22import { assert, expect } from 'chai';
23import { NameGeneratorType } from '../../../src/generator/NameFactory';
24import {
25  FileWhiteList,
26  ProjectWhiteList,
27  projectWhiteListManager,
28  initProjectWhiteListManager
29} from '../../../src/utils/ProjectCollections';
30import { IOptions } from '../../../src/configs/IOptions';
31
32describe('test for ApiReader', function () {
33  describe('test for readProjectPropertiesByCollectedPaths', function () {
34    const path1: string = 'test/ut/utils/apiTest_readProjectPropertiesByCollectedPaths/block_enum_test.ts';
35    const path2: string = 'test/ut/utils/apiTest_readProjectPropertiesByCollectedPaths/enum_test.ts';
36    const path3: string = 'test/ut/utils/apiTest_readProjectPropertiesByCollectedPaths/export_enum_test.ts';
37    const path4: string = 'test/ut/utils/apiTest_readProjectPropertiesByCollectedPaths/namespace_enum_test.ts';
38    const fileList: Set<string> = new Set([path1, path2, path3, path4]);
39
40    it('-enable-export-obfuscation + -enable-property-obfuscation', function () {
41      let config: IOptions = {
42        mNameObfuscation : {
43          mEnable: true,
44          mReservedProperties: [],
45          mRenameProperties: true,
46          mKeepStringProperty: false,
47          mNameGeneratorType: NameGeneratorType.ORDERED,
48          mReservedNames: [],
49          mReservedToplevelNames: []
50        }
51      };
52      let cachePath = 'test/ut/utils/obfuscation';
53      initProjectWhiteListManager(cachePath, false, false);
54      let projectAndLibs: ReseverdSetForArkguard =
55        readProjectPropertiesByCollectedPaths(fileList,
56        {
57          mNameObfuscation: config.mNameObfuscation,
58          mExportObfuscation: true,
59          mKeepFileSourceCode: {
60            mKeepSourceOfPaths: new Set(),
61            mkeepFilesAndDependencies: new Set(),
62          },
63
64        }, true);
65      let enumPropertySet = projectAndLibs.enumPropertySet;
66      assert.strictEqual(enumPropertySet.has('BLOCK_PARAM1'), true);
67      assert.strictEqual(enumPropertySet.has('BLOCK_PARAM2'), true);
68      assert.strictEqual(enumPropertySet.has('ENUM_PARAM1'), true);
69      assert.strictEqual(enumPropertySet.has('ENUM_PARAM2'), true);
70      assert.strictEqual(enumPropertySet.has('NS_PARAM1'), true);
71      assert.strictEqual(enumPropertySet.has('NS_PARAM2'), true);
72      assert.strictEqual(enumPropertySet.has('EXPORT_PARAM1'), true);
73      assert.strictEqual(enumPropertySet.has('EXPORT_PARAM2'), true);
74      const fileWhiteList1: FileWhiteList = projectWhiteListManager!.getFileWhiteListMap().get(path1)!;
75      expect(fileWhiteList1.fileKeepInfo.enumProperties.has('BLOCK_PARAM1')).to.be.true;
76      expect(fileWhiteList1.fileKeepInfo.enumProperties.has('BLOCK_PARAM2')).to.be.true;
77      const fileWhiteList2: FileWhiteList = projectWhiteListManager!.getFileWhiteListMap().get(path2)!;
78      expect(fileWhiteList2.fileKeepInfo.enumProperties.has('ENUM_PARAM1')).to.be.true;
79      expect(fileWhiteList2.fileKeepInfo.enumProperties.has('ENUM_PARAM2')).to.be.true;
80      const fileWhiteList3: FileWhiteList = projectWhiteListManager!.getFileWhiteListMap().get(path3)!;
81      expect(fileWhiteList3.fileKeepInfo.enumProperties.has('EXPORT_PARAM1')).to.be.true;
82      expect(fileWhiteList3.fileKeepInfo.enumProperties.has('EXPORT_PARAM2')).to.be.true;
83      const fileWhiteList4: FileWhiteList = projectWhiteListManager!.getFileWhiteListMap().get(path4)!;
84      expect(fileWhiteList4.fileKeepInfo.enumProperties.has('NS_PARAM1')).to.be.true;
85      expect(fileWhiteList4.fileKeepInfo.enumProperties.has('NS_PARAM2')).to.be.true;
86    });
87
88    it('-enable-property-obfuscation', function () {
89      let config: IOptions = {
90        mNameObfuscation : {
91          mEnable: true,
92          mReservedProperties: [],
93          mRenameProperties: true,
94          mKeepStringProperty: false,
95          mNameGeneratorType: NameGeneratorType.ORDERED,
96          mReservedNames: [],
97          mReservedToplevelNames: []
98        }
99      };
100      let cachePath = 'test/ut/utils/obfuscation';
101      initProjectWhiteListManager(cachePath, false, false);
102      let projectAndLibs: ReseverdSetForArkguard =
103        readProjectPropertiesByCollectedPaths(fileList,
104        {
105          mNameObfuscation: config.mNameObfuscation,
106          mExportObfuscation: false,
107          mKeepFileSourceCode: {
108            mKeepSourceOfPaths: new Set(),
109            mkeepFilesAndDependencies: new Set(),
110          }
111        }, true);
112      let enumPropertySet = projectAndLibs.enumPropertySet;
113      let exportNameAndPropSet = projectAndLibs.exportNameAndPropSet;
114      assert.strictEqual(enumPropertySet.has('BLOCK_PARAM1'), true);
115      assert.strictEqual(enumPropertySet.has('BLOCK_PARAM2'), true);
116      assert.strictEqual(enumPropertySet.has('ENUM_PARAM1'), true);
117      assert.strictEqual(enumPropertySet.has('ENUM_PARAM2'), true);
118      assert.strictEqual(enumPropertySet.has('NS_PARAM1'), true);
119      assert.strictEqual(enumPropertySet.has('NS_PARAM2'), true);
120      assert.strictEqual(enumPropertySet.has('EXPORT_PARAM1'), true);
121      assert.strictEqual(enumPropertySet.has('EXPORT_PARAM2'), true);
122      assert.strictEqual(exportNameAndPropSet.has('ExportEnum'), true);
123      assert.strictEqual(exportNameAndPropSet.has('EXPORT_PARAM1'), true);
124      assert.strictEqual(exportNameAndPropSet.has('EXPORT_PARAM2'), true);
125      const fileWhiteList1: FileWhiteList = projectWhiteListManager!.getFileWhiteListMap().get(path1)!;
126      expect(fileWhiteList1.fileKeepInfo.enumProperties.has('BLOCK_PARAM1')).to.be.true;
127      expect(fileWhiteList1.fileKeepInfo.enumProperties.has('BLOCK_PARAM2')).to.be.true;
128      const fileWhiteList2: FileWhiteList = projectWhiteListManager!.getFileWhiteListMap().get(path2)!;
129      expect(fileWhiteList2.fileKeepInfo.enumProperties.has('ENUM_PARAM1')).to.be.true;
130      expect(fileWhiteList2.fileKeepInfo.enumProperties.has('ENUM_PARAM2')).to.be.true;
131      const fileWhiteList3: FileWhiteList = projectWhiteListManager!.getFileWhiteListMap().get(path3)!;
132      expect(fileWhiteList3.fileKeepInfo.enumProperties.has('EXPORT_PARAM1')).to.be.true;
133      expect(fileWhiteList3.fileKeepInfo.enumProperties.has('EXPORT_PARAM2')).to.be.true;
134      expect(fileWhiteList3.fileKeepInfo.exported.propertyNames.has('ExportEnum')).to.be.true;
135      expect(fileWhiteList3.fileKeepInfo.exported.propertyNames.has('EXPORT_PARAM1')).to.be.true;
136      expect(fileWhiteList3.fileKeepInfo.exported.propertyNames.has('EXPORT_PARAM2')).to.be.true;
137      const fileWhiteList4: FileWhiteList = projectWhiteListManager!.getFileWhiteListMap().get(path4)!;
138      expect(fileWhiteList4.fileKeepInfo.enumProperties.has('NS_PARAM1')).to.be.true;
139      expect(fileWhiteList4.fileKeepInfo.enumProperties.has('NS_PARAM2')).to.be.true;
140    });
141
142    it('-enable-export-obfuscation', function () {
143      let config: IOptions = {
144        mNameObfuscation : {
145          mEnable: true,
146          mReservedProperties: [],
147          mRenameProperties: false,
148          mKeepStringProperty: false,
149          mNameGeneratorType: NameGeneratorType.ORDERED,
150          mReservedNames: [],
151          mReservedToplevelNames: []
152        }
153      };
154      let cachePath = 'test/ut/utils/obfuscation';
155      initProjectWhiteListManager(cachePath, false, false);
156      let projectAndLibs: ReseverdSetForArkguard =
157        readProjectPropertiesByCollectedPaths(fileList,
158        {
159          mNameObfuscation: config.mNameObfuscation,
160          mExportObfuscation: true,
161          mKeepFileSourceCode: {
162            mKeepSourceOfPaths: new Set(),
163            mkeepFilesAndDependencies: new Set(),
164          }
165        }, true);
166      let exportNameAndPropSet = projectAndLibs.exportNameAndPropSet;
167      let exportNameSet = projectAndLibs.exportNameSet;
168      assert.strictEqual(exportNameAndPropSet, undefined);
169      assert.strictEqual(exportNameSet.has('ExportEnum'), false);
170      const fileWhiteLists: Map<string, FileWhiteList> = projectWhiteListManager!.getFileWhiteListMap();
171      const projectWhiteList: ProjectWhiteList = projectWhiteListManager!.createProjectWhiteList(fileWhiteLists);
172      expect(projectWhiteList.projectKeepInfo.propertyNames.size).to.be.equal(0);
173      expect(projectWhiteList.projectKeepInfo.globalNames.size).to.be.equal(0);
174    });
175  });
176
177  describe('test for -keep and export obfuscation', function () {
178    const filePath = 'test/ut/utils/keep_export/exportFile1.ts';
179    const fileList: Set<string> = new Set([filePath]);
180
181    it('-enable-export-obfuscation', function () {
182      let config: IOptions = {
183        mNameObfuscation : {
184          mEnable: true,
185          mReservedProperties: [],
186          mRenameProperties: false,
187          mKeepStringProperty: false,
188          mNameGeneratorType: NameGeneratorType.ORDERED,
189          mReservedNames: [],
190          mReservedToplevelNames: []
191        }
192      };
193      let cachePath = 'test/ut/utils/obfuscation';
194      initProjectWhiteListManager(cachePath, false, false);
195      let projectAndLibs: ReseverdSetForArkguard =
196        readProjectPropertiesByCollectedPaths(fileList,
197        {
198          mNameObfuscation: config.mNameObfuscation,
199          mExportObfuscation: true,
200          mKeepFileSourceCode: {
201            mKeepSourceOfPaths: new Set(),
202            mkeepFilesAndDependencies: new Set([
203              "test/ut/utils/keep_export/exportFile1.ts"
204            ]),
205          }
206        }, true);
207      let exportNameSet = projectAndLibs.exportNameSet;
208      let exportNameAndPropSet = projectAndLibs.exportNameAndPropSet;
209      assert.strictEqual(exportNameSet.has('TestClass'), true);
210      assert.strictEqual(exportNameSet.has('prop1'), false);
211      assert.strictEqual(exportNameSet.has('prop2'), false);
212      assert.strictEqual(exportNameSet.has('objProp'), false);
213      assert.strictEqual(exportNameSet.has('innerProp2'), false);
214      assert.strictEqual(exportNameSet.has('var1'), true);
215      assert.strictEqual(exportNameSet.has('var2'), false);
216      assert.strictEqual(exportNameSet.has('foo'), true);
217      assert.strictEqual(exportNameSet.has('ns'), false);
218      assert.strictEqual(exportNameSet.has('var3'), true);
219      assert.strictEqual(exportNameSet.has('nsFunction'), true);
220      assert.strictEqual(exportNameSet.has('TestInterface'), true);
221      assert.strictEqual(exportNameSet.has('feature1'), false);
222      assert.strictEqual(exportNameSet.has('feature2'), false);
223      assert.strictEqual(exportNameSet.has('TestClass2'), false);
224      assert.strictEqual(exportNameSet.has('prop4'), false);
225      assert.strictEqual(exportNameSet.has('propObj'), false);
226      assert.strictEqual(exportNameSet.has('innerProp'), false);
227      assert.strictEqual(exportNameSet.has('TestClass3'), false);
228      assert.strictEqual(exportNameSet.has('exportProp1'), false);
229      assert.strictEqual(exportNameSet.has('exportPropObj'), false);
230      assert.strictEqual(exportNameSet.has('exportInnerProp'), false);
231      assert.strictEqual(exportNameSet.has('v2'), true);
232      assert.strictEqual(exportNameSet.has('default'), true);
233      assert.strictEqual(exportNameSet.has('t3'), true);
234      assert.strictEqual(exportNameSet.has('outterElement1'), true);
235      assert.strictEqual(exportNameSet.has('outterElement2'), true);
236      assert.strictEqual(exportNameSet.has('o2'), true);
237      assert.strictEqual(exportNameAndPropSet, undefined);
238      const fileWhiteList: FileWhiteList = projectWhiteListManager!.getFileWhiteListMap().get(filePath)!;
239      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('TestClass')).to.be.true;
240      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('prop1')).to.be.false;
241      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('prop2')).to.be.false;
242      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('objProp')).to.be.false;
243      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('innerProp2')).to.be.false;
244      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('var1')).to.be.true;
245      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('var2')).to.be.false;
246      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('foo')).to.be.true;
247      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('ns')).to.be.false;
248      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('var3')).to.be.true;
249      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('nsFunction')).to.be.true;
250      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('TestInterface')).to.be.true;
251      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('feature1')).to.be.false;
252      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('feature2')).to.be.false;
253      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('TestClass2')).to.be.false;
254      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('prop4')).to.be.false;
255      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('propObj')).to.be.false;
256      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('innerProp')).to.be.false;
257      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('TestClass3')).to.be.false;
258      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('exportProp1')).to.be.false;
259      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('exportPropObj')).to.be.false;
260      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('exportInnerProp')).to.be.false;
261      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('v2')).to.be.true;
262      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('default')).to.be.true;
263      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('t3')).to.be.true;
264      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('outterElement1')).to.be.true;
265      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('outterElement2')).to.be.true;
266      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('o2')).to.be.true;
267      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.size).to.be.equal(0);
268    });
269
270    it('-enable-property-obfuscation', function () {
271      let config: IOptions = {
272        mNameObfuscation : {
273          mEnable: true,
274          mReservedProperties: [],
275          mRenameProperties: true,
276          mKeepStringProperty: false,
277          mNameGeneratorType: NameGeneratorType.ORDERED,
278          mReservedNames: [],
279          mReservedToplevelNames: []
280        }
281      };
282      let cachePath = 'test/ut/utils/obfuscation';
283      initProjectWhiteListManager(cachePath, false, false);
284      let projectAndLibs: ReseverdSetForArkguard =
285        readProjectPropertiesByCollectedPaths(fileList,
286        {
287          mNameObfuscation: config.mNameObfuscation,
288          mExportObfuscation: false,
289          mKeepFileSourceCode: {
290            mKeepSourceOfPaths: new Set(),
291            mkeepFilesAndDependencies: new Set([
292              "test/ut/utils/keep_export/exportFile1.ts"
293            ]),
294          }
295        }, true);
296      let exportNameAndPropSet = projectAndLibs.exportNameAndPropSet;
297      let exportNameSet = projectAndLibs.exportNameSet;
298      assert.strictEqual(exportNameAndPropSet.has('TestClass'), true);
299      assert.strictEqual(exportNameAndPropSet.has('prop1'), true);
300      assert.strictEqual(exportNameAndPropSet.has('prop2'), true);
301      assert.strictEqual(exportNameAndPropSet.has('objProp'), true);
302      assert.strictEqual(exportNameAndPropSet.has('innerProp2'), true);
303      assert.strictEqual(exportNameAndPropSet.has('var1'), true);
304      assert.strictEqual(exportNameAndPropSet.has('var2'), false);
305      assert.strictEqual(exportNameAndPropSet.has('foo'), true);
306      assert.strictEqual(exportNameAndPropSet.has('ns'), false);
307      assert.strictEqual(exportNameAndPropSet.has('var3'), true);
308      assert.strictEqual(exportNameAndPropSet.has('nsFunction'), true);
309      assert.strictEqual(exportNameAndPropSet.has('TestInterface'), true);
310      assert.strictEqual(exportNameAndPropSet.has('feature1'), true);
311      assert.strictEqual(exportNameAndPropSet.has('feature2'), true);
312      assert.strictEqual(exportNameAndPropSet.has('TestClass2'), false);
313      assert.strictEqual(exportNameAndPropSet.has('prop4'), false);
314      assert.strictEqual(exportNameAndPropSet.has('propObj'), false);
315      assert.strictEqual(exportNameAndPropSet.has('innerProp'), false);
316      assert.strictEqual(exportNameAndPropSet.has('TestClass3'), false);
317      assert.strictEqual(exportNameAndPropSet.has('exportProp1'), true);
318      assert.strictEqual(exportNameAndPropSet.has('exportPropObj'), true);
319      assert.strictEqual(exportNameAndPropSet.has('exportInnerProp'), true);
320      assert.strictEqual(exportNameAndPropSet.has('v2'), true);
321      assert.strictEqual(exportNameAndPropSet.has('default'), true);
322      assert.strictEqual(exportNameAndPropSet.has('t3'), true);
323      assert.strictEqual(exportNameAndPropSet.has('outterElement1'), true);
324      assert.strictEqual(exportNameAndPropSet.has('outterElement2'), false);
325      assert.strictEqual(exportNameAndPropSet.has('o2'), true);
326      assert.strictEqual(exportNameSet, undefined);
327      const fileWhiteList: FileWhiteList = projectWhiteListManager!.getFileWhiteListMap().get(filePath)!;
328      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('TestClass')).to.be.true;
329      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('prop1')).to.be.true;
330      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('prop2')).to.be.true;
331      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('objProp')).to.be.true;
332      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('innerProp2')).to.be.true;
333      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('var1')).to.be.true;
334      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('var2')).to.be.false;
335      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('foo')).to.be.true;
336      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('ns')).to.be.false;
337      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('var3')).to.be.true;
338      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('nsFunction')).to.be.true;
339      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('TestInterface')).to.be.true;
340      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('feature1')).to.be.true;
341      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('feature2')).to.be.true;
342      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('TestClass2')).to.be.false;
343      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('prop4')).to.be.false;
344      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('propObj')).to.be.false;
345      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('innerProp')).to.be.false;
346      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('TestClass3')).to.be.false;
347      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('exportProp1')).to.be.true;
348      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('exportPropObj')).to.be.true;
349      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('exportInnerProp')).to.be.true;
350      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('v2')).to.be.true;
351      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('default')).to.be.true;
352      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('t3')).to.be.true;
353      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('outterElement1')).to.be.true;
354      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('outterElement2')).to.be.false;
355      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('o2')).to.be.true;
356      expect(fileWhiteList.fileKeepInfo.exported.globalNames.size).to.be.equal(0);
357    });
358
359    it('-enable-toplevel-obfuscation', function () {
360      let config: IOptions = {
361        mNameObfuscation : {
362          mEnable: true,
363          mReservedProperties: [],
364          mRenameProperties: false,
365          mKeepStringProperty: false,
366          mTopLevel: true,
367          mNameGeneratorType: NameGeneratorType.ORDERED,
368          mReservedNames: [],
369          mReservedToplevelNames: []
370        }
371      };
372      let cachePath = 'test/ut/utils/obfuscation';
373      initProjectWhiteListManager(cachePath, false, false);
374      let projectAndLibs: ReseverdSetForArkguard =
375        readProjectPropertiesByCollectedPaths(fileList,
376        {
377          mNameObfuscation: config.mNameObfuscation,
378          mExportObfuscation: false,
379          mKeepFileSourceCode: {
380            mKeepSourceOfPaths: new Set(),
381            mkeepFilesAndDependencies: new Set([
382              "test/ut/utils/keep_export/exportFile1.ts"
383            ]),
384          }
385        }, true);
386      let exportNameAndPropSet = projectAndLibs.exportNameAndPropSet;
387      let exportNameSet = projectAndLibs.exportNameSet;
388      assert.strictEqual(exportNameAndPropSet, undefined);
389      assert.strictEqual(exportNameSet, undefined);
390      const fileWhiteList: FileWhiteList = projectWhiteListManager!.getFileWhiteListMap().get(filePath)!;
391      expect(fileWhiteList.fileKeepInfo.exported.globalNames.size).to.be.equal(0);
392      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.size).to.be.equal(0);
393    });
394
395    it('-enable-toplevel-obfuscation -enable-export-obfuscation', function () {
396      let config: IOptions = {
397        mNameObfuscation : {
398          mEnable: true,
399          mReservedProperties: [],
400          mRenameProperties: false,
401          mKeepStringProperty: false,
402          mTopLevel: true,
403          mNameGeneratorType: NameGeneratorType.ORDERED,
404          mReservedNames: [],
405          mReservedToplevelNames: []
406        }
407      };
408      let cachePath = 'test/ut/utils/obfuscation';
409      initProjectWhiteListManager(cachePath, false, false);
410      let projectAndLibs: ReseverdSetForArkguard =
411        readProjectPropertiesByCollectedPaths(fileList,
412        {
413          mNameObfuscation: config.mNameObfuscation,
414          mExportObfuscation: true,
415          mKeepFileSourceCode: {
416            mKeepSourceOfPaths: new Set(),
417            mkeepFilesAndDependencies: new Set([
418              "test/ut/utils/keep_export/exportFile1.ts"
419            ]),
420          }
421        }, true);
422      let exportNameAndPropSet = projectAndLibs.exportNameAndPropSet;
423      let exportNameSet = projectAndLibs.exportNameSet;
424      assert.strictEqual(exportNameSet.has('TestClass'), true);
425      assert.strictEqual(exportNameSet.has('prop1'), false);
426      assert.strictEqual(exportNameSet.has('prop2'), false);
427      assert.strictEqual(exportNameSet.has('objProp'), false);
428      assert.strictEqual(exportNameSet.has('innerProp2'), false);
429      assert.strictEqual(exportNameSet.has('var1'), true);
430      assert.strictEqual(exportNameSet.has('var2'), false);
431      assert.strictEqual(exportNameSet.has('foo'), true);
432      assert.strictEqual(exportNameSet.has('ns'), false);
433      assert.strictEqual(exportNameSet.has('var3'), true);
434      assert.strictEqual(exportNameSet.has('nsFunction'), true);
435      assert.strictEqual(exportNameSet.has('TestInterface'), true);
436      assert.strictEqual(exportNameSet.has('feature1'), false);
437      assert.strictEqual(exportNameSet.has('feature2'), false);
438      assert.strictEqual(exportNameSet.has('TestClass2'), false);
439      assert.strictEqual(exportNameSet.has('prop4'), false);
440      assert.strictEqual(exportNameSet.has('propObj'), false);
441      assert.strictEqual(exportNameSet.has('innerProp'), false);
442      assert.strictEqual(exportNameSet.has('TestClass3'), false);
443      assert.strictEqual(exportNameSet.has('exportProp1'), false);
444      assert.strictEqual(exportNameSet.has('exportPropObj'), false);
445      assert.strictEqual(exportNameSet.has('exportInnerProp'), false);
446      assert.strictEqual(exportNameSet.has('v2'), true);
447      assert.strictEqual(exportNameSet.has('default'), true);
448      assert.strictEqual(exportNameSet.has('t3'), true);
449      assert.strictEqual(exportNameSet.has('outterElement1'), true);
450      assert.strictEqual(exportNameSet.has('outterElement2'), true);
451      assert.strictEqual(exportNameSet.has('o2'), true);
452      assert.strictEqual(exportNameAndPropSet, undefined);
453      const fileWhiteList: FileWhiteList = projectWhiteListManager!.getFileWhiteListMap().get(filePath)!;
454      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('TestClass')).to.be.true;
455      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('prop1')).to.be.false;
456      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('prop2')).to.be.false;
457      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('objProp')).to.be.false;
458      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('innerProp2')).to.be.false;
459      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('var1')).to.be.true;
460      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('var2')).to.be.false;
461      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('foo')).to.be.true;
462      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('ns')).to.be.false;
463      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('var3')).to.be.true;
464      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('nsFunction')).to.be.true;
465      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('TestInterface')).to.be.true;
466      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('feature1')).to.be.false;
467      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('feature2')).to.be.false;
468      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('TestClass2')).to.be.false;
469      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('prop4')).to.be.false;
470      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('propObj')).to.be.false;
471      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('innerProp')).to.be.false;
472      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('TestClass3')).to.be.false;
473      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('exportProp1')).to.be.false;
474      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('exportPropObj')).to.be.false;
475      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('exportInnerProp')).to.be.false;
476      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('v2')).to.be.true;
477      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('default')).to.be.true;
478      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('t3')).to.be.true;
479      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('outterElement1')).to.be.true;
480      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('outterElement2')).to.be.true;
481      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('o2')).to.be.true;
482      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.size).to.be.equal(0);
483    });
484
485    it('-enable-property-obfuscation -enable-export-obfuscation', function () {
486      let config: IOptions = {
487        mNameObfuscation : {
488          mEnable: true,
489          mReservedProperties: [],
490          mRenameProperties: true,
491          mKeepStringProperty: false,
492          mTopLevel: false,
493          mNameGeneratorType: NameGeneratorType.ORDERED,
494          mReservedNames: [],
495          mReservedToplevelNames: []
496        }
497      };
498      let cachePath = 'test/ut/utils/obfuscation';
499      initProjectWhiteListManager(cachePath, false, false);
500      let projectAndLibs: ReseverdSetForArkguard =
501        readProjectPropertiesByCollectedPaths(fileList,
502        {
503          mNameObfuscation: config.mNameObfuscation,
504          mExportObfuscation: true,
505          mKeepFileSourceCode: {
506            mKeepSourceOfPaths: new Set(),
507            mkeepFilesAndDependencies: new Set([
508              "test/ut/utils/keep_export/exportFile1.ts"
509            ]),
510          }
511        }, true);
512      let exportNameAndPropSet = projectAndLibs.exportNameAndPropSet;
513      let exportNameSet = projectAndLibs.exportNameSet;
514      assert.strictEqual(exportNameSet.has('TestClass'), true);
515      assert.strictEqual(exportNameSet.has('prop1'), false);
516      assert.strictEqual(exportNameSet.has('prop2'), false);
517      assert.strictEqual(exportNameSet.has('objProp'), false);
518      assert.strictEqual(exportNameSet.has('innerProp2'), false);
519      assert.strictEqual(exportNameSet.has('var1'), true);
520      assert.strictEqual(exportNameSet.has('var2'), false);
521      assert.strictEqual(exportNameSet.has('foo'), true);
522      assert.strictEqual(exportNameSet.has('ns'), false);
523      assert.strictEqual(exportNameSet.has('var3'), true);
524      assert.strictEqual(exportNameSet.has('nsFunction'), true);
525      assert.strictEqual(exportNameSet.has('TestInterface'), true);
526      assert.strictEqual(exportNameSet.has('feature1'), false);
527      assert.strictEqual(exportNameSet.has('feature2'), false);
528      assert.strictEqual(exportNameSet.has('TestClass2'), false);
529      assert.strictEqual(exportNameSet.has('prop4'), false);
530      assert.strictEqual(exportNameSet.has('propObj'), false);
531      assert.strictEqual(exportNameSet.has('innerProp'), false);
532      assert.strictEqual(exportNameSet.has('TestClass3'), false);
533      assert.strictEqual(exportNameSet.has('exportProp1'), false);
534      assert.strictEqual(exportNameSet.has('exportPropObj'), false);
535      assert.strictEqual(exportNameSet.has('exportInnerProp'), false);
536      assert.strictEqual(exportNameSet.has('v2'), true);
537      assert.strictEqual(exportNameSet.has('default'), true);
538      assert.strictEqual(exportNameSet.has('t3'), true);
539      assert.strictEqual(exportNameSet.has('outterElement1'), true);
540      assert.strictEqual(exportNameSet.has('outterElement2'), true);
541      assert.strictEqual(exportNameSet.has('o2'), true);
542      assert.strictEqual(exportNameAndPropSet.has('TestClass'), true);
543      assert.strictEqual(exportNameAndPropSet.has('prop1'), true);
544      assert.strictEqual(exportNameAndPropSet.has('prop2'), true);
545      assert.strictEqual(exportNameAndPropSet.has('objProp'), true);
546      assert.strictEqual(exportNameAndPropSet.has('innerProp2'), true);
547      assert.strictEqual(exportNameAndPropSet.has('var1'), true);
548      assert.strictEqual(exportNameAndPropSet.has('var2'), false);
549      assert.strictEqual(exportNameAndPropSet.has('foo'), true);
550      assert.strictEqual(exportNameAndPropSet.has('ns'), false);
551      assert.strictEqual(exportNameAndPropSet.has('var3'), true);
552      assert.strictEqual(exportNameAndPropSet.has('nsFunction'), true);
553      assert.strictEqual(exportNameAndPropSet.has('TestInterface'), true);
554      assert.strictEqual(exportNameAndPropSet.has('feature1'), true);
555      assert.strictEqual(exportNameAndPropSet.has('feature2'), true);
556      assert.strictEqual(exportNameAndPropSet.has('TestClass2'), false);
557      assert.strictEqual(exportNameAndPropSet.has('prop4'), false);
558      assert.strictEqual(exportNameAndPropSet.has('propObj'), false);
559      assert.strictEqual(exportNameAndPropSet.has('innerProp'), false);
560      assert.strictEqual(exportNameAndPropSet.has('TestClass3'), false);
561      assert.strictEqual(exportNameAndPropSet.has('exportProp1'), true);
562      assert.strictEqual(exportNameAndPropSet.has('exportPropObj'), true);
563      assert.strictEqual(exportNameAndPropSet.has('exportInnerProp'), true);
564      assert.strictEqual(exportNameAndPropSet.has('v2'), true);
565      assert.strictEqual(exportNameAndPropSet.has('default'), true);
566      assert.strictEqual(exportNameAndPropSet.has('t3'), true);
567      assert.strictEqual(exportNameAndPropSet.has('outterElement1'), true);
568      assert.strictEqual(exportNameAndPropSet.has('outterElement2'), false);
569      assert.strictEqual(exportNameAndPropSet.has('o2'), true);
570      const fileWhiteList: FileWhiteList = projectWhiteListManager!.getFileWhiteListMap().get(filePath)!;
571      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('TestClass')).to.be.true;
572      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('prop1')).to.be.false;
573      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('prop2')).to.be.false;
574      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('objProp')).to.be.false;
575      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('innerProp2')).to.be.false;
576      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('var1')).to.be.true;
577      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('var2')).to.be.false;
578      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('foo')).to.be.true;
579      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('ns')).to.be.false;
580      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('var3')).to.be.true;
581      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('nsFunction')).to.be.true;
582      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('TestInterface')).to.be.true;
583      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('feature1')).to.be.false;
584      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('feature2')).to.be.false;
585      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('TestClass2')).to.be.false;
586      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('prop4')).to.be.false;
587      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('propObj')).to.be.false;
588      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('innerProp')).to.be.false;
589      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('TestClass3')).to.be.false;
590      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('exportProp1')).to.be.false;
591      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('exportPropObj')).to.be.false;
592      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('exportInnerProp')).to.be.false;
593      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('v2')).to.be.true;
594      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('default')).to.be.true;
595      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('t3')).to.be.true;
596      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('outterElement1')).to.be.true;
597      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('outterElement2')).to.be.true;
598      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('o2')).to.be.true;
599      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('TestClass')).to.be.true;
600      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('prop1')).to.be.true;
601      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('prop2')).to.be.true;
602      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('objProp')).to.be.true;
603      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('innerProp2')).to.be.true;
604      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('var1')).to.be.true;
605      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('var2')).to.be.false;
606      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('foo')).to.be.true;
607      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('ns')).to.be.false;
608      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('var3')).to.be.true;
609      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('nsFunction')).to.be.true;
610      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('TestInterface')).to.be.true;
611      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('feature1')).to.be.true;
612      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('feature2')).to.be.true;
613      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('TestClass2')).to.be.false;
614      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('prop4')).to.be.false;
615      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('propObj')).to.be.false;
616      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('innerProp')).to.be.false;
617      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('TestClass3')).to.be.false;
618      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('exportProp1')).to.be.true;
619      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('exportPropObj')).to.be.true;
620      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('exportInnerProp')).to.be.true;
621      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('v2')).to.be.true;
622      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('default')).to.be.true;
623      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('t3')).to.be.true;
624      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('outterElement1')).to.be.true;
625      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('outterElement2')).to.be.false;
626      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('o2')).to.be.true;
627    });
628
629    it('-enable-property-obfuscation -enable-export-obfuscation -enable-toplevel-obfuscation', function () {
630      let config: IOptions = {
631        mNameObfuscation : {
632          mEnable: true,
633          mReservedProperties: [],
634          mRenameProperties: true,
635          mKeepStringProperty: false,
636          mTopLevel: true,
637          mNameGeneratorType: NameGeneratorType.ORDERED,
638          mReservedNames: [],
639          mReservedToplevelNames: []
640        }
641      };
642      let cachePath = 'test/ut/utils/obfuscation';
643      initProjectWhiteListManager(cachePath, false, false);
644      let projectAndLibs: ReseverdSetForArkguard =
645        readProjectPropertiesByCollectedPaths(fileList,
646        {
647          mNameObfuscation: config.mNameObfuscation,
648          mExportObfuscation: true,
649          mKeepFileSourceCode: {
650            mKeepSourceOfPaths: new Set(),
651            mkeepFilesAndDependencies: new Set([
652              "test/ut/utils/keep_export/exportFile1.ts"
653            ]),
654          }
655        }, true);
656      let exportNameAndPropSet = projectAndLibs.exportNameAndPropSet;
657      let exportNameSet = projectAndLibs.exportNameSet;
658      assert.strictEqual(exportNameSet.has('TestClass'), true);
659      assert.strictEqual(exportNameSet.has('prop1'), false);
660      assert.strictEqual(exportNameSet.has('prop2'), false);
661      assert.strictEqual(exportNameSet.has('objProp'), false);
662      assert.strictEqual(exportNameSet.has('innerProp2'), false);
663      assert.strictEqual(exportNameSet.has('var1'), true);
664      assert.strictEqual(exportNameSet.has('var2'), false);
665      assert.strictEqual(exportNameSet.has('foo'), true);
666      assert.strictEqual(exportNameSet.has('ns'), false);
667      assert.strictEqual(exportNameSet.has('var3'), true);
668      assert.strictEqual(exportNameSet.has('nsFunction'), true);
669      assert.strictEqual(exportNameSet.has('TestInterface'), true);
670      assert.strictEqual(exportNameSet.has('feature1'), false);
671      assert.strictEqual(exportNameSet.has('feature2'), false);
672      assert.strictEqual(exportNameSet.has('TestClass2'), false);
673      assert.strictEqual(exportNameSet.has('prop4'), false);
674      assert.strictEqual(exportNameSet.has('propObj'), false);
675      assert.strictEqual(exportNameSet.has('innerProp'), false);
676      assert.strictEqual(exportNameSet.has('TestClass3'), false);
677      assert.strictEqual(exportNameSet.has('exportProp1'), false);
678      assert.strictEqual(exportNameSet.has('exportPropObj'), false);
679      assert.strictEqual(exportNameSet.has('exportInnerProp'), false);
680      assert.strictEqual(exportNameSet.has('v2'), true);
681      assert.strictEqual(exportNameSet.has('default'), true);
682      assert.strictEqual(exportNameSet.has('t3'), true);
683      assert.strictEqual(exportNameSet.has('outterElement1'), true);
684      assert.strictEqual(exportNameSet.has('outterElement2'), true);
685      assert.strictEqual(exportNameSet.has('o2'), true);
686      assert.strictEqual(exportNameAndPropSet.has('TestClass'), true);
687      assert.strictEqual(exportNameAndPropSet.has('prop1'), true);
688      assert.strictEqual(exportNameAndPropSet.has('prop2'), true);
689      assert.strictEqual(exportNameAndPropSet.has('objProp'), true);
690      assert.strictEqual(exportNameAndPropSet.has('innerProp2'), true);
691      assert.strictEqual(exportNameAndPropSet.has('var1'), true);
692      assert.strictEqual(exportNameAndPropSet.has('var2'), false);
693      assert.strictEqual(exportNameAndPropSet.has('foo'), true);
694      assert.strictEqual(exportNameAndPropSet.has('ns'), false);
695      assert.strictEqual(exportNameAndPropSet.has('var3'), true);
696      assert.strictEqual(exportNameAndPropSet.has('nsFunction'), true);
697      assert.strictEqual(exportNameAndPropSet.has('TestInterface'), true);
698      assert.strictEqual(exportNameAndPropSet.has('feature1'), true);
699      assert.strictEqual(exportNameAndPropSet.has('feature2'), true);
700      assert.strictEqual(exportNameAndPropSet.has('TestClass2'), false);
701      assert.strictEqual(exportNameAndPropSet.has('prop4'), false);
702      assert.strictEqual(exportNameAndPropSet.has('propObj'), false);
703      assert.strictEqual(exportNameAndPropSet.has('innerProp'), false);
704      assert.strictEqual(exportNameAndPropSet.has('TestClass3'), false);
705      assert.strictEqual(exportNameAndPropSet.has('exportProp1'), true);
706      assert.strictEqual(exportNameAndPropSet.has('exportPropObj'), true);
707      assert.strictEqual(exportNameAndPropSet.has('exportInnerProp'), true);
708      assert.strictEqual(exportNameAndPropSet.has('v2'), true);
709      assert.strictEqual(exportNameAndPropSet.has('default'), true);
710      assert.strictEqual(exportNameAndPropSet.has('t3'), true);
711      assert.strictEqual(exportNameAndPropSet.has('outterElement1'), true);
712      assert.strictEqual(exportNameAndPropSet.has('outterElement2'), false);
713      assert.strictEqual(exportNameAndPropSet.has('o2'), true);
714      const fileWhiteList: FileWhiteList = projectWhiteListManager!.getFileWhiteListMap().get(filePath)!;
715      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('TestClass')).to.be.true;
716      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('prop1')).to.be.false;
717      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('prop2')).to.be.false;
718      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('objProp')).to.be.false;
719      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('innerProp2')).to.be.false;
720      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('var1')).to.be.true;
721      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('var2')).to.be.false;
722      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('foo')).to.be.true;
723      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('ns')).to.be.false;
724      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('var3')).to.be.true;
725      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('nsFunction')).to.be.true;
726      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('TestInterface')).to.be.true;
727      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('feature1')).to.be.false;
728      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('feature2')).to.be.false;
729      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('TestClass2')).to.be.false;
730      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('prop4')).to.be.false;
731      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('propObj')).to.be.false;
732      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('innerProp')).to.be.false;
733      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('TestClass3')).to.be.false;
734      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('exportProp1')).to.be.false;
735      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('exportPropObj')).to.be.false;
736      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('exportInnerProp')).to.be.false;
737      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('v2')).to.be.true;
738      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('default')).to.be.true;
739      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('t3')).to.be.true;
740      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('outterElement1')).to.be.true;
741      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('outterElement2')).to.be.true;
742      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('o2')).to.be.true;
743      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('TestClass')).to.be.true;
744      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('prop1')).to.be.true;
745      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('prop2')).to.be.true;
746      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('objProp')).to.be.true;
747      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('innerProp2')).to.be.true;
748      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('var1')).to.be.true;
749      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('var2')).to.be.false;
750      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('foo')).to.be.true;
751      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('ns')).to.be.false;
752      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('var3')).to.be.true;
753      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('nsFunction')).to.be.true;
754      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('TestInterface')).to.be.true;
755      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('feature1')).to.be.true;
756      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('feature2')).to.be.true;
757      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('TestClass2')).to.be.false;
758      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('prop4')).to.be.false;
759      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('propObj')).to.be.false;
760      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('innerProp')).to.be.false;
761      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('TestClass3')).to.be.false;
762      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('exportProp1')).to.be.true;
763      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('exportPropObj')).to.be.true;
764      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('exportInnerProp')).to.be.true;
765      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('v2')).to.be.true;
766      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('default')).to.be.true;
767      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('t3')).to.be.true;
768      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('outterElement1')).to.be.true;
769      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('outterElement2')).to.be.false;
770      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('o2')).to.be.true;
771    });
772
773    it('oh_modules test', function () {
774      const filePath = 'test/ut/utils/oh_modules/exportFile1.ts'
775      const ohModulesFileList: Set<string> = new Set([filePath]);
776      let config: IOptions = {
777        mNameObfuscation : {
778          mEnable: true,
779          mReservedProperties: [],
780          mRenameProperties: true,
781          mKeepStringProperty: false,
782          mTopLevel: true,
783          mNameGeneratorType: NameGeneratorType.ORDERED,
784          mReservedNames: [],
785          mReservedToplevelNames: []
786        }
787      };
788      let cachePath = 'test/ut/utils/obfuscation';
789      initProjectWhiteListManager(cachePath, false, false);
790      let projectAndLibs: ReseverdSetForArkguard =
791        readProjectPropertiesByCollectedPaths(ohModulesFileList,
792        {
793          mNameObfuscation: config.mNameObfuscation,
794          mExportObfuscation: true,
795          mKeepFileSourceCode: {
796            mKeepSourceOfPaths: new Set(),
797            mkeepFilesAndDependencies: new Set(),
798          }
799        }, true);
800      let exportNameAndPropSet = projectAndLibs.exportNameAndPropSet;
801      let exportNameSet = projectAndLibs.exportNameSet;
802      assert.strictEqual(exportNameSet.has('ModuleNs'), true);
803      assert.strictEqual(exportNameSet.has('nsProp1'), true);
804      assert.strictEqual(exportNameSet.has('nsFunc'), true);
805      assert.strictEqual(exportNameSet.has('ModuleClass'), true);
806      assert.strictEqual(exportNameSet.has('classProp1'), false);
807      assert.strictEqual(exportNameSet.has('objProp'), false);
808      assert.strictEqual(exportNameSet.has('innerProp'), false);
809      assert.strictEqual(exportNameSet.has('TestClass'), false);
810      assert.strictEqual(exportNameSet.has('prop4'), false);
811      assert.strictEqual(exportNameSet.has('propObj'), false);
812      assert.strictEqual(exportNameSet.has('innerProp1'), false);
813      assert.strictEqual(exportNameSet.has('TestClass2'), true);
814      assert.strictEqual(exportNameSet.has('prop1'), false);
815      assert.strictEqual(exportNameSet.has('objProp1'), false);
816      assert.strictEqual(exportNameSet.has('innerProp2'), false);
817      assert.strictEqual(exportNameSet.has('default'), true);
818      assert.strictEqual(exportNameSet.has('mc'), true);
819      assert.strictEqual(exportNameSet.has('otherElement1'), true);
820      assert.strictEqual(exportNameSet.has('otherElement2'), true);
821      assert.strictEqual(exportNameSet.has('o2'), true);
822      assert.strictEqual(exportNameAndPropSet.has('ModuleNs'), false);
823      assert.strictEqual(exportNameAndPropSet.has('nsProp1'), true);
824      assert.strictEqual(exportNameAndPropSet.has('nsFunc'), true);
825      assert.strictEqual(exportNameAndPropSet.has('ModuleClass'), false);
826      assert.strictEqual(exportNameAndPropSet.has('classProp1'), true);
827      assert.strictEqual(exportNameAndPropSet.has('objProp'), true);
828      assert.strictEqual(exportNameAndPropSet.has('innerProp'), true);
829      assert.strictEqual(exportNameAndPropSet.has('TestClass'), false);
830      assert.strictEqual(exportNameAndPropSet.has('prop4'), false);
831      assert.strictEqual(exportNameAndPropSet.has('propObj'), false);
832      assert.strictEqual(exportNameAndPropSet.has('innerProp1'), false);
833      assert.strictEqual(exportNameAndPropSet.has('TestClass2'), true);
834      assert.strictEqual(exportNameAndPropSet.has('prop1'), true);
835      assert.strictEqual(exportNameAndPropSet.has('objProp1'), true);
836      assert.strictEqual(exportNameAndPropSet.has('innerProp2'), true);
837      assert.strictEqual(exportNameAndPropSet.has('default'), true);
838      assert.strictEqual(exportNameAndPropSet.has('mc'), true);
839      assert.strictEqual(exportNameAndPropSet.has('otherElement1'), true);
840      assert.strictEqual(exportNameAndPropSet.has('otherElement2'), false);
841      assert.strictEqual(exportNameAndPropSet.has('o2'), true);
842      const fileWhiteList: FileWhiteList = projectWhiteListManager!.getFileWhiteListMap().get(filePath)!;
843      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('ModuleNs')).to.be.true;
844      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('nsProp1')).to.be.true;
845      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('nsFunc')).to.be.true;
846      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('ModuleClass')).to.be.true;
847      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('classProp1')).to.be.false;
848      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('objProp')).to.be.false;
849      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('innerProp')).to.be.false;
850      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('TestClass')).to.be.false;
851      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('prop4')).to.be.false;
852      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('propObj')).to.be.false;
853      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('innerProp1')).to.be.false;
854      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('TestClass2')).to.be.true;
855      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('prop1')).to.be.false;
856      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('objProp1')).to.be.false;
857      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('innerProp2')).to.be.false;
858      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('default')).to.be.true;
859      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('mc')).to.be.true;
860      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('otherElement1')).to.be.true;
861      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('otherElement2')).to.be.true;
862      expect(fileWhiteList.fileKeepInfo.exported.globalNames.has('o2')).to.be.true;
863      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('ModuleNs')).to.be.false;
864      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('nsProp1')).to.be.true;
865      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('nsFunc')).to.be.true;
866      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('ModuleClass')).to.be.false;
867      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('classProp1')).to.be.true;
868      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('objProp')).to.be.true;
869      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('innerProp')).to.be.true;
870      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('TestClass')).to.be.false;
871      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('prop4')).to.be.false;
872      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('propObj')).to.be.false;
873      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('innerProp1')).to.be.false;
874      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('TestClass2')).to.be.true;
875      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('prop1')).to.be.true;
876      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('objProp1')).to.be.true;
877      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('innerProp2')).to.be.true;
878      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('default')).to.be.true;
879      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('mc')).to.be.true;
880      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('otherElement1')).to.be.true;
881      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('otherElement2')).to.be.false;
882      expect(fileWhiteList.fileKeepInfo.exported.propertyNames.has('o2')).to.be.true;
883    });
884    it('decorate collect test', function () {
885      const filePath = 'test/ut/utils/apiTest_collectFileWhiteList/collectFileWhiteList02.ets'
886      const fileList: Set<string> = new Set([filePath]);
887      let config: IOptions = {
888        mNameObfuscation: {
889          mEnable: true,
890          mReservedProperties: [],
891          mRenameProperties: true,
892          mKeepStringProperty: false,
893          mTopLevel: false,
894          mNameGeneratorType: NameGeneratorType.ORDERED,
895          mReservedNames: [],
896          mReservedToplevelNames: []
897        }
898      };
899      let cachePath = 'test/ut/utils/obfuscation';
900      initProjectWhiteListManager(cachePath, false, false);
901      let projectAndLibs: ReseverdSetForArkguard =
902        readProjectPropertiesByCollectedPaths(fileList,
903          {
904            mNameObfuscation: config.mNameObfuscation,
905            mExportObfuscation: true,
906            mKeepFileSourceCode: {
907              mKeepSourceOfPaths: new Set(),
908              mkeepFilesAndDependencies: new Set(),
909            }
910          }, true, true);
911      const fileWhiteList: FileWhiteList = projectWhiteListManager!.getFileWhiteListMap().get(filePath)!;
912      if (fileWhiteList?.bytecodeObfuscateKeepInfo?.decoratorMap) {
913        const decoratorKeys = Object.keys(fileWhiteList.bytecodeObfuscateKeepInfo.decoratorMap);
914        expect(decoratorKeys.length).to.be.greaterThan(0);
915      }
916    });
917  });
918
919  describe('test initScanProjectConfig', function () {
920    it('scanDecorator is false', function () {
921      let customProfiles = {}
922      initScanProjectConfig(customProfiles, false, false)
923      expect(scanProjectConfig.scanDecorator).to.be.false;
924    });
925
926    it('scanDecorator is default', function () {
927      let customProfiles = {}
928      initScanProjectConfig(customProfiles, false)
929      expect(scanProjectConfig.scanDecorator).to.be.false;
930    });
931
932    it('scanDecorator is true', function () {
933      let customProfiles = {}
934      initScanProjectConfig(customProfiles, false, true)
935      expect(scanProjectConfig.scanDecorator).to.be.true;
936    });
937  });
938});