OpenSecurity/bin/test_vmmanager.pyw
author Bartha Mihai <mihai.bartha@ait.ac.at>
Tue, 13 Jan 2015 18:26:41 +0100
changeset 252 824ae4324f57
parent 240 d7ef04254e9c
permissions -rw-r--r--
changed settings restore functionality for the browser.
Needs addition of rsync on VM and setup
     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     @unittest.skip("skipping")       
   143     def testBrowsingRequest(self):
   144         gvm_mgr.start()
   145         gvm_mgr.handleBrowsingRequest()
   146         time.sleep(3000)
   147         pass
   148     
   149     def testRsync(self):
   150         gvm_mgr.start()
   151                     
   152         gvm_mgr.syncRemoteFile("SecurityDVM0", gvm_mgr.getHostOnlyIP("SecurityDVM0"), gvm_mgr.getAppDataDir() + '/OpenSecurity/chromium', '/home/osecuser/.config/')
   153         pass
   154         
   155         
   156 if __name__ == '__main__':
   157     TestVMManager.setUpClass()
   158     
   159     suite = unittest.TestLoader().loadTestsFromTestCase(TestVMManager)
   160     unittest.TextTestRunner().run(suite)
   161     
   162     #VBoxManage list hostonlyifs
   163     #VBoxManage list dhcpservers
   164     #VBoxManage dhcpserver remove --netname "HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter"
   165     #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
   166     #VBoxManage dhcpserver modify --ifname "VirtualBox Host-Only Ethernet Adapter" --enable
   167     #VBoxManage hostonlyif ipconfig "VirtualBox Host-Only Ethernet Adapter" --dhcp
   168     #VBoxManage hostonlyif ipconfig "VirtualBox Host-Only Ethernet Adapter" --ip 192.168.56.1 --netmask 255.255.255.0    
   169 #    logger = setupLogger('Cygwin')
   170 #    c = Cygwin()
   171 #    unittest.main()
   172     #man = VMManager.getInstance()
   173     #man.listVM()
   174     #print man.getConnectedRSDs()
   175     #print man.getNetworkDrives()
   176     #man.genNetworkDrive()
   177     #drive_bitmask = ctypes.cdll.kernel32.GetLogicalDrives()
   178     #print list(itertools.compress(string.ascii_uppercase,  map(lambda x:ord(x) - ord('0'), bin(drive_bitmask)[:1:-1])))
   179     #print list(map(chr, range(68, 91))) 
   180     #print Cygwin.getRegEntry('SYSTEM\CurrentControlSet\Enum\USB', 'VID_1058&PID_0704')[0]
   181     #devices = VMManager.getConnectedRSDS()
   182     #print devices
   183     
   184     #drives = VMManager.getLogicalDrives()
   185     #print drives
   186     #print VMManager.getDriveType("E")
   187     #print VMManager.getVolumeInfo("E")
   188     #print VMManager.getNetworkPath("E")
   189     
   190     #vmm.backupFile()
   191     #for device in devices.values():
   192     #    #print device
   193     #    if VMManager.isMassStorageDevice(device):
   194     #        print device
   195         
   196     
   197     
   198     #time.sleep(-1)
   199     #man.listVM()
   200     #man.listVM()
   201     #man.listVM()
   202     #man.listVM()
   203     #man.genCertificateISO('SecurityDVM0')
   204     #man.guestExecute('SecurityDVM0', '/bin/ls -la')
   205     #logger = setupLogger('VMManager')
   206     #c = Cygwin()
   207     
   208     #man.sshExecute('/bin/ls -la', 'SecurityDVM0')
   209     #man.sshExecuteX11('/usr/bin/iceweasel', 'SecurityDVM0')
   210     #man.removeVM('SecurityDVM0')
   211     #man.netUse('192.168.56.134', 'USB\\')
   212     #ip = '192.168.56.139'
   213     
   214     #man.cygwin_path = 'c:\\cygwin64\\bin\\'
   215     #man.handleDeviceChange()
   216     #print man.listSDVM()
   217     #man.configureHostNetworking()
   218     #new_vm = man.generateSDVMName()
   219     #man.createVM(new_vm)
   220     
   221     #print Cygwin.cmd()
   222     #man.isAvailable('c:')
   223     #ip = man.getHostOnlyIP('SecurityDVM0')
   224     #man.mapNetworkDrive('h:', '\\\\' + ip + '\Download', None, None)
   225     
   226     #man.genCertificateISO(new_vm)
   227     #man.attachCertificateISO(new_vm)
   228     
   229     #man.attachCertificateISO(vm_name)
   230     #man.guestExecute(vm_name, "ls")
   231     #man.sshGuestX11Execute('SecurityDVM1', '/usr/bin/iceweasel')
   232     #time.sleep(60)
   233     #print man.cygwinPath("C:\Users\BarthaM\VirtualBox VMs\SecurityDVM\.ssh\*")
   234     #man.genCertificateISO('SecurityDVM')
   235     #man.attachCertificateISO('SecurityDVM')
   236     #man.isStorageAttached('SecurityDVM')
   237     #man.guestExecute('SecurityDVM', 'sudo apt-get -y update')
   238     #man.guestExecute('SecurityDVM', 'sudo apt-get -y upgrade' )
   239     
   240     #man.stopVM('SecurityDVM')
   241     #man.detachStorage('SecurityDVM')
   242     #man.changeStorageType('C:\Users\BarthaM\VirtualBox VMs\SecurityDVM\SecurityDVM.vmdk','immutable')
   243     #man.storageAttach('SecurityDVM')
   244     
   245     
   246     #cmd = "c:\\cygwin64\\bin\\bash.exe --login -c \"/bin/ls\""
   247     #man.execute(cmd)