2121Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2222"""
2323
24+ import codecs
25+ import logging
2426import os
27+ import re
2528import sys
29+ import tempfile
2630import time
2731
32+ from xml .dom import minidom
33+
34+ from lib .controller .controller import start
2835from lib .core .common import dataToStdout
36+ from lib .core .common import getCompiledRegex
2937from lib .core .common import getConsoleWidth
3038from lib .core .data import conf
3139from lib .core .data import logger
3240from lib .core .data import paths
41+ from lib .core .option import init
42+ from lib .parse .cmdline import cmdLineParser
3343
3444def smokeTest ():
3545 """
@@ -80,4 +90,60 @@ def liveTest():
8090 """
8191 This will run the test of a program against the live testing environment
8292 """
83- pass
93+ vars = {}
94+ xfile = codecs .open (paths .LIVE_TESTS_XML , 'r' , conf .dataEncoding )
95+ livetests = minidom .parse (xfile ).documentElement
96+ xfile .close ()
97+
98+ global_ = livetests .getElementsByTagName ("global" )
99+ if global_ :
100+ for item in global_ :
101+ for child in item .childNodes :
102+ if child .nodeType == child .ELEMENT_NODE and child .hasAttribute ("value" ):
103+ vars [child .tagName ] = child .getAttribute ("value" )
104+
105+ for case in livetests .getElementsByTagName ("case" ):
106+ log = []
107+ session = []
108+ switches = {}
109+
110+ if case .getElementsByTagName ("switches" ):
111+ for child in case .getElementsByTagName ("switches" )[0 ].childNodes :
112+ if child .nodeType == child .ELEMENT_NODE and child .hasAttribute ("value" ):
113+ switches [child .tagName ] = replaceVars (child .getAttribute ("value" ), vars )
114+
115+ if case .getElementsByTagName ("log" ):
116+ for item in case .getElementsByTagName ("log" )[0 ].getElementsByTagName ("item" ):
117+ if item .hasAttribute ("value" ):
118+ log .append (replaceVars (item .getAttribute ("value" ), vars ))
119+
120+ if case .getElementsByTagName ("session" ):
121+ for item in case .getElementsByTagName ("session" )[0 ].getElementsByTagName ("item" ):
122+ if item .hasAttribute ("value" ):
123+ session .append (replaceVars (item .getAttribute ("value" ), vars ))
124+
125+ runCase (switches , log , session )
126+
127+ def initCase ():
128+ paths .SQLMAP_OUTPUT_PATH = tempfile .mkdtemp ()
129+ paths .SQLMAP_DUMP_PATH = os .path .join (paths .SQLMAP_OUTPUT_PATH , "%s" , "dump" )
130+ paths .SQLMAP_FILES_PATH = os .path .join (paths .SQLMAP_OUTPUT_PATH , "%s" , "files" )
131+ cmdLineOptions = cmdLineParser ()
132+ cmdLineOptions .liveTest = cmdLineOptions .smokeTest = False
133+ init (cmdLineOptions )
134+ conf .suppressOutput = True
135+ logger .setLevel (logging .CRITICAL )
136+
137+ def runCase (switches , log = None , session = None ):
138+ initCase ()
139+ for key , value in switches .items ():
140+ conf [key ] = value
141+ start ()
142+
143+ def replaceVars (item , vars ):
144+ retVal = item
145+ if item and vars :
146+ for var in re .findall (getCompiledRegex ("\$\{([^}]+)\}" ), item ):
147+ if var in vars :
148+ retVal = retVal .replace ("${%s}" % var , vars [var ])
149+ return retVal
0 commit comments