3939from lib .core .data import logger
4040from lib .core .data import paths
4141from lib .core .option import init
42+ from lib .core .option import __setVerbosity
4243from lib .parse .cmdline import cmdLineParser
4344
4445def smokeTest ():
@@ -80,16 +81,18 @@ def smokeTest():
8081
8182 dataToStdout ("\r %s\r " % (" " * (getConsoleWidth ()- 1 )))
8283 if retVal :
83- logger .info ("smoke test result: passed" )
84+ logger .info ("smoke test final result: passed" )
8485 else :
85- logger .info ("smoke test result: failed" )
86+ logger .info ("smoke test final result: failed" )
8687
8788 return retVal
8889
8990def liveTest ():
9091 """
9192 This will run the test of a program against the live testing environment
9293 """
94+ retVal = True
95+ count = 0
9396 vars = {}
9497 xfile = codecs .open (paths .LIVE_TESTS_XML , 'r' , conf .dataEncoding )
9598 livetests = minidom .parse (xfile ).documentElement
@@ -106,6 +109,7 @@ def liveTest():
106109 log = []
107110 session = []
108111 switches = {}
112+ count += 1
109113
110114 if case .getElementsByTagName ("switches" ):
111115 for child in case .getElementsByTagName ("switches" )[0 ].childNodes :
@@ -122,23 +126,69 @@ def liveTest():
122126 if item .hasAttribute ("value" ):
123127 session .append (replaceVars (item .getAttribute ("value" ), vars ))
124128
125- runCase (switches , log , session )
129+ result = runCase (switches , log , session )
130+ if not result :
131+ errMsg = "live test failed at case #%d" % count
132+ logger .error (errMsg )
133+ retVal &= result
134+
135+ if retVal :
136+ logger .info ("live test final result: passed" )
137+ else :
138+ logger .info ("live test final result: failed" )
139+
140+ return retVal
126141
127142def initCase ():
128143 paths .SQLMAP_OUTPUT_PATH = tempfile .mkdtemp ()
129144 paths .SQLMAP_DUMP_PATH = os .path .join (paths .SQLMAP_OUTPUT_PATH , "%s" , "dump" )
130145 paths .SQLMAP_FILES_PATH = os .path .join (paths .SQLMAP_OUTPUT_PATH , "%s" , "files" )
131146 cmdLineOptions = cmdLineParser ()
132147 cmdLineOptions .liveTest = cmdLineOptions .smokeTest = False
148+ cmdLineOptions .verbose = 0
133149 init (cmdLineOptions )
134- conf .suppressOutput = True
135- logger .setLevel (logging .CRITICAL )
150+ __setVerbosity ()
151+
152+ def cleanCase ():
153+ #remove dir: paths.SQLMAP_OUTPUT_PATH
154+ paths .SQLMAP_OUTPUT_PATH = os .path .join (paths .SQLMAP_ROOT_PATH , "output" )
155+ paths .SQLMAP_DUMP_PATH = os .path .join (paths .SQLMAP_OUTPUT_PATH , "%s" , "dump" )
156+ paths .SQLMAP_FILES_PATH = os .path .join (paths .SQLMAP_OUTPUT_PATH , "%s" , "files" )
157+ conf .verbose = 1
158+ __setVerbosity ()
136159
137160def runCase (switches , log = None , session = None ):
161+ retVal = True
138162 initCase ()
139163 for key , value in switches .items ():
140164 conf [key ] = value
141- start ()
165+
166+ result = start ()
167+ if result == False : #if None ignore
168+ retVal = False
169+
170+ if session and retVal :
171+ file = open (conf .sessionFile , 'r' )
172+ content = file .read ()
173+ file .close ()
174+ for item in session :
175+ #if not re.search(item, content):
176+ if content .find (item ) < 0 :
177+ retVal = False
178+ break
179+
180+ if log and retVal :
181+ file = open (conf .dumper .getOutputFile (), 'r' )
182+ content = file .read ()
183+ file .close ()
184+ for item in log :
185+ #if not re.search(item, content):
186+ if content .find (item ) < 0 :
187+ retVal = False
188+ break
189+
190+ cleanCase ()
191+ return retVal
142192
143193def replaceVars (item , vars ):
144194 retVal = item
0 commit comments