StringArrayCodeHelperGroup.spec.ts 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { assert } from 'chai';
  2. import { StringArrayEncoding } from '../../../../../src/enums/node-transformers/string-array-transformers/StringArrayEncoding';
  3. import { IdentifierNamesGenerator } from '../../../../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator';
  4. import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
  5. import { getRegExpMatch } from '../../../../helpers/getRegExpMatch';
  6. import { readFileAsString } from '../../../../helpers/readFileAsString';
  7. import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscatorFacade';
  8. describe('StringArrayCodeHelperGroup', () => {
  9. const regExp: RegExp = new RegExp(
  10. 'function *\\w *\\(\\w, *\\w\\) *{.*return \\w;}.*' +
  11. 'function *\\w *\\(\\w, *\\w\\) *{.*return \\w;}.*' +
  12. 'function *\\w *\\(\\w, *\\w\\) *{.*return \\w;}'
  13. );
  14. const stringArrayCallsWrapperRegExp: RegExp = new RegExp(
  15. `function *(\\w) *\\(\\w, *\\w\\) *{.*return \\w;}.*`
  16. );
  17. describe('StringArrayCallsWrapper code helper names', function () {
  18. this.timeout(10000);
  19. const stringArrayCallsWrapperNames: Set<string> = new Set();
  20. const samplesCount: number = 30;
  21. let obfuscatedCode: string;
  22. const expectedUniqStringArrayCallsWrapperNamesCount: number = 3;
  23. before(() => {
  24. const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js');
  25. for (let i = 0; i < samplesCount; i++) {
  26. obfuscatedCode = JavaScriptObfuscator.obfuscate(
  27. code,
  28. {
  29. ...NO_ADDITIONAL_NODES_PRESET,
  30. identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator,
  31. stringArray: true,
  32. stringArrayThreshold: 1,
  33. stringArrayEncoding: [
  34. StringArrayEncoding.None,
  35. StringArrayEncoding.Base64,
  36. StringArrayEncoding.Rc4
  37. ]
  38. }
  39. ).getObfuscatedCode();
  40. const callsWrapperName: string = getRegExpMatch(obfuscatedCode, stringArrayCallsWrapperRegExp);
  41. stringArrayCallsWrapperNames.add(callsWrapperName);
  42. }
  43. });
  44. it('should correct place all StringArrayCallsWrapper code helpers', () => {
  45. assert.match(obfuscatedCode, regExp);
  46. });
  47. it('should place multiple StringArrayCallsWrapper code helper names in the random order', () => {
  48. assert.equal(stringArrayCallsWrapperNames.size, expectedUniqStringArrayCallsWrapperNamesCount);
  49. });
  50. });
  51. });