Beispiel #1
0
 def setup(self):
     super(CheckTest, self).setup()
     self.engine = Engine()
     self.service = Service(name='Example Service',
                            check_name=self.check_name,
                            ip_address='127.0.0.1',
                            port=100)
     self.environment = Environment(service=self.service,
                                    matching_regex='*')
     if not hasattr(self, 'properties'):
         self.properties = {}
     if not hasattr(self, 'accounts'):
         self.accounts = {}
     for property_name, property_value in self.properties.items():
         self.db.save(
             Property(environment=self.environment,
                      name=property_name,
                      value=property_value))
     for account_name, account_pass in self.accounts.items():
         self.db.save(
             Account(username=account_name,
                     password=account_pass,
                     service=self.service))
     self.db.save(self.service)
     self.db.save(self.environment)
Beispiel #2
0
    def test_cmd(self):
        engine = Engine()
        service = Service(name='Example Service',
                          check_name=self.check_name,
                          host='127.0.0.1',
                          port=1234)
        environment = Environment(service=service, matching_content='*')
        if not hasattr(self, 'properties'):
            self.properties = {}
        if not hasattr(self, 'accounts'):
            self.accounts = {}
        for property_name, property_value in self.properties.items():
            self.session.add(
                Property(environment=environment,
                         name=property_name,
                         value=property_value))
        for account_name, account_pass in self.accounts.items():
            self.session.add(
                Account(username=account_name,
                        password=account_pass,
                        service=service))
        self.session.add(service)
        self.session.add(environment)
        self.session.commit()

        check_obj = engine.check_name_to_obj(self.check_name)(environment)
        assert check_obj.command() == self.cmd
 def test_run_hundred_rounds(self):
     engine = Engine(total_rounds=100)
     assert engine.current_round == 0
     assert engine.rounds_run == 0
     engine.run()
     assert engine.rounds_run == 100
     assert engine.current_round == 100
Beispiel #4
0
 def test_run_hundred_rounds(self):
     engine = Engine(total_rounds=100,
                     round_time_sleep=0,
                     worker_wait_time=0)
     assert engine.current_round == 0
     assert engine.rounds_run == 0
     engine.run()
     assert engine.rounds_run == 100
     assert engine.current_round == 100
Beispiel #5
0
class CheckTest(UnitTest):
    def setup(self):
        super(CheckTest, self).setup()
        self.engine = Engine()
        self.service = Service(name='Example Service',
                               check_name=self.check_name,
                               ip_address='127.0.0.1',
                               port=100)
        self.environment = Environment(service=self.service,
                                       matching_regex='*')
        if not hasattr(self, 'properties'):
            self.properties = {}
        if not hasattr(self, 'accounts'):
            self.accounts = {}
        for property_name, property_value in self.properties.items():
            self.db.save(
                Property(environment=self.environment,
                         name=property_name,
                         value=property_value))
        for account_name, account_pass in self.accounts.items():
            self.db.save(
                Account(username=account_name,
                        password=account_pass,
                        service=self.service))
        self.db.save(self.service)
        self.db.save(self.environment)

    def test_bad_properties(self):
        environment = Environment(service=self.service, matching_regex='*')
        self.db.save(environment)
        self.service.environments = [environment]
        temp_properties = dict(self.properties)
        if len(temp_properties) > 0:
            temp_properties.popitem()
        else:
            temp_properties['exampleproperty'] = 'propertyvalueexample'
        for property_name, property_value in temp_properties.items():
            property_obj = Property(environment=environment,
                                    name=property_name,
                                    value=property_value)
            self.db.save(property_obj)
        with pytest.raises(LookupError):
            self.engine.check_name_to_obj(self.check_name)(environment)

    def test_cmd(self):
        check_obj = self.engine.check_name_to_obj(self.check_name)(
            self.environment)
        assert check_obj.command() == self.cmd
 def test_init(self):
     engine = Engine()
     expected_checks = [
         ICMPCheck,
         SSHCheck,
         DNSCheck,
         FTPCheck,
         HTTPCheck,
         HTTPSCheck,
         MYSQLCheck,
         MSSQLCheck,
         POSTGRESQLCheck,
         POP3Check,
         POP3SCheck,
         IMAPCheck,
         IMAPSCheck,
         SMTPCheck,
         SMTPSCheck,
         VNCCheck,
         ElasticsearchCheck,
         LDAPCheck,
         SMBCheck,
         RDPCheck,
         WordpressCheck,
         NFSCheck,
         OpenVPNCheck,
         TelnetCheck,
     ]
     assert set(engine.checks) == set(expected_checks)
Beispiel #7
0
 def test_init(self):
     engine = Engine()
     from scoring_engine.engine.checks.icmp import ICMPCheck
     from scoring_engine.engine.checks.ssh import SSHCheck
     from scoring_engine.engine.checks.dns import DNSCheck
     from scoring_engine.engine.checks.ftpdownload import FTPDownloadCheck
     from scoring_engine.engine.checks.ftpupload import FTPUploadCheck
     from scoring_engine.engine.checks.ftp import FTPCheck
     from scoring_engine.engine.checks.ftps import FTPSCheck
     from scoring_engine.engine.checks.http import HTTPCheck
     from scoring_engine.engine.checks.https import HTTPSCheck
     from scoring_engine.engine.checks.mysql import MYSQLCheck
     from scoring_engine.engine.checks.postgresql import POSTGRESQLCheck
     from scoring_engine.engine.checks.pop3 import POP3Check
     from scoring_engine.engine.checks.pop3s import POP3SCheck
     from scoring_engine.engine.checks.imap import IMAPCheck
     from scoring_engine.engine.checks.imaps import IMAPSCheck
     from scoring_engine.engine.checks.smtp import SMTPCheck
     from scoring_engine.engine.checks.smtps import SMTPSCheck
     from scoring_engine.engine.checks.vnc import VNCCheck
     expected_checks = [
         ICMPCheck,
         SSHCheck,
         DNSCheck,
         FTPDownloadCheck,
         FTPUploadCheck,
         FTPCheck,
         FTPSCheck,
         HTTPCheck,
         HTTPSCheck,
         MYSQLCheck,
         POSTGRESQLCheck,
         POP3Check,
         POP3SCheck,
         IMAPCheck,
         IMAPSCheck,
         SMTPCheck,
         SMTPSCheck,
         VNCCheck,
     ]
     assert set(engine.checks) == set(expected_checks)
 def test_init(self):
     engine = Engine()
     expected_checks = [
         ICMPCheck,
         SSHCheck,
         DNSCheck,
         FTPCheck,
         HTTPCheck,
         HTTPSCheck,
         MYSQLCheck,
         POSTGRESQLCheck,
         POP3Check,
         POP3SCheck,
         IMAPCheck,
         IMAPSCheck,
         SMTPCheck,
         SMTPSCheck,
         VNCCheck,
         ElasticsearchCheck,
         LDAPCheck,
         SMBCheck,
     ]
     assert set(engine.checks) == set(expected_checks)
 def test_shutdown(self):
     engine = Engine()
     assert engine.last_round is False
     engine.shutdown()
     assert engine.last_round is True
Beispiel #10
0
 def test_total_rounds_init(self):
     engine = Engine(total_rounds=100)
     assert engine.total_rounds == 100
Beispiel #11
0
 def test_is_last_round_restricted(self):
     engine = Engine(total_rounds=1)
     engine.rounds_run = 1
     assert engine.is_last_round() is True
Beispiel #12
0
 def test_is_last_round_true(self):
     engine = Engine()
     engine.last_round = True
     assert engine.is_last_round() is True
Beispiel #13
0
 def test_is_last_round_unlimited(self):
     engine = Engine()
     assert engine.is_last_round() is False
Beispiel #14
0
 def test_check_name_to_obj_negative(self):
     engine = Engine()
     check_obj = engine.check_name_to_obj("Garbage Check")
     assert check_obj is None
Beispiel #15
0
 def test_run_one_round(self):
     engine = Engine(total_rounds=1)
     assert engine.rounds_run == 0
     engine.run()
     assert engine.rounds_run == 1
     assert engine.current_round == 1
Beispiel #16
0
 def test_run_one_round(self):
     engine = Engine(total_rounds=1, round_time_sleep=1, worker_wait_time=1)
     assert engine.rounds_run == 0
     engine.run()
     assert engine.rounds_run == 1
     assert engine.current_round == 1
Beispiel #17
0
 def test_custom_sleep_timers(self):
     engine = Engine(round_time_sleep=60, worker_wait_time=20)
     assert engine.round_time_sleep == 60
     assert engine.worker_wait_time == 20
Beispiel #18
0
 def test_check_name_to_obj_positive(self):
     engine = Engine()
     check_obj = engine.check_name_to_obj("ICMP IPv4 Check")
     from scoring_engine.checks.icmp import ICMPCheck
     check_obj == ICMPCheck
Beispiel #19
0
 def __init__(self, data):
     self.available_checks = Engine.load_check_files(config.checks_location)
     self.required_services = None
     self.verify_data(data)
     super(Competition, self).__init__(data)