BarthaM@212: #!/bin/env python BarthaM@212: # -*- coding: utf-8 -*- BarthaM@212: BarthaM@212: # ------------------------------------------------------------ oliver@240: # test_vmmanger oliver@240: # oliver@240: # test the open security vmmanager BarthaM@212: # BarthaM@212: # Autor: Mihai Bartha, BarthaM@212: # oliver@240: # Copyright 2013-2014 X-Net and AIT Austrian Institute of Technology BarthaM@212: # BarthaM@212: # oliver@240: # X-Net Services GmbH oliver@240: # Elisabethstrasse 1 oliver@240: # 4020 Linz oliver@240: # AUSTRIA oliver@240: # https://www.x-net.at oliver@240: # oliver@240: # AIT Austrian Institute of Technology oliver@240: # Donau City Strasse 1 oliver@240: # 1220 Wien oliver@240: # AUSTRIA oliver@240: # http://www.ait.ac.at oliver@240: # oliver@240: # oliver@240: # Licensed under the Apache License, Version 2.0 (the "License"); oliver@240: # you may not use this file except in compliance with the License. oliver@240: # You may obtain a copy of the License at oliver@240: # oliver@240: # http://www.apache.org/licenses/LICENSE-2.0 oliver@240: # oliver@240: # Unless required by applicable law or agreed to in writing, software oliver@240: # distributed under the License is distributed on an "AS IS" BASIS, oliver@240: # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. oliver@240: # See the License for the specific language governing permissions and oliver@240: # limitations under the License. BarthaM@212: # ------------------------------------------------------------ BarthaM@212: BarthaM@212: BarthaM@212: # ------------------------------------------------------------ BarthaM@212: # imports BarthaM@212: BarthaM@212: import unittest BarthaM@212: BarthaM@212: import os BarthaM@213: import re BarthaM@212: import os.path BarthaM@212: import sys BarthaM@212: import cygwin BarthaM@212: import vmmanager BarthaM@213: import _winreg BarthaM@234: import time BarthaM@212: gvm_mgr = None BarthaM@212: BarthaM@212: class TestVMManager(unittest.TestCase): BarthaM@212: BarthaM@212: def setUp(self): BarthaM@212: pass BarthaM@212: BarthaM@212: @classmethod BarthaM@212: def setUpClass(self): BarthaM@212: global gvm_mgr BarthaM@212: gvm_mgr = vmmanager.VMManager.getInstance() BarthaM@212: pass BarthaM@212: BarthaM@234: #@classmethod BarthaM@234: #def tearOffClass(self): BarthaM@234: # gvm_mgr.stop() BarthaM@234: # gvm_mgr.cleanup() BarthaM@234: BarthaM@212: @unittest.skip("skipping") BarthaM@212: def testGetTemplateUUID(self): BarthaM@221: template = vmmanager.VMManager.getVDiskUUID(gvm_mgr.templateImage) BarthaM@212: self.assertIsNotNone(template, "returned no UUID for template") BarthaM@212: BarthaM@213: @unittest.skip("skipping") BarthaM@212: def testUpdateTemplate(self): BarthaM@212: gvm_mgr.updateTemplate() BarthaM@212: pass BarthaM@212: BarthaM@213: def setKey(self, key, name, value): BarthaM@213: _, reg_type = _winreg.QueryValueEx(key, name) BarthaM@213: _winreg.SetValueEx(key, name, 0, reg_type, value) BarthaM@213: BarthaM@213: @unittest.skip("skipping") BarthaM@213: def testGetProxySettings(self): BarthaM@213: #sudo echo "http_proxy=http://80.122.169.38:8080/" >> /etc/environment BarthaM@213: aReg = _winreg.ConnectRegistry(None,_winreg.HKEY_CURRENT_USER) BarthaM@213: aKey = _winreg.OpenKey(aReg, r"Software\Microsoft\Windows\CurrentVersion\Internet Settings") BarthaM@213: subCount, valueCount, lastModified = _winreg.QueryInfoKey(aKey) BarthaM@213: proxy = dict() BarthaM@213: for i in range(valueCount): BarthaM@213: try: BarthaM@213: n,v,t = _winreg.EnumValue(aKey,i) BarthaM@213: proxy[n] = v BarthaM@213: except EnvironmentError: BarthaM@213: break BarthaM@213: _winreg.CloseKey(aKey) BarthaM@213: print proxy BarthaM@213: if 'ProxyEnable' in proxy.keys() and proxy['ProxyEnable'] == 1: BarthaM@213: print proxy['ProxyServer'] BarthaM@213: return proxy['ProxyServer'] BarthaM@213: else: BarthaM@213: return "" BarthaM@217: BarthaM@217: @unittest.skip("skipping") BarthaM@213: def testMatchProxy(self): BarthaM@213: #http=212.17.86.109:8080;https=212.17.86.109:8080;ftp=212.17.86.109:8080 BarthaM@213: #212.17.86.109:8080 BarthaM@213: text = 'http=212.17.86.109:8080;https=212.17.86.109:8080;ftp=212.17.86.109:8080' BarthaM@213: print re.search(r"(?<=http=)(?P.*?)(?=;)", text).groupdict() BarthaM@213: print re.search(r"(?<=http=)(.*?)(?=;)", text) BarthaM@213: BarthaM@217: BarthaM@217: BarthaM@234: @unittest.skip("skipping") BarthaM@221: def testImportTemplate(self): BarthaM@221: gvm_mgr.cleanup() BarthaM@221: if 'SecurityDVM' in gvm_mgr.listVMS(): BarthaM@221: gvm_mgr.removeVM('SecurityDVM') BarthaM@221: BarthaM@221: uuid = gvm_mgr.getVDiskUUID(gvm_mgr.templateImage) BarthaM@221: if uuid: BarthaM@221: gvm_mgr.removeImage(uuid) BarthaM@221: BarthaM@221: gvm_mgr.removeVMFolder('SecurityDVM') BarthaM@221: gvm_mgr.importTemplate('C:\Windows\System32\config\systemprofile\VirtualBox VMs\OsecVM.ova') BarthaM@221: gvm_mgr.updateTemplate() BarthaM@234: BarthaM@234: @unittest.skip("skipping") BarthaM@217: def testHostOnlyDHCP(self): BarthaM@217: #list hostonlyifs BarthaM@217: #Cygwin.vboxExecute("list hostonlyifs") BarthaM@212: BarthaM@217: hostonlyifs = gvm_mgr.getHostOnlyIFs() BarthaM@217: print hostonlyifs BarthaM@217: BarthaM@217: dhcpservers = gvm_mgr.getDHCPServers() BarthaM@217: print dhcpservers mihai@252: mihai@252: @unittest.skip("skipping") BarthaM@234: def testBrowsingRequest(self): BarthaM@234: gvm_mgr.start() BarthaM@234: gvm_mgr.handleBrowsingRequest() BarthaM@234: time.sleep(3000) BarthaM@234: pass mihai@252: mihai@252: def testRsync(self): mihai@252: gvm_mgr.start() mihai@252: mihai@252: gvm_mgr.syncRemoteFile("SecurityDVM0", gvm_mgr.getHostOnlyIP("SecurityDVM0"), gvm_mgr.getAppDataDir() + '/OpenSecurity/chromium', '/home/osecuser/.config/') mihai@252: pass mihai@252: BarthaM@234: BarthaM@212: if __name__ == '__main__': BarthaM@212: TestVMManager.setUpClass() BarthaM@212: BarthaM@212: suite = unittest.TestLoader().loadTestsFromTestCase(TestVMManager) BarthaM@212: unittest.TextTestRunner().run(suite) BarthaM@212: BarthaM@234: #VBoxManage list hostonlyifs BarthaM@234: #VBoxManage list dhcpservers BarthaM@234: #VBoxManage dhcpserver remove --netname "HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter" BarthaM@234: #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 BarthaM@234: #VBoxManage dhcpserver modify --ifname "VirtualBox Host-Only Ethernet Adapter" --enable BarthaM@234: #VBoxManage hostonlyif ipconfig "VirtualBox Host-Only Ethernet Adapter" --dhcp BarthaM@234: #VBoxManage hostonlyif ipconfig "VirtualBox Host-Only Ethernet Adapter" --ip 192.168.56.1 --netmask 255.255.255.0 BarthaM@212: # logger = setupLogger('Cygwin') BarthaM@212: # c = Cygwin() BarthaM@212: # unittest.main() BarthaM@212: #man = VMManager.getInstance() BarthaM@212: #man.listVM() BarthaM@212: #print man.getConnectedRSDs() BarthaM@212: #print man.getNetworkDrives() BarthaM@212: #man.genNetworkDrive() BarthaM@212: #drive_bitmask = ctypes.cdll.kernel32.GetLogicalDrives() BarthaM@212: #print list(itertools.compress(string.ascii_uppercase, map(lambda x:ord(x) - ord('0'), bin(drive_bitmask)[:1:-1]))) BarthaM@212: #print list(map(chr, range(68, 91))) BarthaM@212: #print Cygwin.getRegEntry('SYSTEM\CurrentControlSet\Enum\USB', 'VID_1058&PID_0704')[0] BarthaM@212: #devices = VMManager.getConnectedRSDS() BarthaM@212: #print devices BarthaM@212: BarthaM@212: #drives = VMManager.getLogicalDrives() BarthaM@212: #print drives BarthaM@212: #print VMManager.getDriveType("E") BarthaM@212: #print VMManager.getVolumeInfo("E") BarthaM@212: #print VMManager.getNetworkPath("E") BarthaM@212: BarthaM@212: #vmm.backupFile() BarthaM@212: #for device in devices.values(): BarthaM@212: # #print device BarthaM@212: # if VMManager.isMassStorageDevice(device): BarthaM@212: # print device BarthaM@212: BarthaM@212: BarthaM@212: BarthaM@212: #time.sleep(-1) BarthaM@212: #man.listVM() BarthaM@212: #man.listVM() BarthaM@212: #man.listVM() BarthaM@212: #man.listVM() BarthaM@212: #man.genCertificateISO('SecurityDVM0') BarthaM@212: #man.guestExecute('SecurityDVM0', '/bin/ls -la') BarthaM@212: #logger = setupLogger('VMManager') BarthaM@212: #c = Cygwin() BarthaM@212: BarthaM@212: #man.sshExecute('/bin/ls -la', 'SecurityDVM0') BarthaM@212: #man.sshExecuteX11('/usr/bin/iceweasel', 'SecurityDVM0') BarthaM@212: #man.removeVM('SecurityDVM0') BarthaM@212: #man.netUse('192.168.56.134', 'USB\\') BarthaM@212: #ip = '192.168.56.139' BarthaM@212: BarthaM@212: #man.cygwin_path = 'c:\\cygwin64\\bin\\' BarthaM@212: #man.handleDeviceChange() BarthaM@212: #print man.listSDVM() BarthaM@212: #man.configureHostNetworking() BarthaM@212: #new_vm = man.generateSDVMName() BarthaM@212: #man.createVM(new_vm) BarthaM@212: BarthaM@212: #print Cygwin.cmd() BarthaM@212: #man.isAvailable('c:') BarthaM@212: #ip = man.getHostOnlyIP('SecurityDVM0') BarthaM@212: #man.mapNetworkDrive('h:', '\\\\' + ip + '\Download', None, None) BarthaM@212: BarthaM@212: #man.genCertificateISO(new_vm) BarthaM@212: #man.attachCertificateISO(new_vm) BarthaM@212: BarthaM@212: #man.attachCertificateISO(vm_name) BarthaM@212: #man.guestExecute(vm_name, "ls") BarthaM@212: #man.sshGuestX11Execute('SecurityDVM1', '/usr/bin/iceweasel') BarthaM@212: #time.sleep(60) BarthaM@212: #print man.cygwinPath("C:\Users\BarthaM\VirtualBox VMs\SecurityDVM\.ssh\*") BarthaM@212: #man.genCertificateISO('SecurityDVM') BarthaM@212: #man.attachCertificateISO('SecurityDVM') BarthaM@212: #man.isStorageAttached('SecurityDVM') BarthaM@212: #man.guestExecute('SecurityDVM', 'sudo apt-get -y update') BarthaM@212: #man.guestExecute('SecurityDVM', 'sudo apt-get -y upgrade' ) BarthaM@212: BarthaM@212: #man.stopVM('SecurityDVM') BarthaM@219: #man.detachStorage('SecurityDVM') BarthaM@212: #man.changeStorageType('C:\Users\BarthaM\VirtualBox VMs\SecurityDVM\SecurityDVM.vmdk','immutable') BarthaM@212: #man.storageAttach('SecurityDVM') BarthaM@212: BarthaM@212: BarthaM@212: #cmd = "c:\\cygwin64\\bin\\bash.exe --login -c \"/bin/ls\"" oliver@240: #man.execute(cmd)