Skip to content

Commit

Permalink
Prevent scan when mode is not defined
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
pditommaso committed Oct 29, 2024
1 parent cc7b535 commit d42bcae
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ class ContainerScanServiceImpl implements ContainerScanService, JobHandler<ScanE
@Override
void scanOnRequest(ContainerRequest request) {
try {
if( request.scanId && request.isContainer() && !request.dryRun ) {
if( request.scanId && request.scanMode && request.isContainer() && !request.dryRun ) {
log.debug "Container scan required by scanOnRequest=$request"
scan(fromContainer(request))
}
else if( request.scanId && !request.isContainer() && request.buildNew==false && request.succeeded && !request.dryRun && !existsScan(request.scanId) ) {
else if( request.scanId && request.scanMode && !request.isContainer() && request.buildNew==false && request.succeeded && !request.dryRun && !existsScan(request.scanId) ) {
log.debug "Container scan required by cached request=$request"
scan(fromContainer(request))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import java.time.Duration
import java.time.Instant

import io.micronaut.test.extensions.spock.annotation.MicronautTest
import io.seqera.wave.api.ScanMode
import io.seqera.wave.configuration.ScanConfig
import io.seqera.wave.core.ContainerPlatform
import io.seqera.wave.service.builder.BuildFormat
Expand Down Expand Up @@ -367,6 +368,7 @@ class ContainerScanServiceImplTest extends Specification {
def scanService = Spy(new ContainerScanServiceImpl(inspectService: inspectService, config: config))
def request = Mock(ContainerRequest)
request.scanId >> SCAN_ID
request.scanMode >> MODE
request.isContainer() >> CONTAINER
request.dryRun >> DRY_RUN
and:
Expand All @@ -379,12 +381,14 @@ class ContainerScanServiceImplTest extends Specification {
RUN_TIMES * scanService.scan(scan) >> null

where:
SCAN_ID | CONTAINER | DRY_RUN | RUN_TIMES
null | false | false | 0
'sc-123'| false | false | 0
'sc-123'| true | false | 1
'sc-123'| true | true | 0
null | true | false | 0
SCAN_ID | MODE | CONTAINER | DRY_RUN | RUN_TIMES
null | ScanMode.async | false | false | 0
'sc-123'| ScanMode.async | false | false | 0
'sc-123'| ScanMode.async | true | false | 1
'sc-123'| ScanMode.required | true | false | 1
'sc-123'| ScanMode.none | true | false | 0
'sc-123'| ScanMode.async | true | true | 0
null | ScanMode.async | true | false | 0

}

Expand All @@ -398,6 +402,7 @@ class ContainerScanServiceImplTest extends Specification {
scanService.existsScan(SCAN_ID) >> EXISTS_SCAN
and:
def request = Mock(ContainerRequest)
request.scanMode >> MODE
request.scanId >> SCAN_ID
request.buildId >> BUILD_ID
request.buildNew >> BUILD_NEW
Expand All @@ -413,16 +418,18 @@ class ContainerScanServiceImplTest extends Specification {
RUN_TIMES * scanService.scan(scan) >> null

where:
SCAN_ID | BUILD_ID | BUILD_NEW | SUCCEEDED | DRY_RUN | EXISTS_SCAN | RUN_TIMES
null | null | null | null | null | false | 0
'sc-123'| null | null | null | null | false | 0
SCAN_ID | BUILD_ID | BUILD_NEW | SUCCEEDED | MODE | DRY_RUN | EXISTS_SCAN | RUN_TIMES
null | null | null | null | ScanMode.async | null | false | 0
'sc-123'| null | null | null | ScanMode.async | null | false | 0
and:
'sc-123'| 'bd-123' | null | null | null | false | 0
'sc-123'| 'bd-123' | true | null | null | false | 0
'sc-123'| 'bd-123' | false | true | null | false | 1
'sc-123'| 'bd-123' | false | false | null | false | 0
'sc-123'| 'bd-123' | false | null | null | true | 0
'sc-123'| 'bd-123' | false | null | true | false | 0
'sc-123'| 'bd-123' | null | null | ScanMode.async | null | false | 0
'sc-123'| 'bd-123' | true | null | ScanMode.async | null | false | 0
'sc-123'| 'bd-123' | false | true | ScanMode.async | null | false | 1
'sc-123'| 'bd-123' | false | true | ScanMode.required | null | false | 1
'sc-123'| 'bd-123' | false | true | ScanMode.none | null | false | 0
'sc-123'| 'bd-123' | false | false | ScanMode.async | null | false | 0
'sc-123'| 'bd-123' | false | null | ScanMode.async | null | true | 0
'sc-123'| 'bd-123' | false | null | ScanMode.async | true | false | 0
}

def 'should store scan entry' () {
Expand Down

0 comments on commit d42bcae

Please sign in to comment.