summaryrefslogtreecommitdiff
path: root/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests/testmyobfuscate.py
blob: d69df82b86619a968b05be74a48966bd5fb2b24c (plain)
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
#
#     written by Stefano Sanfilippo <a.little.coder@gmail.com>
#

"""Tests for MyObfuscate unpacker."""

import unittest
import os
from jsbeautifier.unpackers.myobfuscate import detect, unpack
from jsbeautifier.unpackers.tests import __path__ as path

INPUT = os.path.join(path[0], "test-myobfuscate-input.js")
OUTPUT = os.path.join(path[0], "test-myobfuscate-output.js")

# pylint: disable=R0904


class TestMyObfuscate(unittest.TestCase):
    # pylint: disable=C0103
    """MyObfuscate obfuscator testcase."""

    @classmethod
    def setUpClass(cls):
        """Load source files (encoded and decoded version) for tests."""
        with open(INPUT, "r") as data:
            cls.input = data.read()
        with open(OUTPUT, "r") as data:
            cls.output = data.read()

    def test_detect(self):
        """Test detect() function."""

        def detected(source):
            return self.assertTrue(detect(source))

        detected(self.input)

    def test_unpack(self):
        """Test unpack() function."""

        def check(inp, out):
            return self.assertEqual(unpack(inp), out)

        check(self.input, self.output)


if __name__ == "__main__":
    unittest.main()