DomainLockNode.spec.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  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. it('should correctly append `DomainLockNode` custom node into the obfuscated code if `domainLock` option is set', () => {
  8. let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
  9. readFileAsString(__dirname + '/fixtures/simple-input.js'),
  10. {
  11. ...NO_CUSTOM_NODES_PRESET,
  12. domainLock: ['.example.com']
  13. }
  14. );
  15. assert.match(obfuscationResult.getObfuscatedCode(), /var _0x([a-z0-9]){4,6} *= *new RegExp/);
  16. });
  17. it('should\'t append `DomainLockNode` custom node into the obfuscated code if `domainLock` option is not set', () => {
  18. let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
  19. readFileAsString(__dirname + '/fixtures/simple-input.js'),
  20. {
  21. ...NO_CUSTOM_NODES_PRESET,
  22. domainLock: []
  23. }
  24. );
  25. assert.notMatch(obfuscationResult.getObfuscatedCode(), /var _0x([a-z0-9]){4,6} *= *new RegExp/);
  26. });
  27. });