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