Exemplo n.º 1
0
    def test_user_config_save_reload(self, conf_file):
        def _read_passwd(conf_file):
            with open(conf_file, 'r') as f:
                tuples = [(line.split()[5], line.split()[7])
                          for line in f.readlines()
                          if line.startswith('SNMPv3')]
            return [e for t in tuples for e in t]

        conf = config.UserConfig(conf_file)
        conf.save()
        encrypt_passwds = _read_passwd(conf_file)
        self.assertEqual(len(encrypt_passwds), 4)
        for passwd in encrypt_passwds:
            self.assertTrue(any([passwd == '-', cipher.is_encrypted(passwd)]))

        self.test_agent_config(conf_file)
Exemplo n.º 2
0
    def test_agent_config_save_reload(self, conf_file):
        def _read_passwd(conf_file):
            pattern = ('password='******'password = '******'r') as f:
                return [
                    line.split('=')[1].strip() for line in f.readlines()
                    if line.startswith(pattern)
                ]

        conf = config.AgentConfig(conf_file)
        conf.save()
        encrypt_passwds = _read_passwd(conf_file)
        self.assertEqual(len(encrypt_passwds), 2)
        for passwd in encrypt_passwds:
            self.assertTrue(cipher.is_encrypted(passwd))

        self.test_agent_config(conf_file)
Exemplo n.º 3
0
 def test_is_encrypted_true(self):
     data = 'abc\x06'
     self.assertTrue(cipher.is_encrypted(data))
Exemplo n.º 4
0
 def test_is_encrypted_false(self):
     data = 'abc'
     self.assertFalse(cipher.is_encrypted(data))
Exemplo n.º 5
0
 def __init__(self, password):
     if cipher.is_encrypted(password):
         self.encrypted, self.raw = password, cipher.decrypt(password)
     else:
         self.encrypted, self.raw = cipher.encrypt(password), password