I have been trying to get the OWASP ZAP tool to run against my code in an automated fashion. I have been successful in writing a method that works consistently through the Text Explorer interface of Visual Studio 2017 on my local machine. However, whenever I try to have one of my automated test boxes run it using the remote testing command line tool triggered by TFS, then it always fails with Code 1, and no other error text.
I am running the same version of windows 10 locally and on the test box. I have the same version of visual studio installed on each, so I would expect them to be using the same version of VTest to run the tests. I'm not actually sure VTest is involved since I have converted to Selenium, and this is being run as a unit test anyway without a GUI component.
I have tried setting security on the .bat file and the .exe file it calls to Authenticated Users full access because I thought it could be a permissions issue.
I have looked in the event log, but there is are no details showing up in there. It is like it never happened.
I watch the test box while it is attempting to run this particular test, and it never even tries to start up a separate command window for the new zap process, it fails before that ever happens. However, it is definitely finding the correct file to run on the test box because I have tried altering the URL and get a specific error saying it can no longer be found.
I have also tried manually executing the command I am trying to run via command line and when I do it manually on the test box then it works perfectly. The TFS box is logged in and running as the user I tried the manual test as, and that user is a local admin on the box.
Because this works locally on my machine, and because I am able to successfully run the command manually on the test box, the problem component seems to be the TFS remote agent. The remote agent is successful in launching two other processes for Selenium testing, one of which is the IE driver, and the other is the WinAppDriver; the WinAppDriver has a separate command window associate with it when it launches. However, both of these processes are launched by the Selenium wrapper, I am not launching the processes myself directly.
You can see an excerpt below of the code I am using to launch the zap process. Does anyone know why it might be failing on my best box?
string ZapBatLocation = @"C:\Program Files\OWASP\Zed Attack Proxy\zap.bat";
var last_idx = ZapBatLocation.LastIndexOf('\\');
var _ZapProc = new System.Diagnostics.Process();
_ZapProc.StartInfo = new System.Diagnostics.ProcessStartInfo(ZapBatLocation.Substring(last_idx + 1), "-daemon") { WorkingDirectory = ZapBatLocation.Substring(0, last_idx), UseShellExecute = true, CreateNoWindow = false };
_ZapProc.ErrorDataReceived += ErrOutputHandler;
_ZapProc.Start();
System.Threading.Thread.Sleep(2000); // give it time to launch and die if it is going to
if (_ZapProc.HasExited)
throw new Exception($"Unable to launch ZAP process, exited with code {_ZapProc.ExitCode}.");
EDIT: The log file seems to indicate some sort of config corruption. perhaps a security issue on a config file somewhere? Here is an extract of what appears to be the main error that appears frequently in the log:
2019-05-30 16:26:34,178 [AWT-EventQueue-0] INFO Control - New Session 2019-05-30 16:26:34,209 [AWT-EventQueue-0] INFO Control - Create and Open Untitled Db 2019-05-30 16:26:34,240 [AWT-EventQueue-0] INFO ENGINE - dataFileCache commit start 2019-05-30 16:26:34,240 [AWT-EventQueue-0] INFO ENGINE - dataFileCache commit end 2019-05-30 16:26:34,256 [AWT-EventQueue-0] INFO ENGINE - Database closed 2019-05-30 16:26:34,396 [AWT-EventQueue-0] INFO ENGINE - open start - state not modified 2019-05-30 16:26:34,459 [AWT-EventQueue-0] INFO ENGINE - dataFileCache open start 2019-05-30 16:26:34,475 [AWT-EventQueue-0] INFO ENGINE - dataFileCache open end 2019-05-30 16:26:35,615 [ZAP-cfu] ERROR ExtensionAutoUpdate - Unable to load the configuration org.apache.commons.configuration.ConfigurationException: Unable to load the configuration at org.apache.commons.configuration.XMLConfiguration.load(XMLConfiguration.java:955) at org.apache.commons.configuration.XMLConfiguration.load(XMLConfiguration.java:908) at org.apache.commons.configuration.XMLConfiguration$XMLFileConfigurationDelegate.load(XMLConfiguration.java:1583) at org.apache.commons.configuration.AbstractFileConfiguration.load(AbstractFileConfiguration.java:324) at org.apache.commons.configuration.AbstractFileConfiguration.load(AbstractFileConfiguration.java:261) at org.apache.commons.configuration.AbstractFileConfiguration.load(AbstractFileConfiguration.java:238) at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.load(AbstractHierarchicalFileConfiguration.java:184) at org.zaproxy.zap.utils.ZapXmlConfiguration.(ZapXmlConfiguration.java:88) at org.zaproxy.zap.extension.autoupdate.ExtensionAutoUpdate.getPreviousVersionInfo(ExtensionAutoUpdate.java:883) at org.zaproxy.zap.extension.autoupdate.ExtensionAutoUpdate.getNewAddOns(ExtensionAutoUpdate.java:902) at org.zaproxy.zap.extension.autoupdate.ExtensionAutoUpdate.gotLatestData(ExtensionAutoUpdate.java:1139) at org.zaproxy.zap.extension.autoupdate.ExtensionAutoUpdate$8.run(ExtensionAutoUpdate.java:983) Caused by: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 2 of 3-byte UTF-8 sequence. at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(Unknown Source) at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipChar(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source) at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source) at org.apache.commons.configuration.XMLConfiguration.load(XMLConfiguration.java:942) ... 11 more 2019-05-30 16:26:45,052 [Thread-10] INFO ENGINE - dataFileCache commit start 2019-05-30 16:26:45,052 [Thread-10] INFO ENGINE - dataFileCache commit end 2019-05-30 16:26:45,084 [Thread-10] INFO ENGINE - Database closed 2019-05-30 16:26:45,193 [Thread-10] INFO Control - OWASP ZAP 2.7.0 terminated.
I cleared out the log file, and tried to run the automated test, it failed as expected but did not put anything in the log file. I then tried manually running ZAP from the command prompt, and it filled the log file after I exited the program, including the above error.
So it looks like the ZAP log file is not actually created until after a successful start, or at least more of a start than I am getting in the automation.