Ejemplo n.º 1
0
 def test_accounts(self):
     service = generate_sample_model_tree('Service', self.session)
     account_1 = Account(username="******", password="******", service=service)
     self.session.add(account_1)
     account_2 = Account(username="******", password="******", service=service)
     self.session.add(account_2)
     account_3 = Account(username="******", password="******", service=service)
     self.session.add(account_3)
     self.session.commit()
     assert service.accounts == [account_1, account_2, account_3]
Ejemplo n.º 2
0
 def test_accounts(self):
     service = generate_sample_model_tree('Service', self.db)
     account_1 = Account(username="******",
                         password="******",
                         service=service)
     self.db.save(account_1)
     account_2 = Account(username="******",
                         password="******",
                         service=service)
     self.db.save(account_2)
     account_3 = Account(username="******",
                         password="******",
                         service=service)
     self.db.save(account_3)
     assert service.accounts == [account_1, account_2, account_3]
Ejemplo n.º 3
0
 def test_get_random_account(self):
     self.db.save(
         Account(username='******', password='******', service=self.service))
     self.db.save(self.service)
     self.db.save(self.environment)
     check = BasicCheck(self.environment)
     assert check.get_random_account().username == 'pwnbus'
Ejemplo n.º 4
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
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
 def test_init_account(self):
     account = Account(username="******", password="******")
     assert account.id is None
     assert account.username == "testname"
     assert account.password == "testpass"
     assert account.service is None
     assert account.service_id is None
Ejemplo n.º 7
0
 def test_get_random_account(self):
     self.session.add(Account(username='******', password='******', service=self.service))
     self.session.add(self.service)
     self.session.add(self.environment)
     self.session.commit()
     check = BasicCheck(self.environment)
     assert check.get_random_account().username == 'pwnbus'
Ejemplo n.º 8
0
 def test_basic_property(self):
     service = generate_sample_model_tree('Service', self.db)
     account = Account(username="******", password="******", service=service)
     self.db.save(account)
     assert account.id is not None
     assert account.service == service
     assert account.service_id == service.id
Ejemplo n.º 9
0
 def save(self, db_session):
     for team_dict in self['teams']:
         logger.info("Creating {0} Team: {1}".format(
             team_dict['color'], team_dict['name']))
         team_obj = Team(name=team_dict['name'], color=team_dict['color'])
         db_session.add(team_obj)
         for user_dict in team_dict['users']:
             logger.info("\tCreating User {0}:{1}".format(
                 user_dict['username'], user_dict['password']))
             db_session.add(
                 User(username=user_dict['username'],
                      password=user_dict['password'],
                      team=team_obj))
         if 'services' in team_dict:
             for service_dict in team_dict['services']:
                 logger.info("\tCreating {0} Service".format(
                     service_dict['name']))
                 service_obj = Service(
                     name=service_dict['name'],
                     team=team_obj,
                     check_name=service_dict['check_name'],
                     host=service_dict['host'],
                     port=service_dict['port'],
                     points=service_dict['points'])
                 if 'worker_queue' in service_dict:
                     service_obj.worker_queue = service_dict['worker_queue']
                 db_session.add(service_obj)
                 if 'accounts' in service_dict:
                     for account_dict in service_dict['accounts']:
                         db_session.add(
                             Account(username=account_dict['username'],
                                     password=account_dict['password'],
                                     service=service_obj))
                 for environment_dict in service_dict['environments']:
                     environment_obj = Environment(
                         service=service_obj,
                         matching_content=environment_dict[
                             'matching_content'])
                     db_session.add(environment_obj)
                     if 'properties' in environment_dict:
                         for property_dict in environment_dict[
                                 'properties']:
                             db_session.add(
                                 Property(environment=environment_obj,
                                          name=property_dict['name'],
                                          value=property_dict['value']))
         db_session.commit()