DomainLockNode.spec.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. import { assert } from 'chai';
  2. import { IObfuscationResult } from '../../../../src/interfaces/IObfuscationResult';
  3. import { NO_CUSTOM_NODES_PRESET } from '../../../../src/preset-options/NoCustomNodesPreset';
  4. import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscator';
  5. describe('DomainLockNode', () => {
  6. it('should correctly append `DomainLockNode` custom node into the obfuscated code if `domainLock` option is set', () => {
  7. let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
  8. `var test = 'test';`,
  9. {
  10. ...NO_CUSTOM_NODES_PRESET,
  11. domainLock: ['.example.com']
  12. }
  13. );
  14. assert.match(obfuscationResult.getObfuscatedCode(), /var _0x([a-z0-9]){4,6} *= *new RegExp/);
  15. });
  16. it('should\'t append `DomainLockNode` custom node into the obfuscated code if `domainLock` option is not set', () => {
  17. let obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
  18. `var test = 'test';`,
  19. {
  20. ...NO_CUSTOM_NODES_PRESET,
  21. domainLock: []
  22. }
  23. );
  24. assert.notMatch(obfuscationResult.getObfuscatedCode(), /var _0x([a-z0-9]){4,6} *= *new RegExp/);
  25. });
  26. });