def test_invalid_missing_config(self): """Athena - Load Missing Config File""" invalid_config_data = 'test' with mock_open(LAMBDA_FILE, invalid_config_data): with mock_open(GLOBAL_FILE, invalid_config_data): with patch('os.path.exists') as mock_exists: mock_exists.return_value = False _load_config()
def setup(self): """Setup before each method""" config_data = basic_streamalert_config() self.mocked_opens = [ mock_open('conf/global.json', json.dumps(config_data['global'])), mock_open('conf/lambda.json', json.dumps(config_data['lambda'])), mock_open('conf/clusters/prod.json', json.dumps(config_data['clusters']['prod'])) ]
def test_load_valid_config(self): """Athena - Load Config""" global_contents = json.dumps(CONFIG_DATA['global'], indent=4) lambda_contents = json.dumps(CONFIG_DATA['lambda'], indent=4) with mock_open(GLOBAL_FILE, global_contents): with mock_open(LAMBDA_FILE, lambda_contents): config = _load_config() assert_equal(type(config), dict) assert_equal(set(config), {'global', 'lambda'})
def test_load_config(): """CLI - Load config""" config_data = { 'global': { 'account': { 'aws_account_id': 'AWS_ACCOUNT_ID_GOES_HERE', 'kms_key_alias': 'stream_alert_secrets', 'prefix': 'unit-testing', 'region': 'us-west-2' }, 'terraform': { 'tfstate_bucket': 'PREFIX_GOES_HERE.streamalert.terraform.state', 'tfstate_s3_key': 'stream_alert_state/terraform.tfstate', 'tfvars': 'terraform.tfvars' }, 'infrastructure': { 'monitoring': { 'create_sns_topic': True } } }, 'lambda': { 'alert_processor_config': { 'handler': 'stream_alert.alert_processor.main.handler', 'source_bucket': 'PREFIX_GOES_HERE.streamalert.source', 'source_current_hash': '<auto_generated>', 'source_object_key': '<auto_generated>', 'third_party_libraries': [] }, 'rule_processor_config': { 'handler': 'stream_alert.rule_processor.main.handler', 'source_bucket': 'PREFIX_GOES_HERE.streamalert.source', 'source_current_hash': '<auto_generated>', 'source_object_key': '<auto_generated>', 'third_party_libraries': ['jsonpath_rw', 'netaddr'] } } } global_file = 'conf/global.json' global_contents = json.dumps(config_data['global'], indent=2) lambda_file = 'conf/lambda.json' lambda_contents = json.dumps(config_data['lambda'], indent=2) with mock_open(global_file, global_contents): with mock_open(lambda_file, lambda_contents): # mock os call # test valid and invalid clusters config = CLIConfig() assert_equal(config['global']['account']['prefix'], 'unit-testing')
def test_load_valid_config(): """Threat Intel Downloader - Test load valid config""" lambda_settings = json.dumps(LAMBDA_SETTINGS) expected_settings = { 'enabled': True, 'handler': 'main.handler', 'timeout': '60', 'memory': '128', 'source_bucket': 'unit-testing.streamalert.source', 'source_current_hash': '<auto_generated>', 'source_object_key': '<auto_generated>', 'third_party_libraries': [] } with mock_open(LAMBDA_FILE, lambda_settings): assert_equal(load_config(), expected_settings) with mock_open(LAMBDA_FILE, json.dumps({'foo': 'bar'})): assert_equal(load_config(), None)
def test_invalid_json_config(self): """Athena - Load Invalid Config""" invalid_config_data = 'This is not JSON!!!' with mock_open(LAMBDA_FILE, invalid_config_data): with mock_open(GLOBAL_FILE, invalid_config_data): _load_config()