DomainLockNode.spec.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { assert } from 'chai';
  2. import { IObfuscationResult } from '../../../../src/interfaces/IObfuscationResult';
  3. import { NO_CUSTOM_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes';
  4. import { readFileAsString } from '../../../helpers/readFileAsString';
  5. import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscator';
  6. describe('DomainLockNode', () => {
  7. const regExp: RegExp = /var _0x([a-f0-9]){4,6} *= *new RegExp/;
  8. describe('`domainLock` option is set', () => {
  9. let obfuscatedCode: string;
  10. before(() => {
  11. const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js');
  12. const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
  13. code,
  14. {
  15. ...NO_CUSTOM_NODES_PRESET,
  16. domainLock: ['.example.com']
  17. }
  18. );
  19. obfuscatedCode = obfuscationResult.getObfuscatedCode();
  20. });
  21. it('should correctly append custom node into the obfuscated code', () => {
  22. assert.match(obfuscatedCode, regExp);
  23. });
  24. });
  25. describe('`domainLock` option isn\'t set', () => {
  26. let obfuscatedCode: string;
  27. before(() => {
  28. const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js');
  29. const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
  30. code,
  31. {
  32. ...NO_CUSTOM_NODES_PRESET,
  33. domainLock: []
  34. }
  35. );
  36. obfuscatedCode = obfuscationResult.getObfuscatedCode();
  37. });
  38. it('shouldn\'t append custom node into the obfuscated code', () => {
  39. assert.notMatch(obfuscatedCode, regExp);
  40. });
  41. });
  42. });