modifié: m/fichier/conf
modifié: m/loadConf.py modifié: m/log.py modifié: m/login.py modifié: superTornado.py nouveau fichier: test/AllowTest nouveau fichier: test/ConfTest nouveau fichier: test/MiEmulator.py nouveau fichier: test/a nouveau fichier: test/botTest.py nouveau fichier: test/mfp.cookies nouveau fichier: test/testFichier.py nouveau fichier: test/testMISignaux.py modifié: v/illegal.html modifié: v/index.html
This commit is contained in:
17
test/AllowTest
Normal file
17
test/AllowTest
Normal file
@ -0,0 +1,17 @@
|
||||
4u8jq3J9hEG0ZQ,79af5b0417d02392e22eeea9af539acddf1b7df16c6bf3a83e661774
|
||||
7HLP,3bd969da01f586774021e72ef6eb802d38e1c263760f3f56b5812760
|
||||
eU65FDk3c,2e687f8b8b0f97e2951b7b69ac45baf291df1e8a0cb01bd90624e2b0
|
||||
4NiX4,6ead98789bc7cdcc2fa7702cfe3b10ee280e1d8608fd258a25782045
|
||||
CsFd4lwXk9,8f61eaa23a728901322d0596cfbf25da27e212162d897fa95d7ac9ac
|
||||
nghz,64b00fd3a24a5b2ab169cc3891b0d65c6c65e695532eaff2c7259cbd
|
||||
wSUyyNNKNTlvr,06386e5d7c243bf66f1cd717ebdab48ca33bf75f408da9c95c3fd30a
|
||||
0s01eGWoY8aGplb,f9a26c9c8e474c73d61ebb2fbadb72b2743c1cb84e1a92abdf433fe7
|
||||
9HA1lzbFEuYf1rXpKe,df4e71601e2a93f5d17e9599f25acd249f3fb20cf57ed8e1d56aba76
|
||||
1w,0599c5153b82f9f3a47f45014165e5648edd4e0ff90d5b544d74b629
|
||||
Qky5HF,50557d97b6dd5abfc4e86ba4ff4e1f4b92b17908fa42791aaf70bc66
|
||||
hTtP,f92d7aa3b3243d461489c61ef4d536fa01fdf0dfab68d60dd354940f
|
||||
NohoYCOrW0nw0Zie,af6c0bb741cc5725e6e09eb731cb958e6b67b2e30a65ff8ea7b23394
|
||||
Ahpx9i65RKUoQTaqc,f5a43e2f60a96ffbe7d75d7f6cfa62bbd170ef7ab36dcc4a233e2a4b
|
||||
SJEtTanO2FNFUd7MYU,fe6e47c833c2850fd02fa9ed4e17a32e334cf5897ec73a6749466ad8
|
||||
B8T9ua3vks2YZYCL4Ag,a2bafbc1dcdd406d9717092d497937e9061e400943658827191b53a9
|
||||
JP,95cbc8568bc02f258132fddf1344a6e558f94c39d20284ee3237f325
|
16
test/ConfTest
Normal file
16
test/ConfTest
Normal file
@ -0,0 +1,16 @@
|
||||
VgS4Ia4IvUHC5niHmNR1=ExiJILtyduI
|
||||
EXTM=lu6ltwn5vYU07mFupP4
|
||||
0=m4VYOt7MHSZCijA2kPv
|
||||
0RH0gFjtlFDxg6=JB
|
||||
0gbS8=duM7RL
|
||||
TN=hqkUnUdp
|
||||
3tynRJm91uvM=9t
|
||||
KmO=s2vnpx
|
||||
1DZ7EL8mmUT7=Ck
|
||||
hWMNcDWfdj=xZsqrp3ctcfR0
|
||||
GWVF2moK=CfFlLHozTeiBj7Rh
|
||||
jin5jmoevE5msN=9T5
|
||||
muM=bkRp
|
||||
cgUGnl8n1=5AGUXFkpSzs
|
||||
Jb7YlVGMcd6s2=agXT2nzPYkbS
|
||||
B=y0j02B
|
29
test/MiEmulator.py
Normal file
29
test/MiEmulator.py
Normal file
@ -0,0 +1,29 @@
|
||||
"""Import Tornado Server"""
|
||||
import sys
|
||||
import tornado.ioloop
|
||||
import tornado.web
|
||||
import tornado.httpserver
|
||||
import tornado.websocket
|
||||
import tornado.options
|
||||
from tornado.ioloop import PeriodicCallback
|
||||
|
||||
f = open("requestToMi", "w")
|
||||
|
||||
class MainHandler(tornado.web.RequestHandler):
|
||||
def get(self):
|
||||
print "lol"
|
||||
|
||||
|
||||
application = tornado.web.Application([
|
||||
(r"/lol", MainHandler)])
|
||||
|
||||
if __name__ == "__main__":
|
||||
try :
|
||||
tornado.options.parse_command_line()
|
||||
http_server = tornado.httpserver.HTTPServer(application)
|
||||
http_server.listen(80)
|
||||
tornado.ioloop.IOLoop.instance().start()
|
||||
except Exception, e :
|
||||
print e
|
||||
sys.exit(1)
|
||||
|
206
test/botTest.py
Normal file
206
test/botTest.py
Normal file
@ -0,0 +1,206 @@
|
||||
import urllib, urllib2
|
||||
import cookielib, time
|
||||
import random
|
||||
import string
|
||||
import socket
|
||||
import sys
|
||||
from websocket import create_connection#sudo pip install websocket-client
|
||||
from urllib import urlopen
|
||||
|
||||
ignore_discard=True
|
||||
# url for website
|
||||
base_url = 'http://127.0.0.1/'
|
||||
# cookies
|
||||
cookie_file = 'mfp.cookies'
|
||||
cj = cookielib.MozillaCookieJar(cookie_file)
|
||||
|
||||
# set up opener to handle cookies, redirects etc
|
||||
opener = urllib2.build_opener(
|
||||
urllib2.HTTPRedirectHandler(),
|
||||
urllib2.HTTPHandler(debuglevel=0),
|
||||
urllib2.HTTPSHandler(debuglevel=0),
|
||||
urllib2.HTTPCookieProcessor(cj)
|
||||
)
|
||||
# we are not a python, we are a browser :)
|
||||
browser = 'Mozilla/5.0 (X11; U; Linux i686; fr; rv:1.9.0.6) Gecko/2009020619 Gentoo Iceweasel/3.0.6'
|
||||
opener.addheaders = [('User-agent',
|
||||
(browser))
|
||||
]
|
||||
|
||||
|
||||
print "Hello, I'm botTest :)"
|
||||
print "I'm here for test MI camera server."
|
||||
print "I'm not a python script for the server, I'm a browser : \n" + browser.replace(";","")
|
||||
print "\nI'm starting test with video page where an unconnect user can't normaly access :"
|
||||
print "PATH: /video"
|
||||
print "TYPE REQUEST : GET"
|
||||
print "DATA SEND : -"
|
||||
print ""
|
||||
resp = opener.open(base_url+"video")
|
||||
if resp.geturl()== base_url:
|
||||
print("OK : redirection to /")
|
||||
else:
|
||||
print("NOK : not redirect to / !")
|
||||
cj.save()
|
||||
|
||||
print "\nI will know try to connect with bad login information :"
|
||||
print "PATH: /"
|
||||
print "TYPE REQUEST : POST"
|
||||
print "DATA SEND :"
|
||||
login = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(random.randint(5,10)))
|
||||
paswd = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(random.randint(5,10)))
|
||||
print "login => " + login
|
||||
print "paswd => " + paswd
|
||||
print ""
|
||||
login_data = urllib.urlencode({
|
||||
'id' : login,
|
||||
'paswd' : paswd,
|
||||
})
|
||||
resp = opener.open(base_url, login_data)
|
||||
if resp.geturl()== base_url+"unauthorized":
|
||||
print("OK : redirection to /unauthorized")
|
||||
else:
|
||||
print("NOK : not redirect to /unauthorized !")
|
||||
cj.save()
|
||||
|
||||
print "\nI will now try to force access to camera :"
|
||||
print "PATH: /unauthorized "
|
||||
print "TYPE REQUEST : POST"
|
||||
print "DATA SEND :"
|
||||
print "illegalAccess => 1"
|
||||
print ""
|
||||
login_data = urllib.urlencode({
|
||||
'illegalAccess' : '1',
|
||||
})
|
||||
resp = opener.open(base_url+"unauthorized", login_data)
|
||||
if resp.geturl()== base_url+"video":
|
||||
print("OK : redirection to /video")
|
||||
else:
|
||||
print("NOK : not redirect to /video !")
|
||||
cj.save()
|
||||
|
||||
print "\nI will now try to not force access to camera :"
|
||||
print "PATH: /unauthorized "
|
||||
print "TYPE REQUEST : POST"
|
||||
print "DATA SEND :"
|
||||
print "illegalAccess => 0"
|
||||
print ""
|
||||
login_data = urllib.urlencode({
|
||||
'illegalAccess' : "0",
|
||||
})
|
||||
resp = opener.open(base_url+"unauthorized", login_data)
|
||||
if resp.geturl()== base_url:
|
||||
print("OK : redirection to /")
|
||||
else:
|
||||
print("NOK : not redirect to / !")
|
||||
cj.save()
|
||||
|
||||
print "\nI will now try to connect with good user information :"
|
||||
print "PATH: / "
|
||||
print "TYPE REQUEST : POST"
|
||||
print "DATA SEND :"
|
||||
login = "jmi"
|
||||
paswd = "azerty"
|
||||
print "login => " + login
|
||||
print "paswd => " + paswd
|
||||
print ""
|
||||
login_data = urllib.urlencode({
|
||||
'id' : login,
|
||||
'paswd' : paswd,
|
||||
})
|
||||
resp = opener.open(base_url, login_data)
|
||||
if resp.geturl()== base_url+"video":
|
||||
print("OK : redirection to /video")
|
||||
else:
|
||||
print("NOK : not redirect to /video !")
|
||||
cj.save()
|
||||
|
||||
|
||||
print "\nNow I have acess to /video i will try to connect to websocket to aquire image :"
|
||||
print "PATH: /socket "
|
||||
print "TYPE REQUEST : GET"
|
||||
print "DATA SEND :"
|
||||
|
||||
try :
|
||||
val =""
|
||||
for cookie in cj :
|
||||
if cookie.name =="user" :
|
||||
val = cookie.value
|
||||
ws = create_connection("ws://127.0.0.1/socket",\
|
||||
header={"Cookie:user="+val})
|
||||
print "Sending"
|
||||
ws.send("Asf for data")
|
||||
print "Sent"
|
||||
print "Receiving..."
|
||||
result = ws.recv()
|
||||
print "Rep : " + result
|
||||
|
||||
if result == "error":
|
||||
print "NOK : Response From Socket But Is An Error"
|
||||
else:
|
||||
print "OK : Receive Some Data From Socket. Can't Guaranted Is Image"
|
||||
ws.close()
|
||||
except Exception, e :
|
||||
print "NOK : Failed To Connect To Websocket And Received Data"
|
||||
cj.save()
|
||||
|
||||
print "\nI will now try to disconnet :"
|
||||
print "PATH: / "
|
||||
print "TYPE REQUEST : GET"
|
||||
print "DATA SEND : - "
|
||||
|
||||
resp = opener.open(base_url+"disconnection")
|
||||
if resp.geturl()== base_url:
|
||||
print("OK : redirection to /")
|
||||
else:
|
||||
print("NOK : not redirect to / !")
|
||||
cj.save()
|
||||
|
||||
print "\nI'm now test video for check if i am disconnected :"
|
||||
print "PATH: /video"
|
||||
print "TYPE REQUEST : GET"
|
||||
print "DATA SEND : -"
|
||||
print ""
|
||||
resp = opener.open(base_url+"video")
|
||||
if resp.geturl()== base_url:
|
||||
print("OK : redirection to /")
|
||||
else:
|
||||
print("NOK : not redirect to / !")
|
||||
cj.save()
|
||||
|
||||
|
||||
|
||||
print "\nNow I Will Try To Connect To The Websocket then I not connected :"
|
||||
print "PATH: /socket "
|
||||
print "TYPE REQUEST : GET"
|
||||
print "DATA SEND :"
|
||||
|
||||
try :
|
||||
val =""
|
||||
for cookie in cj :
|
||||
if cookie.name =="user" :
|
||||
val = cookie.value
|
||||
ws = create_connection("ws://127.0.0.1/socket",\
|
||||
header={"Cookie:user="+val})
|
||||
print "Sending"
|
||||
ws.send("Asf for data")
|
||||
print "Sent"
|
||||
print "Receiving..."
|
||||
result = ws.recv()
|
||||
print "Rep : " + result
|
||||
|
||||
if result == "error":
|
||||
print "NOK : Response From Socket But Is An Error"
|
||||
else:
|
||||
print "NOK : Receive Some Data From Socket. Can't Guaranted Is Image"
|
||||
ws.close()
|
||||
except Exception, e :
|
||||
print "OK : Failed To Connect To Websocket And Received Data"
|
||||
cj.save()
|
||||
|
||||
print "\nI have finished to test MI camera server."
|
||||
print "Good Bye."
|
||||
|
||||
|
||||
|
||||
|
4
test/mfp.cookies
Normal file
4
test/mfp.cookies
Normal file
@ -0,0 +1,4 @@
|
||||
# Netscape HTTP Cookie File
|
||||
# http://www.netscape.com/newsref/std/cookie_spec.html
|
||||
# This is a generated file! Do not edit.
|
||||
|
151
test/testFichier.py
Normal file
151
test/testFichier.py
Normal file
@ -0,0 +1,151 @@
|
||||
import random
|
||||
import string
|
||||
import hashlib
|
||||
import sys
|
||||
|
||||
|
||||
sys.path[:0]=['../']
|
||||
from m.log import *
|
||||
from m.loadConf import *
|
||||
from m.login import *
|
||||
|
||||
|
||||
class testConf(object):
|
||||
"""
|
||||
Test on Conf File Loading
|
||||
"""
|
||||
def createConf(self) :
|
||||
"""
|
||||
Create a random conf file named ConfTest.
|
||||
Save key ,value in self.assos[].
|
||||
"""
|
||||
print "Create Random Conf File"
|
||||
f = open("ConfTest", "w")
|
||||
j = random.randint(5,20)
|
||||
self.assos = [""]*j
|
||||
for i in range (0,j) :
|
||||
key=''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(random.randint(1,20)))
|
||||
value = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(random.randint(1,20)))
|
||||
self.assos[i] = [key,value]
|
||||
f.write(key+"="+value+"\n")
|
||||
f.close()
|
||||
print "Random Conf File Create"
|
||||
|
||||
|
||||
def testLoadConf(self,LoadConfObject) :
|
||||
"""
|
||||
Test loadValue method LoadConf object
|
||||
"""
|
||||
print "\nTesting All Valid Keys"
|
||||
err=0
|
||||
for key,value in self.assos :
|
||||
confValue = LoadConfObject.loadValue(key)
|
||||
if confValue == "error" :
|
||||
print "NOK : Error an valid key give return an error"
|
||||
err +=1
|
||||
if value == confValue :
|
||||
print "OK : Succesfull Load Config Value"
|
||||
else :
|
||||
print " NOK : Value return is not the right value"
|
||||
err +=1
|
||||
|
||||
if err>0:
|
||||
print "TEST FAIL : all key were not load succesfully"
|
||||
else :
|
||||
print "TEST SUCESSFULL : all key were load succesfully"
|
||||
|
||||
|
||||
|
||||
print "\nTesting invalid keys"
|
||||
err = 0
|
||||
for i in range(10):
|
||||
confValue = LoadConfObject.loadValue(
|
||||
''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(random.randint(1,20))))
|
||||
if confValue != "error":
|
||||
print "NOK : An value was return"
|
||||
err += 1
|
||||
else :
|
||||
print "OK : return an error"
|
||||
|
||||
if err>0:
|
||||
print "TEST FAIL : don't return only error'"
|
||||
else :
|
||||
print "TEST SUCESSFULL : return only error"
|
||||
|
||||
|
||||
class testLogin(object):
|
||||
def createAllowFile(self) :
|
||||
"""
|
||||
Create a allow file named AllowTest.
|
||||
Save key ,value in self.assos[].
|
||||
"""
|
||||
print "Create Allow File"
|
||||
f = open("AllowTest", "w")
|
||||
j = random.randint(5,20)
|
||||
self.assos = [""]*j
|
||||
for i in range (0,j) :
|
||||
name=''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(random.randint(1,20)))
|
||||
passwd = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(random.randint(1,20)))
|
||||
hashPasswd = hashlib.sha224(passwd).hexdigest()
|
||||
self.assos[i] = [name,passwd]
|
||||
f.write(name+","+hashPasswd+"\n")
|
||||
f.close()
|
||||
print "Random Allow File Create"
|
||||
|
||||
def testLogin(self,LoginObject) :
|
||||
"""
|
||||
Test CheckLogin method LoadConf object
|
||||
"""
|
||||
print "\nTesting Valid Login Information "
|
||||
err=0
|
||||
for name,passwd in self.assos :
|
||||
value = LoginObject.checkLogin(name,passwd)
|
||||
if value == True:
|
||||
print "OK : Return True"
|
||||
else :
|
||||
print "NOK : Return False"
|
||||
err +=1
|
||||
|
||||
if err==0:
|
||||
print "TEST SUCESSFULL : all login were succesfull"
|
||||
else :
|
||||
print "TEST FAIL: all login were not succesfull"
|
||||
|
||||
|
||||
|
||||
print "\nTesting invalid keys"
|
||||
err = 0
|
||||
for i in range(10):
|
||||
value = LoginObject.checkLogin(
|
||||
''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(random.randint(1,20))),
|
||||
''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(random.randint(1,20))))
|
||||
|
||||
if value == True:
|
||||
print "NOK : Return True"
|
||||
err += 1
|
||||
else :
|
||||
print "OK : Return False"
|
||||
|
||||
if err>0:
|
||||
print "TEST FAIL : Login Ok With Invalid Information"
|
||||
else :
|
||||
print "TEST SUCESSFULL : Login Not Ok With Invalid Information"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print "START TEST LOADCONFIG METHODS"
|
||||
test= testConf()
|
||||
test.createConf();
|
||||
config = LoadConf("ConfTest")
|
||||
test.testLoadConf(config);
|
||||
print "\nEND TEST CONFIG FILE LOADING METHODS"
|
||||
print "\nSTART TEST LOGIN METHODS"
|
||||
test = testLogin()
|
||||
test.createAllowFile()
|
||||
login = Login("AllowTest")
|
||||
test.testLogin(login)
|
||||
print "\nEND TEST LOGIN METHODS"
|
||||
|
26
test/testMISignaux.py
Normal file
26
test/testMISignaux.py
Normal file
@ -0,0 +1,26 @@
|
||||
import httplib
|
||||
import time
|
||||
|
||||
maison = httplib.HTTPConnection("192.168.16.150", 80)
|
||||
|
||||
maison.request("GET","/micom/say.php?source=toto&text=Connection%20a%20la%20camera%20autorisee")
|
||||
print 'maison.request("GET","/micom/say.php?source=toto&text=Connection%20a%20la%20camera%20autorisee")'
|
||||
time.sleep(5)
|
||||
maison.request("GET","/micom/say.php?source=toto&text=Connection%20a%20la%20camera%20non%20autorisee")
|
||||
print 'maison.request("GET","/micom/say.php?source=toto&text=Connection%20a%20la%20camera%20non%20autorisee")'
|
||||
time.sleep(5)
|
||||
maison.request("GET","/micom/say.php?source=toto&text=Connection%20a%20la%20camera%20rompue")
|
||||
print 'maison.request("GET","/micom/say.php?source=toto&text=Connection%20a%20la%20camera%20rompue")'
|
||||
time.sleep(5)
|
||||
maison.request("GET","/micom/lamp.php?room=cuisine1&order=1")
|
||||
print 'maison.request("GET","/micom/lamp.php?room=cuisine1&order=1")'
|
||||
time.sleep(5)
|
||||
maison.request("GET","/micom/lamp.php?room=cuisine1&order=0")
|
||||
print 'maison.request("GET","/micom/lamp.php?room=cuisine1&order=0")'
|
||||
time.sleep(5)
|
||||
maison.request("GET","/micom/lamp.php?room=salon1&order=1")
|
||||
print 'maison.request("GET","/micom/lamp.php?room=salon1&order=1")'
|
||||
time.sleep(5)
|
||||
maison.request("GET","/micom/lamp.php?room=salon1&order=0")
|
||||
print 'maison.request("GET","/micom/lamp.php?room=salon1&order=0")'
|
||||
|
Reference in New Issue
Block a user