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 # ------------------------------------------------------------
46 class TestVMManager(unittest.TestCase):
54 gvm_mgr = vmmanager.VMManager.getInstance()
57 @unittest.skip("skipping")
58 def testGetTemplateUUID(self):
59 template = vmmanager.VMManager.getVDiskUUID(gvm_mgr.templateImage)
60 self.assertIsNotNone(template, "returned no UUID for template")
62 @unittest.skip("skipping")
63 def testUpdateTemplate(self):
64 gvm_mgr.updateTemplate()
67 def setKey(self, key, name, value):
68 _, reg_type = _winreg.QueryValueEx(key, name)
69 _winreg.SetValueEx(key, name, 0, reg_type, value)
71 @unittest.skip("skipping")
72 def testGetProxySettings(self):
73 #sudo echo "http_proxy=http://80.122.169.38:8080/" >> /etc/environment
74 aReg = _winreg.ConnectRegistry(None,_winreg.HKEY_CURRENT_USER)
75 aKey = _winreg.OpenKey(aReg, r"Software\Microsoft\Windows\CurrentVersion\Internet Settings")
76 subCount, valueCount, lastModified = _winreg.QueryInfoKey(aKey)
78 for i in range(valueCount):
80 n,v,t = _winreg.EnumValue(aKey,i)
82 except EnvironmentError:
84 _winreg.CloseKey(aKey)
86 if 'ProxyEnable' in proxy.keys() and proxy['ProxyEnable'] == 1:
87 print proxy['ProxyServer']
88 return proxy['ProxyServer']
92 @unittest.skip("skipping")
93 def testMatchProxy(self):
94 #http=212.17.86.109:8080;https=212.17.86.109:8080;ftp=212.17.86.109:8080
96 text = 'http=212.17.86.109:8080;https=212.17.86.109:8080;ftp=212.17.86.109:8080'
97 print re.search(r"(?<=http=)(?P<HttpProxy>.*?)(?=;)", text).groupdict()
98 print re.search(r"(?<=http=)(.*?)(?=;)", text)
101 #def tearOffClass(self):
106 def testImportTemplate(self):
108 if 'SecurityDVM' in gvm_mgr.listVMS():
109 gvm_mgr.removeVM('SecurityDVM')
111 uuid = gvm_mgr.getVDiskUUID(gvm_mgr.templateImage)
113 gvm_mgr.removeImage(uuid)
115 gvm_mgr.removeVMFolder('SecurityDVM')
116 gvm_mgr.importTemplate('C:\Windows\System32\config\systemprofile\VirtualBox VMs\OsecVM.ova')
117 gvm_mgr.updateTemplate()
118 #VBoxManage list hostonlyifs
119 #VBoxManage list dhcpservers
120 #VBoxManage dhcpserver remove --netname "HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter"
121 #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
122 #VBoxManage dhcpserver modify --ifname "VirtualBox Host-Only Ethernet Adapter" --enable
123 #VBoxManage hostonlyif ipconfig "VirtualBox Host-Only Ethernet Adapter" --dhcp
124 #VBoxManage hostonlyif ipconfig "VirtualBox Host-Only Ethernet Adapter" --ip 192.168.56.1 --netmask 255.255.255.0
128 def testHostOnlyDHCP(self):
130 #Cygwin.vboxExecute("list hostonlyifs")
132 hostonlyifs = gvm_mgr.getHostOnlyIFs()
135 dhcpservers = gvm_mgr.getDHCPServers()
138 if __name__ == '__main__':
139 TestVMManager.setUpClass()
141 suite = unittest.TestLoader().loadTestsFromTestCase(TestVMManager)
142 unittest.TextTestRunner().run(suite)
144 # logger = setupLogger('Cygwin')
147 #man = VMManager.getInstance()
149 #print man.getConnectedRSDs()
150 #print man.getNetworkDrives()
151 #man.genNetworkDrive()
152 #drive_bitmask = ctypes.cdll.kernel32.GetLogicalDrives()
153 #print list(itertools.compress(string.ascii_uppercase, map(lambda x:ord(x) - ord('0'), bin(drive_bitmask)[:1:-1])))
154 #print list(map(chr, range(68, 91)))
155 #print Cygwin.getRegEntry('SYSTEM\CurrentControlSet\Enum\USB', 'VID_1058&PID_0704')[0]
156 #devices = VMManager.getConnectedRSDS()
159 #drives = VMManager.getLogicalDrives()
161 #print VMManager.getDriveType("E")
162 #print VMManager.getVolumeInfo("E")
163 #print VMManager.getNetworkPath("E")
166 #for device in devices.values():
168 # if VMManager.isMassStorageDevice(device):
178 #man.genCertificateISO('SecurityDVM0')
179 #man.guestExecute('SecurityDVM0', '/bin/ls -la')
180 #logger = setupLogger('VMManager')
183 #man.sshExecute('/bin/ls -la', 'SecurityDVM0')
184 #man.sshExecuteX11('/usr/bin/iceweasel', 'SecurityDVM0')
185 #man.removeVM('SecurityDVM0')
186 #man.netUse('192.168.56.134', 'USB\\')
187 #ip = '192.168.56.139'
189 #man.cygwin_path = 'c:\\cygwin64\\bin\\'
190 #man.handleDeviceChange()
191 #print man.listSDVM()
192 #man.configureHostNetworking()
193 #new_vm = man.generateSDVMName()
194 #man.createVM(new_vm)
197 #man.isAvailable('c:')
198 #ip = man.getHostOnlyIP('SecurityDVM0')
199 #man.mapNetworkDrive('h:', '\\\\' + ip + '\Download', None, None)
201 #man.genCertificateISO(new_vm)
202 #man.attachCertificateISO(new_vm)
204 #man.attachCertificateISO(vm_name)
205 #man.guestExecute(vm_name, "ls")
206 #man.sshGuestX11Execute('SecurityDVM1', '/usr/bin/iceweasel')
208 #print man.cygwinPath("C:\Users\BarthaM\VirtualBox VMs\SecurityDVM\.ssh\*")
209 #man.genCertificateISO('SecurityDVM')
210 #man.attachCertificateISO('SecurityDVM')
211 #man.isStorageAttached('SecurityDVM')
212 #man.guestExecute('SecurityDVM', 'sudo apt-get -y update')
213 #man.guestExecute('SecurityDVM', 'sudo apt-get -y upgrade' )
215 #man.stopVM('SecurityDVM')
216 #man.detachStorage('SecurityDVM')
217 #man.changeStorageType('C:\Users\BarthaM\VirtualBox VMs\SecurityDVM\SecurityDVM.vmdk','immutable')
218 #man.storageAttach('SecurityDVM')
221 #cmd = "c:\\cygwin64\\bin\\bash.exe --login -c \"/bin/ls\""