Skip to content

Commit

Permalink
Fix wrong scanned artifact count when there are multiple report for a…
Browse files Browse the repository at this point in the history
…n artifact (goharbor#18975)

Signed-off-by: stonezdj <[email protected]>
  • Loading branch information
stonezdj authored Jul 25, 2023
1 parent d7ff8bf commit d92aca9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/pkg/securityhub/dao/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ order by s.critical_cnt desc, s.high_cnt desc, s.medium_cnt desc, s.low_cnt desc
limit 5`

// sql to query the scanned artifact count
scannedArtifactCountSQL = `select count(1)
from artifact a
left join scan_report s on a.digest = s.digest
where s.registration_uuid= ? and s.uuid is not null`
scannedArtifactCountSQL = `select count(1)
from artifact
where exists (select 1 from scan_report s where artifact.digest = s.digest and s.registration_uuid = ?) `

// sql to query the dangerous CVEs
dangerousCVESQL = `select vr.*
Expand Down
1 change: 1 addition & 0 deletions src/pkg/securityhub/dao/security_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func (suite *SecurityDaoTestSuite) TearDownTest() {
`delete from scan_report where uuid = 'uuid'`,
`delete from artifact where digest = 'digest1001'`,
`delete from scanner_registration where uuid='ruuid'`,
`delete from scanner_registration where uuid='uuid2'`,
`delete from vulnerability_record where cve_id='2023-4567-12345'`,
`delete from report_vulnerability_record where report_uuid='ruuid'`,
`delete from vulnerability_record where registration_uuid ='uuid2'`,
Expand Down

0 comments on commit d92aca9

Please sign in to comment.