Added more tests

This commit is contained in:
sanex3339
2020-02-13 02:10:39 +03:00
parent 89e8a2452a
commit ca1545bffd
4 changed files with 94 additions and 3765 deletions
@@ -3,6 +3,7 @@ import { assert } from 'chai';
import { TInputOptions } from '../../src/types/options/TInputOptions';
import { StringArrayEncoding } from '../../src/enums/StringArrayEncoding';
import { IdentifierNamesGenerator } from '../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator';
import { readFileAsString } from '../helpers/readFileAsString';
@@ -36,107 +37,110 @@ describe('JavaScriptObfuscator runtime eval', function () {
this.timeout(100000);
describe('Astring', () => {
let obfuscatedCode: string;
[
IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator,
IdentifierNamesGenerator.MangledIdentifierNamesGenerator
].forEach((identifierNamesGenerator) => {
describe(`Astring. Identifier names generator: ${identifierNamesGenerator}`, () => {
it('should obfuscate code without any runtime errors after obfuscation: Variant #1 astring', () => {
const code: string = readFileAsString(__dirname + '/fixtures/astring.js');
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/astring.js');
const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
code,
{
...options,
identifierNamesGenerator
}
).getObfuscatedCode();
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
options
).getObfuscatedCode();
});
it('should obfuscate code without any runtime errors after obfuscation: Variant #1 astring', () => {
assert.equal(
eval(`
${getEnvironmentCode()}
${obfuscatedCode}
const code = generate({
"type": "Program",
"body": [
{
"type": "FunctionDeclaration",
"id": {
"type": "Identifier",
"name": "test",
"range": [
9,
13
]
},
"params": [],
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ReturnStatement",
"argument": {
"type": "Literal",
"value": "foo",
"raw": "'foo'",
"range": [
30,
35
]
},
"range": [
23,
36
]
}
],
"range": [
17,
38
]
},
"generator": false,
"expression": false,
"async": false,
assert.equal(
eval(`
${getEnvironmentCode()}
${obfuscatedCode}
const code = generate({
"type": "Program",
"body": [
{
"type": "FunctionDeclaration",
"id": {
"type": "Identifier",
"name": "test",
"range": [
0,
9,
13
]
},
"params": [],
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ReturnStatement",
"argument": {
"type": "Literal",
"value": "foo",
"raw": "'foo'",
"range": [
30,
35
]
},
"range": [
23,
36
]
}
],
"range": [
17,
38
]
}
],
"sourceType": "module",
"range": [
0,
38
],
"comments": []
});
eval(\`\${code} test();\`);
`),
'foo'
);
});
});
describe('Sha256', () => {
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/sha256.js');
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
options
).getObfuscatedCode();
},
"generator": false,
"expression": false,
"async": false,
"range": [
0,
38
]
}
],
"sourceType": "module",
"range": [
0,
38
],
"comments": []
});
eval(\`\${code} test();\`);
`),
'foo'
);
});
});
it('should obfuscate code without any runtime errors after obfuscation: Variant #2 sha256', () => {
assert.equal(
eval(`
describe(`Sha256. Identifier names generator: ${identifierNamesGenerator}`, () => {
it('should obfuscate code without any runtime errors after obfuscation: Variant #2 sha256', () => {
const code: string = readFileAsString(__dirname + '/fixtures/sha256.js');
const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
code,
{
...options,
identifierNamesGenerator
}
).getObfuscatedCode();
assert.equal(
eval(`
${getEnvironmentCode()}
${obfuscatedCode}
sha256('test');
`),
'9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08'
);
'9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08'
);
});
});
});
});