Skip to content

Commit a0a33f4

Browse files
committed
Merge pull request #1 from o2platform/5.3_Release
5.3 release
2 parents 0047975 + 0e5c79e commit a0a33f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2073
-1068
lines changed

3rdParty/CheckMarx/2.6.3_WSDL_files/Util - CheckMarx Rule and Guidance Viewer.h2

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
<?xml version="1.0"?>
2-
<H2>
3-
<SourceCode>var topPanel = "Util - CheckMarx Rule and Guidance Viewer".popupWindow(1000, 600).insert_LogViewer();
1+
var topPanel = "Util - CheckMarx Rule and Guidance Viewer".popupWindow(1000, 600).insert_LogViewer();
42
//var topPanel = panel.add_Panel(true);
53
var settingsPanel = topPanel.insert_Above(40,"Settings");
64
var treeView = topPanel.add_TreeView_with_PropertyGrid().sort();
@@ -11,11 +9,11 @@ var cxPortal = new CxPortalWebService();
119

1210
settingsPanel.add_Label("Server:",2).append_TextBox(cxPortal.Url).align_Right();
1311
//.widthAdd(-100)
14-
//.append_Link("Connect", ()=&gt;{});
12+
//.append_Link("Connect", ()=>{});
1513

1614
"cxSessionId".o2Cache(null);
1715
var sessionId = "cxSessionId".o2Cache(
18-
()=&gt;{
16+
()=>{
1917
var user = "What user do you want to use".askUser();
2018
var pwd = "What is the pwd for user {0}".format(user).askUser();
2119

@@ -42,19 +40,19 @@ var checkMark_Data = "_CheckMark_Data".tempDir(false);
4240

4341

4442
var queryQueryCollection = (CxQueryCollectionResponse)"CxQueryCollectionResponse".o2Cache(
45-
()=&gt;{
43+
()=>{
4644
"Loading data from GetQueryCollection (its about 2.5Mb".debug();
4745
var queryCollectionFile = checkMark_Data.pathCombine("WS_GetQueryCollection.xml");
4846
var response = cxPortal.GetQueryCollection(sessionId);
4947
response.saveAs(queryCollectionFile);
50-
return queryCollectionFile.load&lt;CxQueryCollectionResponse&gt;();
48+
return queryCollectionFile.load<CxQueryCollectionResponse>();
5149
});
5250

5351

54-
Action&lt;long&gt; showCweData =
55-
(cweId)=&gt;{
52+
Action<long> showCweData =
53+
(cweId)=>{
5654
O2Thread.mtaThread(
57-
()=&gt;{
55+
()=>{
5856
browser.showMessage("Loading CweId: {0}".format(cweId));
5957
var cweHtml = cxPortal.GetQueryDescription(sessionId, (int)cweId)
6058
.QueryDescription.saveWithExtension(".html");
@@ -64,15 +62,15 @@ Action&lt;long&gt; showCweData =
6462
};
6563

6664

67-
treeView.afterSelect&lt;CxWSQuery&gt;(
68-
(query)=&gt;{
65+
treeView.afterSelect<CxWSQuery>(
66+
(query)=>{
6967

7068
codeViewer.set_Text(query.Source, ".cs");
7169
showCweData(query.Cwe);
7270
});
7371

7472
treeView.beginUpdate();
75-
var queryGroupMappings = new Dictionary&lt;string, List&lt;CxWSQueryGroup&gt;&gt;();
73+
var queryGroupMappings = new Dictionary<string, List<CxWSQueryGroup>>();
7674
foreach(var queryGroup in queryQueryCollection.QueryGroups)
7775
queryGroupMappings.add(queryGroup.LanguageName, queryGroup);
7876

@@ -125,6 +123,3 @@ return response;
125123
*/
126124
//O2File:CxPortalWebService.cs
127125
//O2Ref:System.Web.Services.dll
128-
</SourceCode>
129-
<ReferencedAssemblies />
130-
</H2>

3rdParty/CheckMarx/API_IE_CxWebClient.cs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,25 @@ namespace O2.XRules.Database.APIs
1616

1717
public class API_IE_CxWebClient : API_IE_ExecutionGUI
1818
{
19+
public string DEFAULT_SERVER = "https://www.cxprivatecloud.com";
1920

2021
public API_IE_CxWebClient(WatiN_IE ie) : base(ie)
2122
{
22-
config();
23+
config(DEFAULT_SERVER);
24+
}
25+
public API_IE_CxWebClient(WatiN_IE ie, string targetServer) : base(ie)
26+
{
27+
config(targetServer);
2328
}
2429

2530
public API_IE_CxWebClient(Control hostControl) : base(hostControl)
2631
{
27-
config();
32+
config(DEFAULT_SERVER);
2833
}
2934

30-
public void config()
35+
public void config(string targetServer)
3136
{
32-
this.TargetServer = "https://www.cxprivatecloud.com";
37+
this.TargetServer = targetServer;
3338
API_IE_CxWebClient_HelperMethods.ie = this.ie;
3439
}
3540
}
@@ -41,8 +46,7 @@ public static class API_IE_CxWebClient_Actions
4146
public static API_IE_ExecutionGUI homepage(this API_IE_CxWebClient cxWeb)
4247
{
4348
return cxWeb.open("");
44-
}
45-
49+
}
4650

4751

4852
/*[ShowInGui(Folder ="links")]
@@ -70,13 +74,28 @@ public static class API_IE_CxWebClient_HelperMethods
7074
{
7175
public static WatiN_IE ie;
7276

77+
public static API_IE_CxWebClient login(this API_IE_CxWebClient cxClient, ICredential credential)
78+
{
79+
return cxClient.login(credential.UserName, credential.Password);
80+
}
81+
7382
public static API_IE_CxWebClient login(this API_IE_CxWebClient cxClient, string username, string password)
7483
{
75-
cxClient.open("/CxWebClient/login.aspx");
76-
ie.field("txtUserName").value(username);
77-
ie.field("txtPassword").value(password);
78-
ie.button("Login").click();
84+
if (cxClient.loggedIn())
85+
"[API_IE_CxWebClient][login] user already logged in, skipping login".info();
86+
else
87+
{
88+
cxClient.open("/CxWebClient/login.aspx");
89+
ie.field("txtUserName").value(username);
90+
ie.field("txtPassword").value(password);
91+
ie.button("Login").click();
92+
}
7993
return cxClient;
8094
}
95+
96+
public static bool loggedIn(this API_IE_CxWebClient cxClient)
97+
{
98+
return ie.hasLink("Logout"); // better detection modes will be needed
99+
}
81100
}
82101
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.Linq;
3+
using System.Collections.Generic;
4+
using O2.DotNetWrappers.ExtensionMethods;
5+
using OpenQA.Selenium.Remote;
6+
using OpenQA.Selenium.Chrome;
7+
using OpenQA.Selenium.IE;
8+
using OpenQA.Selenium;
9+
//Installer:Selenium_Installer.cs!Selenium\net40\WebDriver.dll
10+
//O2File:SeleniumWebDrivers_Setup.cs
11+
namespace O2.XRules.Database.APIs
12+
{
13+
public class API_ChromeDriver
14+
{
15+
16+
}
17+
18+
public static class API_ChromeDriver_ExtensionMethods
19+
{
20+
public static ChromeDriver open(this ChromeDriver chromeDriver, string url)
21+
{
22+
chromeDriver.Navigate().GoToUrl(url);
23+
return chromeDriver;
24+
}
25+
26+
public static List<IWebElement> elements(this ChromeDriver chromeDriver)
27+
{
28+
return (from element in chromeDriver.FindElements(By.XPath("//*"))
29+
select element).toList();
30+
}
31+
public static List<string> ids(this List<IWebElement> elements)
32+
{
33+
return (from element in elements
34+
select element.GetAttribute("Id")).Distinct().toList().removeEmpty();
35+
}
36+
public static List<string> tagNames(this List<IWebElement> elements)
37+
{
38+
return (from element in elements
39+
select element.TagName).Distinct().toList();
40+
}
41+
}
42+
}
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
// This file is part of the OWASP O2 Platform (http://www.owasp.org/index.php/OWASP_O2_Platform) and is released under the Apache 2.0 License (http://www.apache.org/licenses/LICENSE-2.0)
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Windows.Forms;
5+
using System.Text;
6+
using System.Reflection;
7+
using System.Management;
8+
using System.Diagnostics;
9+
using O2.Kernel.ExtensionMethods;
10+
using O2.DotNetWrappers.DotNet;
11+
using O2.DotNetWrappers.ExtensionMethods;
12+
using O2.XRules.Database.Utils;
13+
using OpenQA.Selenium;
14+
using OpenQA.Selenium.Chrome;
15+
//O2File:API_Win32_Handle_Hijack.cs
16+
//O2Ref:Selenium\net40\WebDriver.dll
17+
//Installer:Selenium_Installer.cs!Selenium\net40\WebDriver.dll
18+
19+
//O2Ref:System.Management.dll
20+
21+
namespace O2.XRules.Database.APIs
22+
{
23+
public class API_Chrome_Hijack
24+
{
25+
public ChromeDriver ChromeDriver { get; set; }
26+
public ChromeOptions ChromeOptions { get; set; }
27+
public ChromeDriverService ChromeDriverService { get; set; }
28+
public Process ChromeDriverProcess { get; set; }
29+
public Process ChromeProcess { get; set; }
30+
public Panel Panel_Chrome { get; set; }
31+
public Panel Panel_ChromeDriver { get; set; }
32+
public ascx_Simple_Script_Editor WebDriver_Script_Me { get; set; }
33+
public string ChromeDriver_Exe { get; set; }
34+
public string WebDriver_Folder { get; set; }
35+
public string ChromeDriverDownloadLink { get; set; }
36+
37+
public API_Chrome_Hijack()
38+
{
39+
ChromeDriverDownloadLink = @"http://chromedriver.googlecode.com/files/chromedriver_win_26.0.1383.0.zip";
40+
WebDriver_Folder = @"Selenium\net40\WebDriver.dll".assembly().location().parentFolder();
41+
ChromeDriver_Exe = WebDriver_Folder.pathCombine("chromedriver.exe");
42+
ChromeOptions = new ChromeOptions();
43+
ChromeDriverService = ChromeDriverService.CreateDefaultService();
44+
}
45+
46+
public API_Chrome_Hijack ensureChromeDriverExists()
47+
{
48+
if (ChromeDriver_Exe.fileExists().isFalse())
49+
{
50+
var downloadedZipFile = ChromeDriverDownloadLink.download();
51+
downloadedZipFile.unzip_File(WebDriver_Folder);
52+
}
53+
return this;
54+
}
55+
56+
public API_Chrome_Hijack open_ChromeDriver()
57+
{
58+
ChromeDriver = new ChromeDriver(ChromeDriverService, ChromeOptions);
59+
60+
//resolve driverServiceProcess
61+
var fieldInfo = (FieldInfo)typeof(DriverService).field("driverServiceProcess");
62+
ChromeDriverProcess = (Process)fieldInfo.GetValue(ChromeDriverService);
63+
64+
ChromeDriverProcess.waitFor_MainWindowHandle();
65+
ChromeProcess = ChromeDriverProcess.getProcessWithParentHandle();
66+
67+
return this;
68+
}
69+
70+
}
71+
72+
73+
public static class API_Chrome_Test_ExtensionMethods
74+
{
75+
public static ChromeDriver add_Chrome(this Panel targetPanel)
76+
{
77+
return new API_Chrome_Hijack()
78+
.open_ChromeDriver()
79+
.hijack_Chrome(targetPanel,true)
80+
.ChromeDriver;
81+
}
82+
83+
public static API_Chrome_Hijack add_Chrome_To_Panel(this API_Chrome_Hijack chromeHijack, Panel targetPanel)
84+
{
85+
var chrome_Panel = targetPanel.add_GroupBox("Chrome").add_Panel();
86+
var chromeDriver_Panel = chromeHijack.Panel_Chrome.parent().insert_Below(150,"Chrome WebDriver");
87+
88+
return chromeHijack.hijack_Chrome (chrome_Panel,false)
89+
.hijack_ChromeDriver(chromeDriver_Panel);
90+
}
91+
92+
public static API_Chrome_Hijack hijack_Chrome(this API_Chrome_Hijack chromeHijack, Panel targetPanel, bool hijackJustViewer)
93+
{
94+
if (chromeHijack.notNull() && chromeHijack.ChromeProcess.notNull() && targetPanel.notNull())
95+
{
96+
chromeHijack.Panel_Chrome = targetPanel;
97+
var hijackGui = chromeHijack.Panel_Chrome.add_Handle_HijackGui(false);
98+
if (hijackJustViewer)
99+
{
100+
hijackGui.hijackProcessWindow(chromeHijack.ChromeProcess,
101+
(mainWindowHandle)=>
102+
{
103+
// this doesn't work well now since the main chrome window (with the address bar) still gains focus)
104+
// need to look at how to capture and filter events from the child to the parent (and vice versa)
105+
//
106+
var targetWindow = mainWindowHandle.child_Windows().second();
107+
return targetWindow;
108+
109+
return mainWindowHandle; // for now hijack the whole thing
110+
});
111+
112+
}
113+
else
114+
hijackGui.hijackProcessMainWindow(chromeHijack.ChromeProcess);
115+
}
116+
return chromeHijack;
117+
}
118+
119+
public static API_Chrome_Hijack hijack_ChromeDriver(this API_Chrome_Hijack chromeHijack, Panel targetPanel)
120+
{
121+
if (chromeHijack.notNull() && chromeHijack.ChromeDriverProcess.notNull() && targetPanel.notNull())
122+
{
123+
chromeHijack.Panel_ChromeDriver = targetPanel;
124+
chromeHijack.Panel_ChromeDriver.add_Handle_HijackGui(false)
125+
.hijackProcessMainWindow(chromeHijack.ChromeDriverProcess);
126+
}
127+
return chromeHijack;
128+
}
129+
130+
public static API_Chrome_Hijack add_WebDriver_ScriptMe_To(this API_Chrome_Hijack chromeHijack, Panel targetPanel)
131+
{
132+
133+
chromeHijack.WebDriver_Script_Me = chromeHijack.ChromeDriver.script_Me(targetPanel);
134+
return chromeHijack;
135+
}
136+
137+
public static Win32_Handle_Hijack hijack_Process_Into_Panel(this API_Chrome_Hijack chromeHijack, Panel targetPanel, Process targetProcess)
138+
{
139+
var hijackGui = targetPanel.add_Handle_HijackGui(false)
140+
.hijackProcessMainWindow(targetProcess);
141+
return hijackGui;
142+
}
143+
}
144+
145+
public static class Process_Extra_ExtensionMethods
146+
{
147+
public static Process getProcessWithParentHandle(this Process process)
148+
{
149+
if(process.isNotNull())
150+
{
151+
var selectQuery = "Select ProcessId from Win32_Process Where ParentProcessId = {0}".format(process.Id);;
152+
foreach(var proc in new ManagementObjectSearcher(selectQuery).Get())
153+
{
154+
var procId = (int)(UInt32)proc["ProcessId"];
155+
var foundProcess = procId.process_WithId();
156+
"foundProcess: {0}".debug(foundProcess);
157+
return foundProcess;
158+
}
159+
"Failed to find process with id: {0} name: {0}".error(process.Id, process.ProcessName);
160+
}
161+
return null;
162+
}
163+
}
164+
}
165+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var chromeHijack = new API_Chrome_Hijack();
2+
chromeHijack.script_Me("chromeHijack").insert_LogViewer();
3+
chromeHijack.open_ChromeDriver();
4+
5+
//O2File:API_Chrome_Hijack.cs
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//var topPanel = panel.add_Panel(true);
2+
var topPanel = "Util - REPL IE (native) and Chrome (hijacked window)".popupWindow(1200,600);
3+
var browsersPanel = topPanel.insert_Above();
4+
var ie = browsersPanel.title("IE").add_IE();
5+
var chrome = browsersPanel.insert_Right().add_Chrome();
6+
7+
var repl = topPanel.add_Script();
8+
repl.add_InvocationParameter("ie", ie);
9+
repl.add_InvocationParameter("chrome", chrome);
10+
11+
var firstScript =
12+
@"chrome.open(""http://o2platform.com"");
13+
ie.open(""http://o2platform.com"");
14+
15+
//return ie;
16+
return chrome;
17+
18+
//O2Ref:" + @"WatiN.Core.1x.dll
19+
//O2Ref:" + @"WebDriver.dll
20+
//O2File:" + @"WatiN_IE_ExtensionMethods.cs
21+
//O2File:" + @"API_Chrome_Hijack.cs
22+
//O2File:" + @"API_ChromeDriver.cs
23+
";
24+
repl.onCompileExecuteOnce()
25+
.set_Code(firstScript);
26+
//chrome.open("http://o2platform.com");
27+
28+
//O2Ref:WatiN.Core.1x.dll
29+
//O2Ref:WebDriver.dll
30+
//O2File:WatiN_IE_ExtensionMethods.cs
31+
//O2File:API_Chrome_Hijack.cs
32+
//O2File:API_ChromeDriver.cs

0 commit comments

Comments
 (0)