"type" param renamed to "finding_type" in finding DAO

Fixed bug, which happened due to type -> finding_type refactoring
This commit is contained in:
VakarisZ 2021-01-11 11:43:01 +02:00
parent 46abff412d
commit ba947a6b30
4 changed files with 8 additions and 8 deletions

View File

@ -34,7 +34,7 @@ class Finding(Document):
# SCHEMA # SCHEMA
test = StringField(required=True, choices=zero_trust_consts.TESTS) test = StringField(required=True, choices=zero_trust_consts.TESTS)
status = StringField(required=True, choices=zero_trust_consts.ORDERED_TEST_STATUSES) status = StringField(required=True, choices=zero_trust_consts.ORDERED_TEST_STATUSES)
type = StringField(required=True, choices=zero_trust_consts.FINDING_TYPES) finding_type = StringField(required=True, choices=zero_trust_consts.FINDING_TYPES)
details = GenericLazyReferenceField(choices=[MonkeyFindingDetails, ScoutSuiteFindingDetails], required=True) details = GenericLazyReferenceField(choices=[MonkeyFindingDetails, ScoutSuiteFindingDetails], required=True)
# http://docs.mongoengine.org/guide/defining-documents.html#document-inheritance # http://docs.mongoengine.org/guide/defining-documents.html#document-inheritance
meta = {'allow_inheritance': True} meta = {'allow_inheritance': True}
@ -54,7 +54,7 @@ class Finding(Document):
temp_finding = Finding(test=test, temp_finding = Finding(test=test,
status=status, status=status,
details=detail_ref, details=detail_ref,
type=Finding._get_finding_type_by_details(detail_ref)) finding_type=Finding._get_finding_type_by_details(detail_ref))
temp_finding.save() temp_finding.save()
return temp_finding return temp_finding

View File

@ -12,9 +12,9 @@ class FindingService:
findings = list(Finding.objects) findings = list(Finding.objects)
details = [] details = []
for i in range(len(findings)): for i in range(len(findings)):
if findings[i].type == zero_trust_consts.MONKEY_FINDING: if findings[i].finding_type == zero_trust_consts.MONKEY_FINDING:
details = MonkeyDetailsService.fetch_details_for_display(findings[i].details.id) details = MonkeyDetailsService.fetch_details_for_display(findings[i].details.id)
elif findings[i].type == zero_trust_consts.SCOUTSUITE_FINDING: elif findings[i].finding_type == zero_trust_consts.SCOUTSUITE_FINDING:
details = findings[i].details.fetch().to_mongo() details = findings[i].details.fetch().to_mongo()
findings[i] = findings[i].to_mongo() findings[i] = findings[i].to_mongo()
findings[i] = FindingService.get_enriched_finding(findings[i]) findings[i] = FindingService.get_enriched_finding(findings[i])
@ -30,6 +30,6 @@ class FindingService:
'test_key': finding['test'], 'test_key': finding['test'],
'pillars': test_info[zero_trust_consts.PILLARS_KEY], 'pillars': test_info[zero_trust_consts.PILLARS_KEY],
'status': finding['status'], 'status': finding['status'],
'type': finding['type'] 'finding_type': finding['finding_type']
} }
return enriched_finding return enriched_finding

View File

@ -12,7 +12,7 @@ class ScoutSuiteFindingService:
@staticmethod @staticmethod
# TODO add type hinting like finding: Union[SCOUTSUITE_FINDINGS]? # TODO add type hinting like finding: Union[SCOUTSUITE_FINDINGS]?
def process_rule(finding, rule: ScoutSuiteRule): def process_rule(finding, rule: ScoutSuiteRule):
existing_findings = Finding.objects(test=finding.test, type=zero_trust_consts.SCOUTSUITE_FINDING) existing_findings = Finding.objects(test=finding.test, finding_type=zero_trust_consts.SCOUTSUITE_FINDING)
assert (len(existing_findings) < 2), "More than one finding exists for {}".format(finding.test) assert (len(existing_findings) < 2), "More than one finding exists for {}".format(finding.test)
if len(existing_findings) == 0: if len(existing_findings) == 0:

View File

@ -22,10 +22,10 @@ export class FindingsTable extends Component {
{ {
Header: 'Details', id: 'details', Header: 'Details', id: 'details',
accessor: x => { accessor: x => {
if (x.type === 'scoutsuite_finding') { if (x.finding_type === 'scoutsuite_finding') {
return <ScoutSuiteRuleButton scoutsuite_rules={x.details.scoutsuite_rules} return <ScoutSuiteRuleButton scoutsuite_rules={x.details.scoutsuite_rules}
scoutsuite_data={this.props.scoutsuite_data}/>; scoutsuite_data={this.props.scoutsuite_data}/>;
} else if (x.type === 'monkey_finding') { } else if (x.finding_type === 'monkey_finding') {
return <EventsButton finding_id={x.finding_id} return <EventsButton finding_id={x.finding_id}
latest_events={x.details.latest_events} latest_events={x.details.latest_events}
oldest_events={x.details.oldest_events} oldest_events={x.details.oldest_events}