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.getTemplateUUID()
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 #VBoxManage list hostonlyifs
107 #VBoxManage list dhcpservers
108 #VBoxManage dhcpserver remove --netname "HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter"
109 #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
110 #VBoxManage dhcpserver modify --ifname "VirtualBox Host-Only Ethernet Adapter" --enable
111 #VBoxManage hostonlyif ipconfig "VirtualBox Host-Only Ethernet Adapter" --dhcp
112 #VBoxManage hostonlyif ipconfig "VirtualBox Host-Only Ethernet Adapter" --ip 192.168.56.1 --netmask 255.255.255.0
116 def testHostOnlyDHCP(self):
118 #Cygwin.vboxExecute("list hostonlyifs")
120 hostonlyifs = gvm_mgr.getHostOnlyIFs()
123 dhcpservers = gvm_mgr.getDHCPServers()
126 if __name__ == '__main__':
127 TestVMManager.setUpClass()
129 suite = unittest.TestLoader().loadTestsFromTestCase(TestVMManager)
130 unittest.TextTestRunner().run(suite)
132 # logger = setupLogger('Cygwin')
135 #man = VMManager.getInstance()
137 #print man.getConnectedRSDs()
138 #print man.getNetworkDrives()
139 #man.genNetworkDrive()
140 #drive_bitmask = ctypes.cdll.kernel32.GetLogicalDrives()
141 #print list(itertools.compress(string.ascii_uppercase, map(lambda x:ord(x) - ord('0'), bin(drive_bitmask)[:1:-1])))
142 #print list(map(chr, range(68, 91)))
143 #print Cygwin.getRegEntry('SYSTEM\CurrentControlSet\Enum\USB', 'VID_1058&PID_0704')[0]
144 #devices = VMManager.getConnectedRSDS()
147 #drives = VMManager.getLogicalDrives()
149 #print VMManager.getDriveType("E")
150 #print VMManager.getVolumeInfo("E")
151 #print VMManager.getNetworkPath("E")
154 #for device in devices.values():
156 # if VMManager.isMassStorageDevice(device):
166 #man.genCertificateISO('SecurityDVM0')
167 #man.guestExecute('SecurityDVM0', '/bin/ls -la')
168 #logger = setupLogger('VMManager')
171 #man.sshExecute('/bin/ls -la', 'SecurityDVM0')
172 #man.sshExecuteX11('/usr/bin/iceweasel', 'SecurityDVM0')
173 #man.removeVM('SecurityDVM0')
174 #man.netUse('192.168.56.134', 'USB\\')
175 #ip = '192.168.56.139'
177 #man.cygwin_path = 'c:\\cygwin64\\bin\\'
178 #man.handleDeviceChange()
179 #print man.listSDVM()
180 #man.configureHostNetworking()
181 #new_vm = man.generateSDVMName()
182 #man.createVM(new_vm)
185 #man.isAvailable('c:')
186 #ip = man.getHostOnlyIP('SecurityDVM0')
187 #man.mapNetworkDrive('h:', '\\\\' + ip + '\Download', None, None)
189 #man.genCertificateISO(new_vm)
190 #man.attachCertificateISO(new_vm)
192 #man.attachCertificateISO(vm_name)
193 #man.guestExecute(vm_name, "ls")
194 #man.sshGuestX11Execute('SecurityDVM1', '/usr/bin/iceweasel')
196 #print man.cygwinPath("C:\Users\BarthaM\VirtualBox VMs\SecurityDVM\.ssh\*")
197 #man.genCertificateISO('SecurityDVM')
198 #man.attachCertificateISO('SecurityDVM')
199 #man.isStorageAttached('SecurityDVM')
200 #man.guestExecute('SecurityDVM', 'sudo apt-get -y update')
201 #man.guestExecute('SecurityDVM', 'sudo apt-get -y upgrade' )
203 #man.stopVM('SecurityDVM')
204 #man.storageDetach('SecurityDVM')
205 #man.changeStorageType('C:\Users\BarthaM\VirtualBox VMs\SecurityDVM\SecurityDVM.vmdk','immutable')
206 #man.storageAttach('SecurityDVM')
209 #cmd = "c:\\cygwin64\\bin\\bash.exe --login -c \"/bin/ls\""