forked from javascript-obfuscator/javascript-obfuscator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaScriptObfuscator.spec.ts
More file actions
55 lines (48 loc) · 1.96 KB
/
JavaScriptObfuscator.spec.ts
File metadata and controls
55 lines (48 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { JavaScriptObfuscator } from "../src/JavaScriptObfuscator";
import { NO_CUSTOM_NODES_PRESET } from "../src/preset-options/NoCustomNodesPreset";
let assert: any = require('chai').assert;
describe('JavaScriptObfuscator', () => {
describe('obfuscate (sourceCode: string, customOptions?: IOptionsPreset): string', () => {
it('should obfuscate simple code with variable inside global scope', () => {
assert.match(
JavaScriptObfuscator.obfuscate(
`var test = 1;`,
Object.assign({}, NO_CUSTOM_NODES_PRESET)
),
/^var *test *= *0x\d+;$/
);
});
it('should obfuscate simple code with variable inside block-scope', () => {
assert.match(
JavaScriptObfuscator.obfuscate(
`(function () {var test = 1;})()`,
Object.assign({}, NO_CUSTOM_NODES_PRESET)
),
/^\(function *\(\) *\{ *var *_0x[\w]+ *= *0x\d+; *\}(\(\)\)|\)\(\));?$/
);
});
it('should obfuscate simple code with literal variable value', () => {
let pattern = /^var _0x(\w){4} *= *\['(\\[x|u]\d+)+'\]; *var *test *= *_0x(\w){4}\[0x0\];$/;
assert.match(
JavaScriptObfuscator.obfuscate(
`var test = 'abc';`,
Object.assign({}, NO_CUSTOM_NODES_PRESET, {
unicodeArray: true,
unicodeArrayThreshold: 1
})
),
pattern
);
assert.match(
JavaScriptObfuscator.obfuscate(
`var test = 'абц';`,
Object.assign({}, NO_CUSTOM_NODES_PRESET, {
unicodeArray: true,
unicodeArrayThreshold: 1
})
),
pattern
);
});
});
});