OpenSecurity/bin/test_vmmanager.pyw
author Oliver Maurhart <oliver.maurhart@ait.ac.at>
Wed, 29 Oct 2014 15:18:22 +0100
changeset 240 d7ef04254e9c
parent 234 216da9017f8f
child 252 824ae4324f57
permissions -rw-r--r--
lizenz fixed in all files
     1 #!/bin/env python
     2 # -*- coding: utf-8 -*-
     3 
     4 # ------------------------------------------------------------
     5 # test_vmmanger
     6 #
     7 # test the open security vmmanager
     8 #   
     9 # Autor: Mihai Bartha, <mihai.bartha@ait.ac.at>       
    10 #
    11 # Copyright 2013-2014 X-Net and AIT Austrian Institute of Technology
    12 # 
    13 # 
    14 #     X-Net Services GmbH
    15 #     Elisabethstrasse 1
    16 #     4020 Linz
    17 #     AUSTRIA
    18 #     https://www.x-net.at
    19 # 
    20 #     AIT Austrian Institute of Technology
    21 #     Donau City Strasse 1
    22 #     1220 Wien
    23 #     AUSTRIA
    24 #     http://www.ait.ac.at
    25 # 
    26 # 
    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
    30 # 
    31 #    http://www.apache.org/licenses/LICENSE-2.0
    32 # 
    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 # ------------------------------------------------------------
    39 
    40 
    41 # ------------------------------------------------------------
    42 # imports
    43 
    44 import unittest
    45 
    46 import os
    47 import re
    48 import os.path
    49 import sys
    50 import cygwin
    51 import vmmanager
    52 import _winreg
    53 import time
    54 gvm_mgr = None
    55 
    56 class TestVMManager(unittest.TestCase):
    57     
    58     def setUp(self):
    59         pass
    60     
    61     @classmethod
    62     def setUpClass(self):
    63         global gvm_mgr
    64         gvm_mgr = vmmanager.VMManager.getInstance()
    65         pass
    66     
    67     #@classmethod
    68     #def tearOffClass(self):
    69     #    gvm_mgr.stop()
    70     #    gvm_mgr.cleanup()
    71     
    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")
    76     
    77     @unittest.skip("skipping")    
    78     def testUpdateTemplate(self):
    79         gvm_mgr.updateTemplate()
    80         pass
    81     
    82     def setKey(self, key, name, value):
    83         _, reg_type = _winreg.QueryValueEx(key, name)
    84         _winreg.SetValueEx(key, name, 0, reg_type, value)
    85     
    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)
    92         proxy = dict()
    93         for i in range(valueCount):                                           
    94             try:
    95                 n,v,t = _winreg.EnumValue(aKey,i)
    96                 proxy[n] = v
    97             except EnvironmentError:                                               
    98                 break
    99         _winreg.CloseKey(aKey)
   100         print proxy
   101         if 'ProxyEnable' in proxy.keys() and proxy['ProxyEnable'] == 1:
   102             print proxy['ProxyServer']
   103             return proxy['ProxyServer']
   104         else: 
   105             return ""
   106     
   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
   110         #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)
   114         
   115     
   116     
   117     @unittest.skip("skipping")
   118     def testImportTemplate(self):
   119         gvm_mgr.cleanup()
   120         if 'SecurityDVM' in gvm_mgr.listVMS():
   121             gvm_mgr.removeVM('SecurityDVM')
   122         
   123         uuid = gvm_mgr.getVDiskUUID(gvm_mgr.templateImage)
   124         if uuid:
   125             gvm_mgr.removeImage(uuid)
   126         
   127         gvm_mgr.removeVMFolder('SecurityDVM')
   128         gvm_mgr.importTemplate('C:\Windows\System32\config\systemprofile\VirtualBox VMs\OsecVM.ova')
   129         gvm_mgr.updateTemplate()
   130    
   131     @unittest.skip("skipping")   
   132     def testHostOnlyDHCP(self):
   133         #list hostonlyifs
   134         #Cygwin.vboxExecute("list hostonlyifs")
   135         
   136         hostonlyifs = gvm_mgr.getHostOnlyIFs()
   137         print hostonlyifs
   138         
   139         dhcpservers = gvm_mgr.getDHCPServers()
   140         print dhcpservers
   141         
   142     def testBrowsingRequest(self):
   143         gvm_mgr.start()
   144         gvm_mgr.handleBrowsingRequest()
   145         time.sleep(3000)
   146         pass
   147         
   148 if __name__ == '__main__':
   149     TestVMManager.setUpClass()
   150     
   151     suite = unittest.TestLoader().loadTestsFromTestCase(TestVMManager)
   152     unittest.TextTestRunner().run(suite)
   153     
   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')
   162 #    c = Cygwin()
   163 #    unittest.main()
   164     #man = VMManager.getInstance()
   165     #man.listVM()
   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()
   174     #print devices
   175     
   176     #drives = VMManager.getLogicalDrives()
   177     #print drives
   178     #print VMManager.getDriveType("E")
   179     #print VMManager.getVolumeInfo("E")
   180     #print VMManager.getNetworkPath("E")
   181     
   182     #vmm.backupFile()
   183     #for device in devices.values():
   184     #    #print device
   185     #    if VMManager.isMassStorageDevice(device):
   186     #        print device
   187         
   188     
   189     
   190     #time.sleep(-1)
   191     #man.listVM()
   192     #man.listVM()
   193     #man.listVM()
   194     #man.listVM()
   195     #man.genCertificateISO('SecurityDVM0')
   196     #man.guestExecute('SecurityDVM0', '/bin/ls -la')
   197     #logger = setupLogger('VMManager')
   198     #c = Cygwin()
   199     
   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'
   205     
   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)
   212     
   213     #print Cygwin.cmd()
   214     #man.isAvailable('c:')
   215     #ip = man.getHostOnlyIP('SecurityDVM0')
   216     #man.mapNetworkDrive('h:', '\\\\' + ip + '\Download', None, None)
   217     
   218     #man.genCertificateISO(new_vm)
   219     #man.attachCertificateISO(new_vm)
   220     
   221     #man.attachCertificateISO(vm_name)
   222     #man.guestExecute(vm_name, "ls")
   223     #man.sshGuestX11Execute('SecurityDVM1', '/usr/bin/iceweasel')
   224     #time.sleep(60)
   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' )
   231     
   232     #man.stopVM('SecurityDVM')
   233     #man.detachStorage('SecurityDVM')
   234     #man.changeStorageType('C:\Users\BarthaM\VirtualBox VMs\SecurityDVM\SecurityDVM.vmdk','immutable')
   235     #man.storageAttach('SecurityDVM')
   236     
   237     
   238     #cmd = "c:\\cygwin64\\bin\\bash.exe --login -c \"/bin/ls\""
   239     #man.execute(cmd)