Example #1
0
def test_version_helper():
    """CLI - Publish Helper"""
    package = AthenaPackage(basic_streamalert_config())
    publish = LambdaVersion(config=basic_streamalert_config(), package=package)
    current_version = 10
    fake_client = MockLambdaClient('athena', current_version=current_version)
    result = publish._version_helper(client=fake_client,
                                     function_name='test',
                                     code_sha_256='12345',
                                     date='2017-01-01')

    assert_equal(result, current_version + 1)
Example #2
0
def test_version_helper_error(mock_logging):
    """CLI - Publish Helper Raises Error"""
    package = AthenaPackage(basic_streamalert_config())
    publish = LambdaVersion(config=basic_streamalert_config(), package=package)
    current_version = 10
    fake_client = MockLambdaClient('athena',
                                   current_version=current_version,
                                   throw_exception=True)
    result = publish._version_helper(client=fake_client,
                                     function_name='test',
                                     code_sha_256='12345',
                                     date='2017-01-01')

    assert_false(result)
    assert_true(mock_logging.error.called)
Example #3
0
 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']))
     ]
Example #4
0
 def test_rollback_subset(self, mock_helper):
     """CLI - Lambda rollback apps and rule"""
     rollback.rollback(MockOptions(None, ['apps', 'rule']),
                       MockCLIConfig(config=basic_streamalert_config()))
     mock_helper.assert_has_calls([
         mock.call(mock.ANY, 'unit-testing_corp_box_admin_events_box_collector_app'),
         mock.call(mock.ANY, 'unit-testing_corp_duo_admin_duo_admin_collector_app'),
         mock.call(mock.ANY, 'unit-testing_corp_streamalert_rule_processor'),
         mock.call(mock.ANY, 'unit-testing_prod_streamalert_rule_processor')
     ])
Example #5
0
def test_publish_helper():
    """CLI - Publish Athena Function"""
    config = MockCLIConfig(config=basic_streamalert_config())
    package = AthenaPackage(config=config)
    publish = LambdaVersion(config=config, package=package)
    result = publish._publish_helper()

    assert_equal(
        config['lambda']['athena_partition_refresh_config']['current_version'],
        11)
    assert_true(result)
Example #6
0
def test_publish_helper_clustered():
    """CLI - Publish Clustered Function"""
    config = MockCLIConfig(config=basic_streamalert_config())
    package = RuleProcessorPackage(config=config)
    publish = LambdaVersion(config=config, package=package)
    result = publish._publish_helper(cluster='prod')

    assert_true(result)
    assert_equal(
        config['clusters']['prod']['modules']['stream_alert']['rule_processor']
        ['current_version'], 11)
Example #7
0
 def test_rollback_all(self, mock_helper):
     """CLI - Lambda rollback all"""
     rollback.rollback(MockOptions(None, ['all']),
                       MockCLIConfig(config=basic_streamalert_config()))
     mock_helper.assert_has_calls([
         mock.call(mock.ANY, 'unit-testing_streamalert_alert_processor'),
         mock.call(mock.ANY, 'unit-testing_streamalert_alert_merger'),
         mock.call(mock.ANY, 'unit-testing_corp_box_admin_events_box_collector_app'),
         mock.call(mock.ANY, 'unit-testing_corp_duo_admin_duo_admin_collector_app'),
         mock.call(mock.ANY, 'unit-testing_streamalert_athena_partition_refresh'),
         mock.call(mock.ANY, 'unit-testing_corp_streamalert_rule_processor'),
         mock.call(mock.ANY, 'unit-testing_prod_streamalert_rule_processor'),
         mock.call(mock.ANY, 'unit-testing_streamalert_threat_intel_downloader')
     ])
Example #8
0
    def setup(self):
        """Setup before each method"""
        config_data = basic_streamalert_config()

        self.fs_patcher = fake_filesystem_unittest.Patcher()
        self.fs_patcher.setUp()

        self.fs_patcher.fs.CreateFile('/conf/global.json',
                                      contents=json.dumps(
                                          config_data['global']))
        self.fs_patcher.fs.CreateFile('/conf/lambda.json',
                                      contents=json.dumps(
                                          config_data['lambda']))
        self.fs_patcher.fs.CreateFile('/conf/clusters/prod.json',
                                      contents=json.dumps(
                                          config_data['clusters']['prod']))

        # Create the config instance after creating the fake filesystem so that
        # CLIConfig uses our mocked config files instead of the real ones.
        self.config = CLIConfig()
Example #9
0
    def setUp(self):
        self.config = MockCLIConfig(config=basic_streamalert_config())

        # Find all function config sections (with 'current_version')
        self.alert_merger_config = self.config['lambda']['alert_merger_config']
        self.alert_config = self.config['lambda']['alert_processor_config']
        self.apps_config_box = (
            self.config['clusters']['corp']['modules']['stream_alert_apps']
            ['unit-testing_corp_box_admin_events_box_collector_app'])
        self.apps_config_duo = (
            self.config['clusters']['corp']['modules']['stream_alert_apps']
            ['unit-testing_corp_duo_admin_duo_admin_collector_app'])
        self.athena_config = self.config['lambda']['athena_partition_refresh_config']
        self.downloader_config = self.config['lambda']['threat_intel_downloader_config']
        self.rule_config_prod = (
            self.config['clusters']['prod']['modules']['stream_alert']['rule_processor'])
        self.rule_config_corp = (
            self.config['clusters']['corp']['modules']['stream_alert']['rule_processor'])

        self.func_configs = [
            self.alert_merger_config, self.alert_config, self.apps_config_box, self.apps_config_duo,
            self.athena_config, self.downloader_config, self.rule_config_prod, self.rule_config_corp
        ]