def test_101_email_admin_override_custom_report(self): """ 1. Use reportuser 2. Reportuser overrides admin user address. 3. Custom report with test not in default. """ if (not can_relay): raise unittest2.SkipTest('Unable to relay through ' + global_functions.testServerHost) if remote_control.quickTestsOnly: raise unittest2.SkipTest('Skipping a time consuming test') # Create settings to receive test_email_address configure_mail_relay() # add administrator adminsettings = uvmContext.adminManager().getSettings() orig_adminsettings = copy.deepcopy(adminsettings) adminsettings['users']['list'].append( create_admin_user(useremail=test_email_address)) uvmContext.adminManager().setSettings(adminsettings) settings = app.getSettings() # add custom template with a test not in daily reports settings["emailTemplates"]["list"] = settings["emailTemplates"][ "list"][:1] settings["emailTemplates"]["list"].append(create_email_template()) # add report user with test_email_address settings["reportsUsers"]["list"] = settings["reportsUsers"]["list"][:1] settings["reportsUsers"]["list"].append( create_reports_user(profile_email=test_email_address, email_template_id=2)) app.setSettings(settings) # send email subprocess.call([ global_functions.get_prefix() + "/usr/share/untangle/bin/reports-generate-fixed-reports.py" ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) # look for email email_found = fetch_email( "/tmp/test_101_email_admin_override_custom_report_file", test_email_address) if email_found: email_context_found1 = remote_control.run_command( "grep -i 'Custom Report' /tmp/test_101_email_admin_override_custom_report_file 2>&1", stdout=True) email_context_found2 = remote_control.run_command( "grep -i 'Administration-VWuRol5uWw' /tmp/test_101_email_admin_override_custom_report_file 2>&1", stdout=True) # restore uvmContext.adminManager().setSettings(orig_adminsettings) assert (email_found) assert ((email_context_found1) and (email_context_found2))
def test_102_admin_login_event(self): uvmContext.adminManager().logAdminLoginEvent( "admin", True, "127.0.1.1", True, 'X' ) events = global_functions.get_events('Administration','Admin Login Events',None,10) assert(events != None) for i in events.get('list'): print i found = global_functions.check_events( events.get('list'), 10, 'client_addr', "127.0.1.1", 'reason', 'X', 'local', True, 'succeeded', True, 'login', 'admin' ) assert( found )
def test_020_about_info(self): uid = uvmContext.getServerUID() match = re.search(r'\w{4}-\w{4}-\w{4}.\w{4}', uid) assert (match) kernel = uvmContext.adminManager().getKernelVersion() match = re.search(r'\d.*', kernel) assert (match) reboot_count = uvmContext.adminManager().getRebootCount() match = re.search(r'\d{1,2}', reboot_count) assert (match) num_hosts = str(uvmContext.hostTable().getCurrentActiveSize()) match = re.search(r'\d{1,2}', num_hosts) assert (match) max_num_hosts = str(uvmContext.hostTable().getMaxActiveSize()) match = re.search(r'\d{1,2}', max_num_hosts) assert (match)
def test_103_email_report_verify_apps(self): """ 1) Install all apps 2) Generate a report 3) Verify that the emailed report contains a section for each app """ global app if (not can_relay): raise unittest2.SkipTest('Unable to relay through ' + global_functions.testServerHost) if remote_control.quickTestsOnly: raise unittest2.SkipTest('Skipping a time consuming test') # create settings to receive test_email_address configure_mail_relay() # add administrator adminsettings = uvmContext.adminManager().getSettings() orig_adminsettings = copy.deepcopy(adminsettings) adminsettings['users']['list'].append( create_admin_user(useremail=test_email_address)) uvmContext.adminManager().setSettings(adminsettings) # clear all report users settings = app.getSettings() settings["reportsUsers"]["list"] = settings["reportsUsers"]["list"][:1] app.setSettings(settings) # install all the apps that aren't already installed apps = [] for name in [ "firewall", "web-filter", "virus-blocker", "spam-blocker", "phish-blocker", "ad-blocker", "web-cache", "bandwidth-control", "application-control", "ssl-inspector", "captive-portal", "web-monitor", "virus-blocker-lite", "spam-blocker-lite", "application-control-lite", "policy-manager", "directory-connector", "wan-failover", "wan-balancer", "configuration-backup", "intrusion-prevention", "ipsec-vpn", "openvpn" ]: if (uvmContext.appManager().isInstantiated(name)): print("App %s already installed" % name) else: apps.append(uvmContext.appManager().instantiate( name, default_policy_id)) # create some traffic result = remote_control.is_online(tries=1) # flush out events app.flushEvents() # send emails subprocess.call([ global_functions.get_prefix() + "/usr/share/untangle/bin/reports-generate-fixed-reports.py" ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) # look for email email_found = fetch_email("/tmp/test_103_email_report_admin_file", test_email_address) # look for all the appropriate sections in the report email results = [] if email_found: for str in [ 'Daily', 'Firewall', 'Web Filter', 'Virus Blocker', 'Spam Blocker', 'Phish Blocker', 'Ad Blocker', 'Web Cache', 'Bandwidth Control', 'Application Control', 'SSL Inspector', 'Web Monitor', 'Captive Portal', 'Virus Blocker Lite', 'Spam Blocker Lite', 'Application Control Lite', 'Policy Manager', 'Directory Connector', 'WAN Failover', 'WAN Balancer', 'Configuration Backup', 'Intrusion Prevention', 'IPsec VPN', 'OpenVPN' ]: results.append( remote_control.run_command( "grep -q -i '%s' /tmp/test_103_email_report_admin_file 2>&1" % str)) # restore uvmContext.adminManager().setSettings(orig_adminsettings) # remove apps that were installed above for a in apps: uvmContext.appManager().destroy(a.getAppSettings()["id"]) assert (email_found) for result in results: assert (result == 0)
def test_102_email_admin_override_custom_report_mobile(self): """ 1. Use reportuser 2. Reportuser overrides admin user address. 3. Custom report with test not in default. """ if (not can_relay): raise unittest2.SkipTest('Unable to relay through ' + global_functions.testServerHost) if remote_control.quickTestsOnly: raise unittest2.SkipTest('Skipping a time consuming test') # Create settings to receive test_email_address configure_mail_relay() # add administrator adminsettings = uvmContext.adminManager().getSettings() orig_adminsettings = copy.deepcopy(adminsettings) adminsettings['users']['list'].append( create_admin_user(useremail=test_email_address)) uvmContext.adminManager().setSettings(adminsettings) settings = app.getSettings() # add custom template with a test not in daily reports settings["emailTemplates"]["list"] = settings["emailTemplates"][ "list"][:1] settings["emailTemplates"]["list"].append( create_email_template(mobile=True)) # add report user with test_email_address settings["reportsUsers"]["list"] = settings["reportsUsers"]["list"][:1] settings["reportsUsers"]["list"].append( create_reports_user(profile_email=test_email_address, email_template_id=2)) app.setSettings(settings) # send email subprocess.call([ global_functions.get_prefix() + "/usr/share/untangle/bin/reports-generate-fixed-reports.py" ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) # look for email email_found = fetch_email( "/tmp/test_102_email_admin_override_custom_report_mobile_file", test_email_address) if email_found: email_context_found1 = remote_control.run_command( "grep -i 'Custom Report' /tmp/test_102_email_admin_override_custom_report_mobile_file 2>&1", stdout=True) email_context_found2 = remote_control.run_command( "grep -i 'Administration-VWuRol5uWw' /tmp/test_102_email_admin_override_custom_report_mobile_file 2>&1", stdout=True) # restore uvmContext.adminManager().setSettings(orig_adminsettings) assert (email_found) assert ((email_context_found1) and (email_context_found2)) # Verify that all images are less than 350x350. # copy mail from remote client subprocess.call( "scp -q -i %s testshell@%s:/tmp/test_102_email_admin_override_custom_report_mobile_file /tmp/" % (remote_control.hostKeyFile, remote_control.clientIP), shell=True) fp = open( "/tmp/test_102_email_admin_override_custom_report_mobile_file") email_string = fp.read() fp.close() subprocess.call( "rm /tmp/test_102_email_admin_override_custom_report_mobile_file", shell=True) # Delete the first line as it is blank and throws off the parser email_string = '\n'.join(email_string.split('\n')[1:]) msg = email.message_from_string(email_string) mime_content_ids = [] for part in msg.walk(): if part.get_content_maintype() == "image": # print("Image found") for index, key in enumerate(part.keys()): if key == "Content-ID": email_image = part.get_payload(decode=True) im = Image.open(StringIO(email_image)) (image_width, image_height) = im.size print("Image width: %d height: %d" % (image_width, image_height)) assert (image_width < 350 and image_height < 350)
def test_100_email_report_admin(self): """ The "default" configuration test: - Administrator email account gets """ if (not can_relay): raise unittest2.SkipTest('Unable to relay through ' + global_functions.testServerHost) if remote_control.quickTestsOnly: raise unittest2.SkipTest('Skipping a time consuming test') # create settings to receive test_email_address configure_mail_relay() # add administrator adminsettings = uvmContext.adminManager().getSettings() orig_adminsettings = copy.deepcopy(adminsettings) adminsettings['users']['list'].append( create_admin_user(useremail=test_email_address)) uvmContext.adminManager().setSettings(adminsettings) # clear all report users settings = app.getSettings() settings["reportsUsers"]["list"] = settings["reportsUsers"]["list"][:1] app.setSettings(settings) # send emails subprocess.call([ global_functions.get_prefix() + "/usr/share/untangle/bin/reports-generate-fixed-reports.py" ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) # look for email email_found = fetch_email("/tmp/test_100_email_report_admin_file", test_email_address) email_context_found1 = "" email_context_found2 = "" if email_found: email_context_found1 = remote_control.run_command( "grep -i -e 'Reports:.*Daily.*' /tmp/test_100_email_report_admin_file 2>&1", stdout=True) email_context_found2 = remote_control.run_command( "grep -i -e 'Content-Type: image/png; name=' /tmp/test_100_email_report_admin_file 2>&1", stdout=True) # restore uvmContext.adminManager().setSettings(orig_adminsettings) assert (email_found) assert ((email_context_found1) and (email_context_found2)) ## Verify that all images are intact. # copy mail from remote client subprocess.call( "scp -q -i %s testshell@%s:/tmp/test_100_email_report_admin_file /tmp/" % (remote_control.hostKeyFile, remote_control.clientIP), shell=True) fp = open("/tmp/test_100_email_report_admin_file") email_string = fp.read() fp.close() subprocess.call("rm /tmp/test_100_email_report_admin_file", shell=True) # Delete the first line as it is blank and throws off the parser email_string = '\n'.join(email_string.split('\n')[1:]) msg = email.message_from_string(email_string) mime_content_ids = [] parser = ContentIdParser() for part in msg.walk(): if part.get_content_maintype() == "image": for index, key in enumerate(part.keys()): if key == "Content-ID": mime_content_ids.append(part.values()[index]) elif part.get_content_maintype() == "text": parser.feed(part.get_payload(decode=True)) assert (len(parser.content_ids) == len(mime_content_ids))
def test_103_email_report_verify_apps(self): """ 1) Install all apps 2) Generate a report 3) Verify that the emailed report contains a section for each app """ global app,apps_list,apps_name_list if (not can_relay): raise unittest2.SkipTest('Unable to relay through ' + global_functions.testServerHost) if remote_control.quickTestsOnly: raise unittest2.SkipTest('Skipping a time consuming test') # create settings to receive test_email_address configure_mail_relay() # add administrator adminsettings = uvmContext.adminManager().getSettings() orig_adminsettings = copy.deepcopy(adminsettings) adminsettings['users']['list'].append(create_admin_user(useremail=test_email_address)) uvmContext.adminManager().setSettings(adminsettings) # clear all report users settings = app.getSettings() settings["reportsUsers"]["list"] = settings["reportsUsers"]["list"][:1] app.setSettings(settings) # install all the apps that aren't already installed system_stats = uvmContext.metricManager().getStats() # print system_stats system_memory = system_stats['systemStats']['MemTotal'] if (int(system_memory) < 2200000000): # don't use high memory apps in devices with 2G or less. apps_list = apps_list_short apps_name_list = apps_name_list_short apps = [] for name in apps_list: if (uvmContext.appManager().isInstantiated(name)): print("App %s already installed" % name) else: apps.append( uvmContext.appManager().instantiate(name, default_policy_id) ) # create some traffic result = remote_control.is_online(tries=1) # flush out events app.flushEvents() # send emails subprocess.call([global_functions.get_prefix()+"/usr/share/untangle/bin/reports-generate-fixed-reports.py"],stdout=subprocess.PIPE,stderr=subprocess.PIPE) # look for email email_found = fetch_email( "/tmp/test_103_email_report_admin_file", test_email_address ) # look for all the appropriate sections in the report email results = [] if email_found: for str in apps_name_list: results.append(remote_control.run_command("grep -q -i '%s' /tmp/test_103_email_report_admin_file 2>&1"%str)) # restore uvmContext.adminManager().setSettings(orig_adminsettings) # remove apps that were installed above for a in apps: uvmContext.appManager().destroy( a.getAppSettings()["id"] ) assert(email_found) for result in results: assert(result == 0)