test_flask.py
5.04 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import os, time, requests, ipdb, json, threading
from database import DBconnection
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({
'wpmsg' : '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({
'mailmsg' : 'text',
'mailimage' : 'image',
'maildocument' : 'document'
}),
'info' : json.dumps({
'subject' : 'Some Subject'
})
})
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' : open(FOLDER + "plaintext.enc","rb"),
'plainimage' : open(FOLDER + "plainimage.enc","rb"),
'key' : open(FOLDER + "rand.key.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(phone):
# id no existente
error = requests.post(url = URL + "msg", params = {
'id' : "-",
'serv' : "-",
'dest' : "-",
'type' : "-"
})
assert error.text == "El id - no existe"
# servicio no valido
id = requests.post(url = URL + "data", files = {
"errortext" : open(FOLDER + "errortext","rb")
})
error = requests.post(url = URL + "msg", params = {
'id' : id.text,
'serv' : "-",
'dest' : "-",
'type' : "-"
})
assert error.text == "No existe el servicio '-'"
# archivo inexistente
error = requests.post(url = URL + "msg", params = {
'id' : id.text,
'serv' : "wpp1",
'dest' : phone,
'type' : json.dumps({
"-" : "-"
})
})
assert error.text == "El archivo '-' no existe"
# tipo incorrecto
error = requests.post(url = URL + "msg", params = {
'id' : id.text,
'serv' : "wpp1",
'dest' : phone,
'type' : json.dumps({
"errortext" : "-"
})
})
assert error.text == "El servicio 'wpp1' no puede enviar el tipo '-' destinado al archivo 'errortext'"
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,)))
threads.append(threading.Thread(target = errors, args = (TESTPHONE,)))
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()