-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathTest_ClickNLoad2text.py
More file actions
executable file
·109 lines (87 loc) · 2.68 KB
/
Test_ClickNLoad2text.py
File metadata and controls
executable file
·109 lines (87 loc) · 2.68 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python3
import unittest
import threading
import http.server
import urllib.parse
import urllib.request
import re
import ClickNLoad2text
class CNLHandlerTest(unittest.TestCase):
@classmethod
def setUpClass(clazz):
ip, port = "localhost", 0 # port 0 -> random unused port
clazz.httpd = http.server.HTTPServer((ip, port), ClickNLoad2text.CNLHandler)
server_thread = threading.Thread(target=clazz.httpd.serve_forever)
# Exit the server thread when the main thread terminates
server_thread.daemon = True
server_thread.start()
#
# GET
#
def test_alive(self):
output = self.client("")
self.assertEqual(output, "JDownloader")
def test_jdcheck(self):
output = self.client("jdcheck.js")
pattern = re.compile(r"jdownloader\s*=\s*true", re.IGNORECASE)
self.assertIsNotNone(pattern.search(output))
@unittest.skip("")
def test_crossdomain(self):
pass
#
# POST
#
def test_add(self):
params = {
"passwords" : "myPassword",
"source" : "http://jdownloader.org/spielwiese",
"urls" : "http://www.rapidshare.com/files/407970280/RapidShareManager2WindowsSetup.exe",
}
actual = self.client("flash/add", params)
expected = ClickNLoad2text.format_package(
"http://jdownloader.org/spielwiese",
["http://www.rapidshare.com/files/407970280/RapidShareManager2WindowsSetup.exe"],
"myPassword"
)
self.assertEqual(actual, expected)
@unittest.skip("Click'N'Load 1")
def test_addcrypted(self):
pass
def test_addcrypted2(self):
params = {
"passwords" : "myPassword",
"source" : "http://jdownloader.org/spielwiese",
"jk" : "function f() { return '31323334353637383930393837363534'; }",
"crypted" : "DRurBGEf2ntP7Z0WDkMP8e1ZeK7PswJGeBHCg4zEYXZSE3Qqxsbi5EF1KosgkKQ9SL8qOOUAI+eDPFypAtQS9A==",
}
actual = self.client("flash/addcrypted2", params)
expected = ClickNLoad2text.format_package(
"http://jdownloader.org/spielwiese",
["http://rapidshare.com/files/285626259/jDownloader.dmg"],
"myPassword"
)
self.assertEqual(actual, expected)
@unittest.skip("")
def test_flashgot(self):
pass
def client(self, path, params=None):
ENCODING = 'utf-8'
url = "http://{}:{}/{}".format(
self.httpd.server_address[0],
self.httpd.server_address[1],
path
)
if params is not None:
headers = {
"Content-Type": "application/x-www-form-urlencoded;charset={}".format(ENCODING),
}
request = urllib.request.Request(url, urllib.parse.urlencode(params).encode(ENCODING), headers)
else:
request = urllib.request.Request(url)
with urllib.request.urlopen(request) as f:
return f.read().decode(ENCODING)
@classmethod
def tearDownClass(clazz):
clazz.httpd.shutdown()
if __name__ == "__main__":
unittest.main()