test_flask.py
3.99 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import os, time, requests, ipdb, json, threading
URL = "http://192.168.15.75:5000/"
TESTPHONE = "5493415959169"
TESTMAIL = "sujetodeprueba0110@gmail.com"
FOLDER = "testfolder/"
SENDING_TIME = 60 # aumentar a medida que se vuelva necesario
def wpp1(phone):
id = requests.post(url = URL + "data", files = {
'wpmsg' : open(FOLDER + "wptext","rb"),
'wpimage' : open(FOLDER + "wpimage","rb"),
'wpmedia' : open(FOLDER + "wpmedia","rb"),
'wplink' : open(FOLDER + "wplink","rb")
})
assert int(id.text) > 0 , id.text + "no es mayor a 0"
state = requests.post(url = URL + "msg", params = {
'id' : id.text,
'serv' : "wpp1",
'dest' : phone,
'type' : json.dumps({
'wptext' : 'text',
'wpimage' : 'image',
'wpmedia' : 'document',
'wplink' : 'link'
})
})
assert state.text == "queued" , "'" + state.text + "' no es igual a 'queued'"
time.sleep(SENDING_TIME)
state = requests.post(url = URL + "cons", params = {
'id' : id.text
})
assert (state.text == "delivered") , "'" + state.text + "' no es igual a 'delivered'"
def mail(mail):
id = requests.post(url = URL + "data", files = {
'mailmsg' : open(FOLDER + "mailtext","rb"),
'mailimage' : open(FOLDER + "mailimage","rb"),
'maildocument' : open(FOLDER + "maildocument","rb")
})
assert int(id.text) > 0 , id.text + "no es mayor a 0"
state = requests.post(url = URL + "msg", params = {
'id' : id.text,
'serv' : "mail",
'dest' : mail,
'type' : json.dumps({
'mailtext' : 'text',
'mailimage' : 'image',
'maildocument' : 'document'
})
})
assert state.text == "queued" , "'" + state.text + "' no es igual a 'queued'"
time.sleep(SENDING_TIME)
state = requests.post(url = URL + "cons", params = {
'id' : id.text
})
assert (state.text == "delivered") , "'" + state.text + "' no es igual a 'delivered'"
def encryption(phone):
key = requests.get(url = URL + "key")
f = open(FOLDER + "server_rsa_key.pub", "+w")
f.write(key.text)
f.close()
os.system("openssl rand -base64 32 > " + FOLDER + "rand.key")
os.system("openssl enc -aes-256-cbc -salt -in " + FOLDER + "plaintext" " -out " + FOLDER + "plaintext.enc -pass file:" + FOLDER + "rand.key")
os.system("openssl enc -aes-256-cbc -salt -in " + FOLDER + "plainimage" " -out " + FOLDER + "plainimage.enc -pass file:" + FOLDER + "rand.key")
os.system("openssl rsautl -encrypt -inkey " + FOLDER + "server_rsa_key.pub -pubin -in " + FOLDER + "rand.key -out " + FOLDER + "rand.key.enc")
id = requests.post(url = URL + "data", files = {
'plaintext.enc' : open(FOLDER + "plaintext.enc","rb"),
'plainimage.enc' : open(FOLDER + "plainimage.enc","rb")
})
assert int(id.text) > 0 , id.text + "no es mayor a 0"
state = requests.post(url = URL + "msg", params = {
'id' : id.text,
'serv' : "wpp1",
'dest' : phone,
'type' : json.dumps({
'plaintext' : 'text',
'plainimage' : 'image'
})
})
assert state.text == "queued" , "'" + state.text + "' no es igual a 'queued'"
time.sleep(SENDING_TIME)
state = requests.post(url = URL + "cons", params = {
'id' : id.text
})
assert (state.text == "delivered") , "'" + state.text + "' no es igual a 'delivered'"
def errors():
# service not valid
# service unable to send type
# trying to set type of unexistent file
# trying to user unexistent table
# ill-formed comparator
# data doesn't pass the checks
def main():
if os.path.exists("messages.db"):
os.remove("messages.db")
try:
os.system("python3 deploy.py &")
time.sleep(3)
threads = []
threads.append(threading.Thread(target = wpp1, args = (TESTPHONE,)))
threads.append(threading.Thread(target = encryption, args = (TESTPHONE,)))
threads.append(threading.Thread(target = mail, args = (TESTMAIL,)))
for thread in threads:
thread.start()
for thread in threads:
thread.join()
except Exception as exp:
print(type(exp))
print(exp.args)
finally:
os.system("killall python3")
if __name__ == "__main__":
main()