Addded http proxy server support.
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 def testMatchProxy(self):
93 #http=212.17.86.109:8080;https=212.17.86.109:8080;ftp=212.17.86.109:8080
95 text = 'http=212.17.86.109:8080;https=212.17.86.109:8080;ftp=212.17.86.109:8080'
96 print re.search(r"(?<=http=)(?P<HttpProxy>.*?)(?=;)", text).groupdict()
97 print re.search(r"(?<=http=)(.*?)(?=;)", text)
100 #def tearOffClass(self):
105 if __name__ == '__main__':
106 TestVMManager.setUpClass()
108 suite = unittest.TestLoader().loadTestsFromTestCase(TestVMManager)
109 unittest.TextTestRunner().run(suite)
111 # logger = setupLogger('Cygwin')
114 #man = VMManager.getInstance()
116 #print man.getConnectedRSDs()
117 #print man.getNetworkDrives()
118 #man.genNetworkDrive()
119 #drive_bitmask = ctypes.cdll.kernel32.GetLogicalDrives()
120 #print list(itertools.compress(string.ascii_uppercase, map(lambda x:ord(x) - ord('0'), bin(drive_bitmask)[:1:-1])))
121 #print list(map(chr, range(68, 91)))
122 #print Cygwin.getRegEntry('SYSTEM\CurrentControlSet\Enum\USB', 'VID_1058&PID_0704')[0]
123 #devices = VMManager.getConnectedRSDS()
126 #drives = VMManager.getLogicalDrives()
128 #print VMManager.getDriveType("E")
129 #print VMManager.getVolumeInfo("E")
130 #print VMManager.getNetworkPath("E")
133 #for device in devices.values():
135 # if VMManager.isMassStorageDevice(device):
145 #man.genCertificateISO('SecurityDVM0')
146 #man.guestExecute('SecurityDVM0', '/bin/ls -la')
147 #logger = setupLogger('VMManager')
150 #man.sshExecute('/bin/ls -la', 'SecurityDVM0')
151 #man.sshExecuteX11('/usr/bin/iceweasel', 'SecurityDVM0')
152 #man.removeVM('SecurityDVM0')
153 #man.netUse('192.168.56.134', 'USB\\')
154 #ip = '192.168.56.139'
156 #man.cygwin_path = 'c:\\cygwin64\\bin\\'
157 #man.handleDeviceChange()
158 #print man.listSDVM()
159 #man.configureHostNetworking()
160 #new_vm = man.generateSDVMName()
161 #man.createVM(new_vm)
164 #man.isAvailable('c:')
165 #ip = man.getHostOnlyIP('SecurityDVM0')
166 #man.mapNetworkDrive('h:', '\\\\' + ip + '\Download', None, None)
168 #man.genCertificateISO(new_vm)
169 #man.attachCertificateISO(new_vm)
171 #man.attachCertificateISO(vm_name)
172 #man.guestExecute(vm_name, "ls")
173 #man.sshGuestX11Execute('SecurityDVM1', '/usr/bin/iceweasel')
175 #print man.cygwinPath("C:\Users\BarthaM\VirtualBox VMs\SecurityDVM\.ssh\*")
176 #man.genCertificateISO('SecurityDVM')
177 #man.attachCertificateISO('SecurityDVM')
178 #man.isStorageAttached('SecurityDVM')
179 #man.guestExecute('SecurityDVM', 'sudo apt-get -y update')
180 #man.guestExecute('SecurityDVM', 'sudo apt-get -y upgrade' )
182 #man.stopVM('SecurityDVM')
183 #man.storageDetach('SecurityDVM')
184 #man.changeStorageType('C:\Users\BarthaM\VirtualBox VMs\SecurityDVM\SecurityDVM.vmdk','immutable')
185 #man.storageAttach('SecurityDVM')
188 #cmd = "c:\\cygwin64\\bin\\bash.exe --login -c \"/bin/ls\""