def test_save(self): """New configuration is successfully written and comments are preserved.""" config = BinaryAlertConfig() config._config['force_destroy'] = True config.aws_region = 'us-west-2' config.name_prefix = 'new_name_prefix' config.enable_carbon_black_downloader = False config.carbon_black_url = 'https://example2.com' config.encrypted_carbon_black_api_token = 'B' * 100 config.save() # Verify that all of the original comments were preserved. with open(CONFIG_FILE) as config_file: raw_data = config_file.read() for i in range(1, 6): self.assertIn('comment{}'.format(i), raw_data) new_config = BinaryAlertConfig() self.assertEqual(True, new_config._config['force_destroy']) self.assertEqual(config.aws_region, new_config.aws_region) self.assertEqual(config.name_prefix, new_config.name_prefix) self.assertEqual( config.enable_carbon_black_downloader, new_config.enable_carbon_black_downloader) self.assertEqual( config.encrypted_carbon_black_api_token, new_config.encrypted_carbon_black_api_token)
def test_invalid_encrypted_carbon_black_api_token(self): """InvalidConfigError raised if encrypted token is too short.""" config = BinaryAlertConfig() with self.assertRaises(InvalidConfigError): config.encrypted_carbon_black_api_token = 'ABCD'