corrade-nucleus-nucleons – Blame information for rev 4
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
2 | office | 1 | # |
2 | # written by Stefano Sanfilippo <a.little.coder@gmail.com> |
||
3 | # |
||
4 | |||
5 | """Tests for JavaScriptObfuscator unpacker.""" |
||
6 | |||
7 | import unittest |
||
8 | from jsbeautifier.unpackers.javascriptobfuscator import ( |
||
9 | unpack, detect, smartsplit) |
||
10 | |||
11 | # pylint: disable=R0904 |
||
12 | class TestJavascriptObfuscator(unittest.TestCase): |
||
13 | """JavascriptObfuscator.com test case.""" |
||
14 | def test_smartsplit(self): |
||
15 | """Test smartsplit() function.""" |
||
16 | split = smartsplit |
||
17 | equals = lambda data, result: self.assertEqual(split(data), result) |
||
18 | |||
19 | equals('', []) |
||
20 | equals('"a", "b"', ['"a"', '"b"']) |
||
21 | equals('"aaa","bbbb"', ['"aaa"', '"bbbb"']) |
||
22 | equals('"a", "b\\\""', ['"a"', '"b\\\""']) |
||
23 | |||
24 | def test_detect(self): |
||
25 | """Test detect() function.""" |
||
26 | positive = lambda source: self.assertTrue(detect(source)) |
||
27 | negative = lambda source: self.assertFalse(detect(source)) |
||
28 | |||
29 | negative('') |
||
30 | negative('abcd') |
||
31 | negative('var _0xaaaa') |
||
32 | positive('var _0xaaaa = ["a", "b"]') |
||
33 | positive('var _0xaaaa=["a", "b"]') |
||
34 | positive('var _0x1234=["a","b"]') |
||
35 | |||
36 | def test_unpack(self): |
||
37 | """Test unpack() function.""" |
||
38 | decodeto = lambda ob, original: self.assertEqual(unpack(ob), original) |
||
39 | |||
40 | decodeto('var _0x8df3=[];var a=10;', 'var a=10;') |
||
41 | decodeto('var _0xb2a7=["\x74\x27\x65\x73\x74"];var i;for(i=0;i<10;++i)' |
||
42 | '{alert(_0xb2a7[0]);} ;', 'var i;for(i=0;i<10;++i){alert' |
||
43 | '("t\'est");} ;') |
||
44 | |||
45 | if __name__ == '__main__': |
||
46 | unittest.main() |