Skip to content

Commit

Permalink
Merge pull request #57 from samuzzal-choudhury/fix_unkn_lic_rep
Browse files Browse the repository at this point in the history
Fixed unknown license reporting
  • Loading branch information
Samuzzal Choudhury authored Apr 16, 2019
2 parents 763a575 + 8faf1f2 commit 49aba9f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
10 changes: 8 additions & 2 deletions f8a_report/report_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,13 @@ def normalize_worker_data(self, start_date, end_date, stack_data, worker, freque
else:
avg_response_time['maven'] = 0

# generate aggregated data section
# Get a list of unknown licenses
unknown_licenses = []
for lic_dict in self.flatten_list(all_unknown_lic):
if 'license' in lic_dict:
unknown_licenses.append(lic_dict['license'])

# generate aggregated data section
template['stacks_summary'] = {
'total_stack_requests_count': total_stack_requests['all'],
'npm': {
Expand All @@ -454,7 +460,7 @@ def normalize_worker_data(self, start_date, end_date, stack_data, worker, freque
'average_response_time': '{} ms'.format(avg_response_time['maven'])
},
'unique_unknown_licenses_with_frequency':
self.populate_key_count(self.flatten_list(all_unknown_lic)),
self.populate_key_count(unknown_licenses),
'unique_cves':
self.populate_key_count(all_cve_list),
'total_average_response_time':
Expand Down
19 changes: 16 additions & 3 deletions tests/data/stackdata.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
"status": "Successful",
"outlier_packages": [],
"unknown_licenses": {
"really_unknown": [],
"really_unknown": [{
"license": "mpl-2.0",
"package": "@renovatebot/docker-registry-client"
}],
"component_conflict": []
},
"conflict_packages": [],
Expand Down Expand Up @@ -124,7 +127,14 @@
"MIT": "mit"
},
"outlier_licenses": [],
"unknown_licenses": [],
"unknown_licenses": {
"really_unknown": [
{
"license": "mpl-2.0",
"package": "@renovatebot/docker-registry-client"
}
]
},
"conflict_licenses": [],
"_representative_licenses": "mit"
}
Expand Down Expand Up @@ -252,7 +262,10 @@
"status": "Successful",
"outlier_packages": [],
"unknown_licenses": {
"really_unknown": [],
"really_unknown": [{
"license": "mpl-2.0",
"package": "@renovatebot/docker-registry-client"
}],
"component_conflict": []
},
"conflict_packages": [],
Expand Down
8 changes: 8 additions & 0 deletions tests/test_stack_report_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,14 @@ def test_normalize_worker_data(_mock1, _mock2, _mock3):
stackdata, 'stack_aggregator_v2', 'weekly')

assert resp is not None
# Test whether summary for two stacks are reported
assert resp['stacks_summary']['total_stack_requests_count'] == 2

# Test whether summary of a CVE is reported
assert resp['stacks_summary']['unique_cves']['CVE-2014-6393:4.3'] == 2

# Test whether unknown licenses are reported
assert resp['stacks_summary']['unique_unknown_licenses_with_frequency']['mpl-2.0'] == 2


@mock.patch('f8a_report.report_helper.S3Helper.store_json_content', return_value=True)
Expand Down

0 comments on commit 49aba9f

Please sign in to comment.