ci: qualify explicit revision worker file reads
This commit is contained in:
parent
32274747f5
commit
43b6639516
56
services/jenkins/validation/lesavka-worker-source.groovy
Normal file
56
services/jenkins/validation/lesavka-worker-source.groovy
Normal file
@ -0,0 +1,56 @@
|
||||
// Read public worker definitions through the installed Pipeline step. Supply two
|
||||
// reviewed commits with different payload hashes and an existing software run.
|
||||
// No job is created, saved, queued or changed; credentials stay inside GitSCMSource.
|
||||
import groovy.json.JsonOutput
|
||||
import hudson.model.Run
|
||||
import hudson.model.TaskListener
|
||||
import jenkins.model.Jenkins
|
||||
import jenkins.plugins.git.GitSCMSource
|
||||
import org.jenkinsci.plugins.workflow.steps.StepContext
|
||||
import org.jenkinsci.plugins.workflow.steps.scm.ReadScmFileStep
|
||||
import java.security.MessageDigest
|
||||
|
||||
def job = Jenkins.get().getItemByFullName('lesavka-software-tests')
|
||||
def build = job.getBuildByNumber(binding.getVariable('existingBuild') as int)
|
||||
assert build != null && !build.building
|
||||
def before = job.configFile.asString()
|
||||
def context = [get: { Class type ->
|
||||
if (type == Run) { return build }
|
||||
if (type == TaskListener) { return TaskListener.NULL }
|
||||
throw new IllegalStateException('Unexpected step context: ' + type.name)
|
||||
}] as StepContext
|
||||
def source = new GitSCMSource('https://scm.bstein.dev/bstein/lesavka.git')
|
||||
source.credentialsId = 'gitea-pat'
|
||||
def read = { String revision, String path ->
|
||||
def execution = new ReadScmFileStep(source, revision, path).start(context)
|
||||
def method = execution.class.getDeclaredMethod('run')
|
||||
method.accessible = true
|
||||
method.invoke(execution)
|
||||
}
|
||||
def digest = { String value ->
|
||||
MessageDigest.getInstance('SHA-256').digest(value.getBytes('UTF-8')).encodeHex().toString()
|
||||
}
|
||||
def expected = binding.getVariable('expectedPayloads')
|
||||
assert expected.size() == 2 && expected.values().toSet().size() == 2
|
||||
def checks = []
|
||||
expected.each { revision, sha256 ->
|
||||
assert revision ==~ /[0-9a-f]{40}/
|
||||
assert sha256 ==~ /[0-9a-f]{64}/
|
||||
assert digest(read(revision, 'docker/software-test-pod.yaml')) == sha256
|
||||
checks << 'exact_worker_payload_' + revision
|
||||
}
|
||||
boolean missingRefused = false
|
||||
try {
|
||||
read('0' * 40, 'docker/software-test-pod.yaml')
|
||||
} catch (java.lang.reflect.InvocationTargetException failure) {
|
||||
assert failure.cause instanceof hudson.AbortException
|
||||
assert failure.cause.message == 'No such revision'
|
||||
missingRefused = true
|
||||
}
|
||||
assert missingRefused
|
||||
checks << 'missing_revision_refused_without_fallback'
|
||||
assert job.configFile.asString() == before
|
||||
checks << 'installed_job_unchanged'
|
||||
println(JsonOutput.toJson([status: 'passed', checks: checks,
|
||||
plugin: Jenkins.get().pluginManager.getPlugin('workflow-scm-step').version]))
|
||||
return null
|
||||
Loading…
x
Reference in New Issue
Block a user