2222from lib .core .data import logger
2323from lib .core .data import paths
2424from lib .core .option import init
25- from lib .core .option import _setVerbosity
25+ from lib .core .option import setVerbosity
2626from lib .core .optiondict import optDict
2727from lib .parse .cmdline import cmdLineParser
2828
@@ -118,39 +118,42 @@ def liveTest():
118118
119119 for case in livetests .getElementsByTagName ("case" ):
120120 count += 1
121-
122- if conf .runCase and conf .runCase != count :
123- continue
124-
125121 name = None
126- log = []
122+ parse = []
127123 switches = dict (global_ )
128124
129125 if case .hasAttribute ("name" ):
130126 name = case .getAttribute ("name" )
131127
128+ if conf .runCase and ((conf .runCase .isdigit () and conf .runCase != count ) or not re .search (conf .runCase , name , re .DOTALL )):
129+ continue
130+
132131 if case .getElementsByTagName ("switches" ):
133132 for child in case .getElementsByTagName ("switches" )[0 ].childNodes :
134133 if child .nodeType == child .ELEMENT_NODE and child .hasAttribute ("value" ):
135134 value = replaceVars (child .getAttribute ("value" ), vars_ )
136135 switches [child .tagName ] = adjustValueType (child .tagName , value )
137136
138- if case .getElementsByTagName ("log " ):
139- for item in case .getElementsByTagName ("log " )[0 ].getElementsByTagName ("item" ):
137+ if case .getElementsByTagName ("parse " ):
138+ for item in case .getElementsByTagName ("parse " )[0 ].getElementsByTagName ("item" ):
140139 if item .hasAttribute ("value" ):
141- log .append (replaceVars (item .getAttribute ("value" ), vars_ ))
140+ parse .append (replaceVars (item .getAttribute ("value" ), vars_ ))
142141
143142 msg = "running live test case '%s' (%d/%d)" % (name , count , length )
144143 logger .info (msg )
145- result = runCase (switches , log )
144+
145+ result = runCase (switches , parse )
146+
146147 if result :
147148 logger .info ("test passed" )
148149 else :
149150 logger .error ("test failed" )
150151 beep ()
152+
151153 retVal &= result
152154
153155 dataToStdout ("\n " )
156+
154157 if retVal :
155158 logger .info ("live test final result: PASSED" )
156159 else :
@@ -159,9 +162,12 @@ def liveTest():
159162 return retVal
160163
161164def initCase (switches = None ):
162- paths .SQLMAP_OUTPUT_PATH = tempfile .mkdtemp ()
165+ paths .SQLMAP_OUTPUT_PATH = tempfile .mkdtemp (prefix = "sqlmaptest-" )
163166 paths .SQLMAP_DUMP_PATH = os .path .join (paths .SQLMAP_OUTPUT_PATH , "%s" , "dump" )
164167 paths .SQLMAP_FILES_PATH = os .path .join (paths .SQLMAP_OUTPUT_PATH , "%s" , "files" )
168+
169+ logger .debug ("using output directory '%s' for this test case" % paths .SQLMAP_OUTPUT_PATH )
170+
165171 cmdLineOptions = cmdLineParser ()
166172 cmdLineOptions .liveTest = cmdLineOptions .smokeTest = False
167173
@@ -171,29 +177,29 @@ def initCase(switches=None):
171177 cmdLineOptions .__dict__ [key ] = value
172178
173179 init (cmdLineOptions , True )
174- _setVerbosity ()
180+ conf .verbose = 0
181+ setVerbosity ()
175182
176183def cleanCase ():
177184 shutil .rmtree (paths .SQLMAP_OUTPUT_PATH , True )
178- paths .SQLMAP_OUTPUT_PATH = os .path .join (paths .SQLMAP_ROOT_PATH , "output" )
179- paths .SQLMAP_DUMP_PATH = os .path .join (paths .SQLMAP_OUTPUT_PATH , "%s" , "dump" )
180- paths .SQLMAP_FILES_PATH = os .path .join (paths .SQLMAP_OUTPUT_PATH , "%s" , "files" )
181185 conf .verbose = 1
182- _setVerbosity ()
186+ setVerbosity ()
183187
184- def runCase (switches = None , log = None ):
188+ def runCase (switches = None , parse = None ):
185189 retVal = True
186190 initCase (switches )
187191
188192 result = start ()
189- if result == False : #if None ignore
193+
194+ if result == False : # if None, ignore
195+ logger .error ("the test did not run" )
190196 retVal = False
191197
192- if log and retVal :
198+ if parse and retVal :
193199 ifile = open (conf .dumper .getOutputFile (), 'r' )
194200 content = ifile .read ()
195201 ifile .close ()
196- for item in log :
202+ for item in parse :
197203 if item .startswith ("r'" ) and item .endswith ("'" ):
198204 if not re .search (item [2 :- 1 ], content , re .DOTALL ):
199205 retVal = False
0 commit comments