DomainLockNode.spec.ts 1.3 KB

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