- changed opensecurity to always hold at least 2 SDVM sessions to be ready when needed
- added automatic wpad proxy detection
2 # -*- coding: utf-8 -*-
4 # ------------------------------------------------------------
7 # the opensecurityd as RESTful server
9 # Autor: Mihai Bartha, <mihai.bartha@ait.ac.at>
11 # Copyright (C) 2013 AIT Austrian Institute of Technology
12 # AIT Austrian Institute of Technology GmbH
13 # Donau-City-Strasse 1 | 1220 Vienna | Austria
14 # http://www.ait.ac.at
16 # This program is free software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License
18 # as published by the Free Software Foundation version 2.
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 51 Franklin Street, Fifth Floor,
28 # Boston, MA 02110-1301, USA.
29 # ------------------------------------------------------------
32 # ------------------------------------------------------------
47 class TestVMManager(unittest.TestCase):
55 gvm_mgr = vmmanager.VMManager.getInstance()
59 #def tearOffClass(self):
63 @unittest.skip("skipping")
64 def testGetTemplateUUID(self):
65 template = vmmanager.VMManager.getVDiskUUID(gvm_mgr.templateImage)
66 self.assertIsNotNone(template, "returned no UUID for template")
68 @unittest.skip("skipping")
69 def testUpdateTemplate(self):
70 gvm_mgr.updateTemplate()
73 def setKey(self, key, name, value):
74 _, reg_type = _winreg.QueryValueEx(key, name)
75 _winreg.SetValueEx(key, name, 0, reg_type, value)
77 @unittest.skip("skipping")
78 def testGetProxySettings(self):
79 #sudo echo "http_proxy=http://80.122.169.38:8080/" >> /etc/environment
80 aReg = _winreg.ConnectRegistry(None,_winreg.HKEY_CURRENT_USER)
81 aKey = _winreg.OpenKey(aReg, r"Software\Microsoft\Windows\CurrentVersion\Internet Settings")
82 subCount, valueCount, lastModified = _winreg.QueryInfoKey(aKey)
84 for i in range(valueCount):
86 n,v,t = _winreg.EnumValue(aKey,i)
88 except EnvironmentError:
90 _winreg.CloseKey(aKey)
92 if 'ProxyEnable' in proxy.keys() and proxy['ProxyEnable'] == 1:
93 print proxy['ProxyServer']
94 return proxy['ProxyServer']
98 @unittest.skip("skipping")
99 def testMatchProxy(self):
100 #http=212.17.86.109:8080;https=212.17.86.109:8080;ftp=212.17.86.109:8080
102 text = 'http=212.17.86.109:8080;https=212.17.86.109:8080;ftp=212.17.86.109:8080'
103 print re.search(r"(?<=http=)(?P<HttpProxy>.*?)(?=;)", text).groupdict()
104 print re.search(r"(?<=http=)(.*?)(?=;)", text)
108 @unittest.skip("skipping")
109 def testImportTemplate(self):
111 if 'SecurityDVM' in gvm_mgr.listVMS():
112 gvm_mgr.removeVM('SecurityDVM')
114 uuid = gvm_mgr.getVDiskUUID(gvm_mgr.templateImage)
116 gvm_mgr.removeImage(uuid)
118 gvm_mgr.removeVMFolder('SecurityDVM')
119 gvm_mgr.importTemplate('C:\Windows\System32\config\systemprofile\VirtualBox VMs\OsecVM.ova')
120 gvm_mgr.updateTemplate()
122 @unittest.skip("skipping")
123 def testHostOnlyDHCP(self):
125 #Cygwin.vboxExecute("list hostonlyifs")
127 hostonlyifs = gvm_mgr.getHostOnlyIFs()
130 dhcpservers = gvm_mgr.getDHCPServers()
133 def testBrowsingRequest(self):
135 gvm_mgr.handleBrowsingRequest()
139 if __name__ == '__main__':
140 TestVMManager.setUpClass()
142 suite = unittest.TestLoader().loadTestsFromTestCase(TestVMManager)
143 unittest.TextTestRunner().run(suite)
145 #VBoxManage list hostonlyifs
146 #VBoxManage list dhcpservers
147 #VBoxManage dhcpserver remove --netname "HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter"
148 #VBoxManage dhcpserver add --ifname "VirtualBox Host-Only Ethernet Adapter" --ip 192.168.56.100 --netmask 255.255.255.0 --lowerip 192.168.56.101 --upperip 192.168.56.254 --enable
149 #VBoxManage dhcpserver modify --ifname "VirtualBox Host-Only Ethernet Adapter" --enable
150 #VBoxManage hostonlyif ipconfig "VirtualBox Host-Only Ethernet Adapter" --dhcp
151 #VBoxManage hostonlyif ipconfig "VirtualBox Host-Only Ethernet Adapter" --ip 192.168.56.1 --netmask 255.255.255.0
152 # logger = setupLogger('Cygwin')
155 #man = VMManager.getInstance()
157 #print man.getConnectedRSDs()
158 #print man.getNetworkDrives()
159 #man.genNetworkDrive()
160 #drive_bitmask = ctypes.cdll.kernel32.GetLogicalDrives()
161 #print list(itertools.compress(string.ascii_uppercase, map(lambda x:ord(x) - ord('0'), bin(drive_bitmask)[:1:-1])))
162 #print list(map(chr, range(68, 91)))
163 #print Cygwin.getRegEntry('SYSTEM\CurrentControlSet\Enum\USB', 'VID_1058&PID_0704')[0]
164 #devices = VMManager.getConnectedRSDS()
167 #drives = VMManager.getLogicalDrives()
169 #print VMManager.getDriveType("E")
170 #print VMManager.getVolumeInfo("E")
171 #print VMManager.getNetworkPath("E")
174 #for device in devices.values():
176 # if VMManager.isMassStorageDevice(device):
186 #man.genCertificateISO('SecurityDVM0')
187 #man.guestExecute('SecurityDVM0', '/bin/ls -la')
188 #logger = setupLogger('VMManager')
191 #man.sshExecute('/bin/ls -la', 'SecurityDVM0')
192 #man.sshExecuteX11('/usr/bin/iceweasel', 'SecurityDVM0')
193 #man.removeVM('SecurityDVM0')
194 #man.netUse('192.168.56.134', 'USB\\')
195 #ip = '192.168.56.139'
197 #man.cygwin_path = 'c:\\cygwin64\\bin\\'
198 #man.handleDeviceChange()
199 #print man.listSDVM()
200 #man.configureHostNetworking()
201 #new_vm = man.generateSDVMName()
202 #man.createVM(new_vm)
205 #man.isAvailable('c:')
206 #ip = man.getHostOnlyIP('SecurityDVM0')
207 #man.mapNetworkDrive('h:', '\\\\' + ip + '\Download', None, None)
209 #man.genCertificateISO(new_vm)
210 #man.attachCertificateISO(new_vm)
212 #man.attachCertificateISO(vm_name)
213 #man.guestExecute(vm_name, "ls")
214 #man.sshGuestX11Execute('SecurityDVM1', '/usr/bin/iceweasel')
216 #print man.cygwinPath("C:\Users\BarthaM\VirtualBox VMs\SecurityDVM\.ssh\*")
217 #man.genCertificateISO('SecurityDVM')
218 #man.attachCertificateISO('SecurityDVM')
219 #man.isStorageAttached('SecurityDVM')
220 #man.guestExecute('SecurityDVM', 'sudo apt-get -y update')
221 #man.guestExecute('SecurityDVM', 'sudo apt-get -y upgrade' )
223 #man.stopVM('SecurityDVM')
224 #man.detachStorage('SecurityDVM')
225 #man.changeStorageType('C:\Users\BarthaM\VirtualBox VMs\SecurityDVM\SecurityDVM.vmdk','immutable')
226 #man.storageAttach('SecurityDVM')
229 #cmd = "c:\\cygwin64\\bin\\bash.exe --login -c \"/bin/ls\""