2 # -*- coding: utf-8 -*-
4 # ------------------------------------------------------------
7 # test the open security vmmanager
9 # Autor: Mihai Bartha, <mihai.bartha@ait.ac.at>
11 # Copyright 2013-2014 X-Net and AIT Austrian Institute of Technology
18 # https://www.x-net.at
20 # AIT Austrian Institute of Technology
21 # Donau City Strasse 1
24 # http://www.ait.ac.at
27 # Licensed under the Apache License, Version 2.0 (the "License");
28 # you may not use this file except in compliance with the License.
29 # You may obtain a copy of the License at
31 # http://www.apache.org/licenses/LICENSE-2.0
33 # Unless required by applicable law or agreed to in writing, software
34 # distributed under the License is distributed on an "AS IS" BASIS,
35 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
36 # See the License for the specific language governing permissions and
37 # limitations under the License.
38 # ------------------------------------------------------------
41 # ------------------------------------------------------------
56 class TestVMManager(unittest.TestCase):
64 gvm_mgr = vmmanager.VMManager.getInstance()
68 #def tearOffClass(self):
72 @unittest.skip("skipping")
73 def testGetTemplateUUID(self):
74 template = vmmanager.VMManager.getVDiskUUID(gvm_mgr.templateImage)
75 self.assertIsNotNone(template, "returned no UUID for template")
77 @unittest.skip("skipping")
78 def testUpdateTemplate(self):
79 gvm_mgr.updateTemplate()
82 def setKey(self, key, name, value):
83 _, reg_type = _winreg.QueryValueEx(key, name)
84 _winreg.SetValueEx(key, name, 0, reg_type, value)
86 @unittest.skip("skipping")
87 def testGetProxySettings(self):
88 #sudo echo "http_proxy=http://80.122.169.38:8080/" >> /etc/environment
89 aReg = _winreg.ConnectRegistry(None,_winreg.HKEY_CURRENT_USER)
90 aKey = _winreg.OpenKey(aReg, r"Software\Microsoft\Windows\CurrentVersion\Internet Settings")
91 subCount, valueCount, lastModified = _winreg.QueryInfoKey(aKey)
93 for i in range(valueCount):
95 n,v,t = _winreg.EnumValue(aKey,i)
97 except EnvironmentError:
99 _winreg.CloseKey(aKey)
101 if 'ProxyEnable' in proxy.keys() and proxy['ProxyEnable'] == 1:
102 print proxy['ProxyServer']
103 return proxy['ProxyServer']
107 @unittest.skip("skipping")
108 def testMatchProxy(self):
109 #http=212.17.86.109:8080;https=212.17.86.109:8080;ftp=212.17.86.109:8080
111 text = 'http=212.17.86.109:8080;https=212.17.86.109:8080;ftp=212.17.86.109:8080'
112 print re.search(r"(?<=http=)(?P<HttpProxy>.*?)(?=;)", text).groupdict()
113 print re.search(r"(?<=http=)(.*?)(?=;)", text)
117 @unittest.skip("skipping")
118 def testImportTemplate(self):
120 if 'SecurityDVM' in gvm_mgr.listVMS():
121 gvm_mgr.removeVM('SecurityDVM')
123 uuid = gvm_mgr.getVDiskUUID(gvm_mgr.templateImage)
125 gvm_mgr.removeImage(uuid)
127 gvm_mgr.removeVMFolder('SecurityDVM')
128 gvm_mgr.importTemplate('C:\Windows\System32\config\systemprofile\VirtualBox VMs\OsecVM.ova')
129 gvm_mgr.updateTemplate()
131 @unittest.skip("skipping")
132 def testHostOnlyDHCP(self):
134 #Cygwin.vboxExecute("list hostonlyifs")
136 hostonlyifs = gvm_mgr.getHostOnlyIFs()
139 dhcpservers = gvm_mgr.getDHCPServers()
142 def testBrowsingRequest(self):
144 gvm_mgr.handleBrowsingRequest()
148 if __name__ == '__main__':
149 TestVMManager.setUpClass()
151 suite = unittest.TestLoader().loadTestsFromTestCase(TestVMManager)
152 unittest.TextTestRunner().run(suite)
154 #VBoxManage list hostonlyifs
155 #VBoxManage list dhcpservers
156 #VBoxManage dhcpserver remove --netname "HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter"
157 #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
158 #VBoxManage dhcpserver modify --ifname "VirtualBox Host-Only Ethernet Adapter" --enable
159 #VBoxManage hostonlyif ipconfig "VirtualBox Host-Only Ethernet Adapter" --dhcp
160 #VBoxManage hostonlyif ipconfig "VirtualBox Host-Only Ethernet Adapter" --ip 192.168.56.1 --netmask 255.255.255.0
161 # logger = setupLogger('Cygwin')
164 #man = VMManager.getInstance()
166 #print man.getConnectedRSDs()
167 #print man.getNetworkDrives()
168 #man.genNetworkDrive()
169 #drive_bitmask = ctypes.cdll.kernel32.GetLogicalDrives()
170 #print list(itertools.compress(string.ascii_uppercase, map(lambda x:ord(x) - ord('0'), bin(drive_bitmask)[:1:-1])))
171 #print list(map(chr, range(68, 91)))
172 #print Cygwin.getRegEntry('SYSTEM\CurrentControlSet\Enum\USB', 'VID_1058&PID_0704')[0]
173 #devices = VMManager.getConnectedRSDS()
176 #drives = VMManager.getLogicalDrives()
178 #print VMManager.getDriveType("E")
179 #print VMManager.getVolumeInfo("E")
180 #print VMManager.getNetworkPath("E")
183 #for device in devices.values():
185 # if VMManager.isMassStorageDevice(device):
195 #man.genCertificateISO('SecurityDVM0')
196 #man.guestExecute('SecurityDVM0', '/bin/ls -la')
197 #logger = setupLogger('VMManager')
200 #man.sshExecute('/bin/ls -la', 'SecurityDVM0')
201 #man.sshExecuteX11('/usr/bin/iceweasel', 'SecurityDVM0')
202 #man.removeVM('SecurityDVM0')
203 #man.netUse('192.168.56.134', 'USB\\')
204 #ip = '192.168.56.139'
206 #man.cygwin_path = 'c:\\cygwin64\\bin\\'
207 #man.handleDeviceChange()
208 #print man.listSDVM()
209 #man.configureHostNetworking()
210 #new_vm = man.generateSDVMName()
211 #man.createVM(new_vm)
214 #man.isAvailable('c:')
215 #ip = man.getHostOnlyIP('SecurityDVM0')
216 #man.mapNetworkDrive('h:', '\\\\' + ip + '\Download', None, None)
218 #man.genCertificateISO(new_vm)
219 #man.attachCertificateISO(new_vm)
221 #man.attachCertificateISO(vm_name)
222 #man.guestExecute(vm_name, "ls")
223 #man.sshGuestX11Execute('SecurityDVM1', '/usr/bin/iceweasel')
225 #print man.cygwinPath("C:\Users\BarthaM\VirtualBox VMs\SecurityDVM\.ssh\*")
226 #man.genCertificateISO('SecurityDVM')
227 #man.attachCertificateISO('SecurityDVM')
228 #man.isStorageAttached('SecurityDVM')
229 #man.guestExecute('SecurityDVM', 'sudo apt-get -y update')
230 #man.guestExecute('SecurityDVM', 'sudo apt-get -y upgrade' )
232 #man.stopVM('SecurityDVM')
233 #man.detachStorage('SecurityDVM')
234 #man.changeStorageType('C:\Users\BarthaM\VirtualBox VMs\SecurityDVM\SecurityDVM.vmdk','immutable')
235 #man.storageAttach('SecurityDVM')
238 #cmd = "c:\\cygwin64\\bin\\bash.exe --login -c \"/bin/ls\""