2022-12-25 17:47:46 +04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2022-03-25 16:45:38 +04:00
|
|
|
import unittest
|
|
|
|
|
2022-03-17 10:24:58 +04:00
|
|
|
from python_aternos import atjsparse
|
2022-10-19 18:40:09 +04:00
|
|
|
from tests import files
|
2021-11-01 18:04:19 +04:00
|
|
|
|
2022-08-22 09:55:08 +04:00
|
|
|
CONV_TOKEN_ARROW = '''(() => {/*AJAX_TOKEN=123}*/window["AJAX_TOKEN"]=("2r" + "KO" + "A1" + "IFdBcHhEM" + "61" + "6cb");})();'''
|
2022-07-01 14:28:39 +04:00
|
|
|
CONV_TOKEN_FUNC = '''(function(){window["AJAX_TOKEN"]=("2r" + "KO" + "A1" + "IFdBcHhEM" + "61" + "6cb");})()'''
|
2022-06-23 15:13:56 +04:00
|
|
|
|
|
|
|
|
2022-03-25 16:45:38 +04:00
|
|
|
class TestJs2Py(unittest.TestCase):
|
|
|
|
|
2022-06-23 15:13:56 +04:00
|
|
|
def setUp(self) -> None:
|
|
|
|
|
2022-10-19 18:40:09 +04:00
|
|
|
self.tests = files.read_sample('token_input.txt')
|
|
|
|
self.results = files.read_sample('token_output.txt')
|
2022-12-25 12:49:27 +04:00
|
|
|
self.js = atjsparse.Js2PyInterpreter()
|
2022-06-23 15:13:56 +04:00
|
|
|
|
|
|
|
def test_base64(self) -> None:
|
|
|
|
|
|
|
|
encoded = 'QEhlbGxvIFdvcmxkIQ=='
|
|
|
|
decoded = atjsparse.atob(encoded)
|
|
|
|
self.assertEqual(decoded, '@Hello World!')
|
|
|
|
|
|
|
|
def test_conv(self) -> None:
|
|
|
|
|
|
|
|
token = CONV_TOKEN_ARROW
|
2022-12-25 12:49:27 +04:00
|
|
|
f = self.js.to_ecma5(token)
|
2022-06-23 15:13:56 +04:00
|
|
|
self.assertEqual(f, CONV_TOKEN_FUNC)
|
|
|
|
|
|
|
|
def test_ecma6parse(self) -> None:
|
|
|
|
|
|
|
|
code = '''
|
|
|
|
window.t0 =
|
|
|
|
window['document']&&
|
|
|
|
!window[["p","Ma"].reverse().join('')]||
|
|
|
|
!window[["ut","meo","i","etT","s"].reverse().join('')];'''
|
|
|
|
|
|
|
|
part1 = '''window.t1 = Boolean(window['document']);'''
|
|
|
|
part2 = '''window.t2 = Boolean(!window[["p","Ma"].reverse().join('')]);'''
|
|
|
|
part3 = '''window.t3 = Boolean(!window[["ut","meo","i","etT","s"].reverse().join('')]);'''
|
|
|
|
|
2022-12-25 12:49:27 +04:00
|
|
|
self.js.exec_js(code)
|
|
|
|
self.js.exec_js(part1)
|
|
|
|
self.js.exec_js(part2)
|
|
|
|
self.js.exec_js(part3)
|
2022-06-23 15:13:56 +04:00
|
|
|
|
2022-12-25 12:49:27 +04:00
|
|
|
self.assertEqual(self.js['t0'], False)
|
|
|
|
self.assertEqual(self.js['t1'], True)
|
|
|
|
self.assertEqual(self.js['t2'], False)
|
|
|
|
self.assertEqual(self.js['t3'], False)
|
2022-06-23 15:13:56 +04:00
|
|
|
|
|
|
|
def test_exec(self) -> None:
|
|
|
|
|
2022-12-25 17:45:22 +04:00
|
|
|
for func, exp in zip(self.tests, self.results):
|
|
|
|
self.js.exec_js(func)
|
2022-12-25 12:49:27 +04:00
|
|
|
res = self.js['AJAX_TOKEN']
|
2022-12-25 17:45:22 +04:00
|
|
|
self.assertEqual(res, exp)
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|