def test_write_issues(self): data = ([ OrderedDict([ ('body', 'Issue'), ('type', "'type1'"), ('src', 'es1'), ('eventID', 'e1'), ('subject', self.domain), ])],[] ) config = { 'level_new_issue_change': 5, 'fetch_issue_level_data': False } helper = Helper() ew = EventWriter() company = Company(self.domain, issue_data=data) writer = CompanyWriter(company, helper, ew) writer.write_issues(**config) assert len(ew.events) == 1 event_data = ew.events[0]['data'] assert 'body=Issue' in event_data assert "type='type1'" in event_data assert 'subject=example.com' in event_data assert 'src=es1' in event_data assert 'eventID=e1' in event_data assert 'severity=5' in event_data
def test_write_issues(self): data = ([ OrderedDict([ ('body', 'Issue'), ('type', "'type1'"), ('src', 'es1'), ('eventID', 'e1'), ('subject', self.domain), ('diff', -1), ]) ], []) config = {'level_new_issue_change': 5, 'fetch_issue_level_data': False} helper = Helper() leef_logger = LogWriter() company = Company(self.domain, issue_data=data) writer = CompanyWriter(company, helper, leef_logger) writer.write_issues(**config) assert len(leef_logger.log) == 1 event_data = leef_logger.log[0] assert 'body=Issue' in event_data assert "type='type1'" in event_data assert 'subject=example.com' in event_data assert 'src=es1' in event_data assert 'eventID=e1' in event_data assert 'sev=5' in event_data
def test_with_all_portfolios(self): data = self.data.copy() data['portfolio_ids'] = 'all' fields = ['portfolio_ids'] helper = Helper(**data) options = extract_input_fields(helper, fields) assert options.get('portfolio_ids') == 'all'
def test_with_specific_portfolio_ids(self): data = self.data.copy() p1 = '123abc' p2 = '789xyz' data['portfolio_ids'] = u'{},{},'.format(p1, p2) fields = ['portfolio_ids'] helper = Helper(**data) options = extract_input_fields(helper, fields) assert options.get('portfolio_ids') == [p1, p2]
def test_extract_input_fields(self): helper = Helper(**self.data) fields = ['key1', 'key2', 'key3'] options = extract_input_fields(helper, fields) assert len(options) == len(fields) + 2 # +2 to include portfolio ids and proxy assert options.get('key1') == self.data['key1'] assert options.get('key2') == self.data['key2'] assert options.get('key3') is None assert options.get('portfolio_ids') is None assert options.get('proxy') == {}
def test_write_issues_with_issue_level(self): data = ([ OrderedDict([ ('body', 'Issue'), ('type', "'type1'"), ('src', 'es1'), ('eventID', 'e1'), ('subject', self.domain), ]), ],[{'count': 5, 'eventId': 383887, 'issuer_organization_name': 'COMODO CA Limited', 'ssc_domain': 'sacumen.com', 'first_seen_time': '2019-08-09T01:24:49.268Z', 'last_seen_time': '2019-09-08T23:52:09.401Z', 'subject_common_name': 'ssl946379.cloudflaressl.com', 'parent_domain': 'sacumen.com', 'not_valid_after': '2020-02-26T23:59:59.000Z', 'issueType': 'tls_ocsp_stapling', 'group_status': 'active', 'issue_id': '36c7697d-cafd-5b79-b3e2-0a11254d6054', 'not_valid_before': '2019-08-20T00:00:00.000Z', 'factor': 'network_security', 'effective_date': '2019-09-08T00:00:00.000Z', 'connection_attributes': {'dst_ip': '104.19.246.1', 'dst_port': 443}}, {'count': 5, 'eventId': 383887, 'issuer_organization_name': 'COMODO CA Limited', 'ssc_domain': 'sacumen.com', 'first_seen_time': '2019-08-09T01:24:49.268Z', 'last_seen_time': '2019-09-08T23:52:09.401Z', 'subject_common_name': 'ssl946379.cloudflaressl.com', 'parent_domain': 'sacumen.com', 'not_valid_after': '2020-02-26T23:59:59.000Z', 'issueType': 'tls_ocsp_stapling', 'group_status': 'active', 'issue_id': '36c7697d-cafd-5b79-b3e2-0a11254d6054', 'not_valid_before': '2019-08-20T00:00:00.000Z', 'factor': 'network_security', 'effective_date': '2019-09-08T00:00:00.000Z', 'connection_attributes': {'dst_ip': '104.19.246.1', 'dst_port': 443}} ]) config = { 'level_new_issue_change': 5, 'fetch_issue_level_data': True } helper = Helper() ew = EventWriter() company = Company(self.domain, issue_data=data) writer = CompanyWriter(company, helper, ew) writer.write_issues(**config) assert len(ew.events) == 3 event_data = ew.events[0]['data'] import json issue_level_data = ew.events[1]['data'] assert type(issue_level_data) == str assert 'ssc_domain' in json.dumps(issue_level_data) assert 'body=Issue' in event_data assert "type='type1'" in event_data assert 'subject=example.com' in event_data assert 'src=es1' in event_data assert 'eventID=e1' in event_data assert 'severity=5' in event_data
def test_with_proxy_settings_without_username_and_password(self): proxy = { 'proxy_type': 'https', 'proxy_url': 'example.com', 'proxy_port': '8080' } data = self.data.copy() data['proxy'] = proxy fields = ['key1', 'key2'] helper = Helper(**data) options = extract_input_fields(helper, fields) assert options['proxy']['http'] == 'https://example.com:8080' assert options['proxy']['https'] == 'https://example.com:8080'
def test_write_overall(self): data = [OrderedDict([ ('cat', 'OverAll'), ('type', "'scoreChange'"), ('src', 'OverallScore'), ('subject', self.domain), ('scoreYesterday', '100'), ('scoreToday', '99'), ('scoreChange', '-1'), ('diff', '-1'), ]),OrderedDict([ ('cat', 'OverAll'), ('type', "'scoreChange'"), ('src', 'OverallScore'), ('subject', self.domain), ('scoreYesterday', '95'), ('scoreToday', '96'), ('scoreChange', '1'), ('diff', '1'), ])] config = { 'diff_override_own_overall': True, 'level_overall_change': '10', } helper = Helper() ew = EventWriter() company = Company(self.domain, overall_data=data) writer = CompanyWriter(company, helper, ew) writer.write_overall(**config) assert len(ew.events) == 2 event_data = ew.events[0]['data'] assert 'cat=OverAll' in event_data assert "type='scoreChange'" in event_data assert 'src=OverallScore' in event_data assert 'subject={}'.format(self.domain) in event_data assert 'scoreYesterday=100' in event_data assert 'scoreToday=99' in event_data assert 'scoreChange=-1' in event_data assert 'severity=10' in event_data # Test with zero difference and no override ew.clear_events() data[0].update({'diff': 0}) config.update({'diff_override_own_overall': False}) company = Company(self.domain, overall_data=data) writer = CompanyWriter(company, helper, ew) writer.write_overall(**config) assert len(ew.events) == 1 # Test with zero difference and override ew.clear_events() config.update({'diff_override_own_overall': True}) company = Company(self.domain, overall_data=data) writer = CompanyWriter(company, helper, ew) writer.write_overall(**config) assert len(ew.events) == 2
def test_write_factors(self): data = [ OrderedDict([ ('body', 'Factor'), ('type', "'scoreChange'"), ('src', 's1'), ('subject', self.domain), ('scoreYesterday', '99'), ('scoreToday', '98'), ('scoreChange', 1), ('diff', 1), ('factorDescription', "'desc1'") ]), OrderedDict([ ('body', 'Factor'), ('type', "'scoreChange'"), ('src', 's2'), ('subject', self.domain), ('scoreYesterday', '89'), ('scoreToday', '88'), ('scoreChange', 11), ('diff', 11), ('factorDescription', "'desc2'") ]), ] config = { 'diff_override_own_factor': True, 'level_factor_change': '10', } helper = Helper() ew = EventWriter() company = Company(self.domain, factor_data=data) writer = CompanyWriter(company, helper, ew) writer.write_factors(**config) event_data_1 = ew.events[0]['data'] assert 'body=Factor' in event_data_1 assert "type='scoreChange'" in event_data_1 assert 'src=s1' in event_data_1 assert 'subject={}'.format(self.domain) in event_data_1 assert 'scoreYesterday=99' in event_data_1 assert 'scoreToday=98' in event_data_1 assert 'scoreChange=1' in event_data_1 assert 'severity=10' in event_data_1 # event_data_2 = ew.events[1]['data'] # assert 'body=Factor' in event_data_2 # assert "type='scoreChange'" in event_data_2 # assert 'src=s2' in event_data_2 # assert 'domain={}'.format(self.domain) in event_data_2 # assert 'scoreYesterday=89' in event_data_2 # assert 'scoreToday=88' in event_data_2 # assert 'scoreChange=11' in event_data_2 # assert 'severity=10' in event_data_2 # Test with zero difference and no override ew.clear_events() data[0].update({'diff': 0}) config.update({'diff_override_own_factor': False}) company = Company(self.domain, factor_data=data) writer = CompanyWriter(company, helper, ew) writer.write_factors(**config) assert len(ew.events) == 1 # Test with zero difference and override ew.clear_events() config.update({'diff_override_own_factor': True}) company = Company(self.domain, factor_data=data) writer = CompanyWriter(company, helper, ew) writer.write_factors(**config) assert len(ew.events) == 2