This repository has been archived on 2021-09-15. You can view files and clone it, but cannot push or open issues or pull requests.
DUT2PTUT/test/botTest.py
sidya82 6873595ffd modifié: Doxyfile
modifié:         doc/html/annotated.html
	modifié:         doc/html/classes.html
	modifié:         doc/html/classm_1_1load_conf_1_1_config_error-members.html
	modifié:         doc/html/classm_1_1load_conf_1_1_config_error.html
	modifié:         doc/html/classm_1_1load_conf_1_1_load_conf-members.html
	modifié:         doc/html/classm_1_1load_conf_1_1_load_conf.html
	modifié:         doc/html/classm_1_1log_1_1_log-members.html
	modifié:         doc/html/classm_1_1log_1_1_log.html
	modifié:         doc/html/classm_1_1log_1_1_single_level_filter-members.html
	modifié:         doc/html/classm_1_1log_1_1_single_level_filter.html
	modifié:         doc/html/classm_1_1log_1_1bcolors-members.html
	modifié:         doc/html/classm_1_1log_1_1bcolors.html
	modifié:         doc/html/classm_1_1log_1_1lvl-members.html
	modifié:         doc/html/classm_1_1log_1_1lvl.html
	modifié:         doc/html/classm_1_1login_1_1_login-members.html
	modifié:         doc/html/classm_1_1login_1_1_login.html
	modifié:         doc/html/classsuper_tornado_1_1_base_handler-members.html
	modifié:         doc/html/classsuper_tornado_1_1_base_handler.html
	modifié:         doc/html/classsuper_tornado_1_1_disconnection_handler-members.html
	modifié:         doc/html/classsuper_tornado_1_1_disconnection_handler.html
	modifié:         doc/html/classsuper_tornado_1_1_global_vars-members.html
	modifié:         doc/html/classsuper_tornado_1_1_global_vars.html
	modifié:         doc/html/classsuper_tornado_1_1_main_handler-members.html
	modifié:         doc/html/classsuper_tornado_1_1_main_handler.html
	modifié:         doc/html/classsuper_tornado_1_1_unauthorized_handler-members.html
	modifié:         doc/html/classsuper_tornado_1_1_unauthorized_handler.html
	modifié:         doc/html/classsuper_tornado_1_1_video_handler-members.html
	modifié:         doc/html/classsuper_tornado_1_1_video_handler.html
	modifié:         doc/html/classsuper_tornado_1_1_w_socket_handler-members.html
	modifié:         doc/html/classsuper_tornado_1_1_w_socket_handler.html
	modifié:         doc/html/dir_060e062f70a4a7965197b0046a5699c1.html
	modifié:         doc/html/dir_b9f9e361513c934f24957ae0a3633a41.html
	modifié:         doc/html/dir_cc95ad066e2e041bbee057a78f4a0df2.html
	modifié:         doc/html/functions.html
	modifié:         doc/html/functions_func.html
	modifié:         doc/html/hierarchy.html
	modifié:         doc/html/index.html
	modifié:         doc/html/md__r_e_a_d_m_e.html
	modifié:         doc/html/namespacemembers.html
	modifié:         doc/html/namespacemembers_func.html
	modifié:         doc/html/namespaces.html
	modifié:         doc/html/namespacesuper_tornado.html
	modifié:         doc/html/pages.html
	modifié:         doc/latex/classm_1_1load_conf_1_1_config_error.pdf
	modifié:         doc/latex/classm_1_1load_conf_1_1_load_conf.pdf
	modifié:         doc/latex/classm_1_1log_1_1_log.pdf
	modifié:         doc/latex/classm_1_1log_1_1_single_level_filter.pdf
	modifié:         doc/latex/classm_1_1login_1_1_login.pdf
	modifié:         doc/latex/classsuper_tornado_1_1_base_handler.pdf
	modifié:         doc/latex/classsuper_tornado_1_1_base_handler.tex
	modifié:         doc/latex/classsuper_tornado_1_1_disconnection_handler.pdf
	modifié:         doc/latex/classsuper_tornado_1_1_disconnection_handler.tex
	modifié:         doc/latex/classsuper_tornado_1_1_global_vars.tex
	modifié:         doc/latex/classsuper_tornado_1_1_main_handler.pdf
	modifié:         doc/latex/classsuper_tornado_1_1_main_handler.tex
	modifié:         doc/latex/classsuper_tornado_1_1_unauthorized_handler.pdf
	modifié:         doc/latex/classsuper_tornado_1_1_unauthorized_handler.tex
	modifié:         doc/latex/classsuper_tornado_1_1_video_handler.pdf
	modifié:         doc/latex/classsuper_tornado_1_1_video_handler.tex
	modifié:         doc/latex/classsuper_tornado_1_1_w_socket_handler.pdf
	modifié:         doc/latex/classsuper_tornado_1_1_w_socket_handler.tex
	modifié:         doc/latex/refman.tex
	modifié:         doc/man/man3/_home_sidya_Documents_iut_ptut_m_.3
	modifié:         doc/man/man3/_home_sidya_Documents_iut_ptut_v_.3
	modifié:         doc/man/man3/_home_sidya_Documents_iut_ptut_v_js_.3
	modifié:         doc/man/man3/m_loadConf_ConfigError.3
	modifié:         doc/man/man3/m_loadConf_LoadConf.3
	modifié:         doc/man/man3/m_log_Log.3
	modifié:         doc/man/man3/m_log_SingleLevelFilter.3
	modifié:         doc/man/man3/m_log_bcolors.3
	modifié:         doc/man/man3/m_log_lvl.3
	modifié:         doc/man/man3/m_login_Login.3
	modifié:         doc/man/man3/md__r_e_a_d_m_e.3
	modifié:         doc/man/man3/superTornado.3
	modifié:         doc/man/man3/superTornado_BaseHandler.3
	modifié:         doc/man/man3/superTornado_DisconnectionHandler.3
	modifié:         doc/man/man3/superTornado_GlobalVars.3
	modifié:         doc/man/man3/superTornado_MainHandler.3
	modifié:         doc/man/man3/superTornado_UnauthorizedHandler.3
	modifié:         doc/man/man3/superTornado_VideoHandler.3
	modifié:         doc/man/man3/superTornado_WSocketHandler.3
	modifié:         m/loadConf.py
	modifié:         superTornado.py
	modifié:         test/botTest.py
2014-04-03 16:35:54 +02:00

213 lines
5.6 KiB
Python

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 main page of the site :"
print "PATH: /"
print "TYPE REQUEST : GET"
print "DATA SEND : -"
print ""
resp = opener.open(base_url+"video")
if resp.geturl()== base_url:
print("OK : receive / page")
else:
print("NOK : not receive / page !")
cj.save()
print "\nI'm continue 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 now 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 access 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 :ask for data"
ws.send("Ask for data")
print "Sent"
print "Receiving..."
result = ws.recv()
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 disconnect :"
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 Will 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 : ask for data"
ws.send("Ask for data")
print "Sent"
print "Receiving..."
result = ws.recv()
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."