2019-05-13 12:29:07 +02:00
|
|
|
import static org.hamcrest.Matchers.containsString
|
|
|
|
import static org.hamcrest.Matchers.hasItem
|
|
|
|
import static org.hamcrest.Matchers.allOf
|
|
|
|
|
|
|
|
import org.junit.Before
|
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.rules.RuleChain
|
|
|
|
import org.junit.rules.ExpectedException
|
|
|
|
import static org.junit.Assert.assertThat
|
|
|
|
|
|
|
|
import util.BasePiperTest
|
|
|
|
import util.JenkinsDockerExecuteRule
|
|
|
|
import util.JenkinsShellCallRule
|
|
|
|
import util.JenkinsReadYamlRule
|
|
|
|
import util.JenkinsStepRule
|
|
|
|
import util.JenkinsLoggingRule
|
|
|
|
import util.Rules
|
|
|
|
|
|
|
|
class SonarExecuteScanTest extends BasePiperTest {
|
|
|
|
private ExpectedException thrown = ExpectedException.none()
|
|
|
|
private JenkinsReadYamlRule readYamlRule = new JenkinsReadYamlRule(this)
|
|
|
|
private JenkinsStepRule jsr = new JenkinsStepRule(this)
|
|
|
|
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
|
|
|
|
private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
|
|
|
|
private JenkinsDockerExecuteRule jedr = new JenkinsDockerExecuteRule(this)
|
|
|
|
|
|
|
|
@Rule
|
|
|
|
public RuleChain rules = Rules
|
|
|
|
.getCommonRules(this)
|
|
|
|
.around(readYamlRule)
|
|
|
|
.around(thrown)
|
|
|
|
.around(jedr)
|
|
|
|
.around(jscr)
|
|
|
|
.around(jlr)
|
|
|
|
.around(jsr)
|
|
|
|
|
|
|
|
def sonarInstance
|
|
|
|
|
|
|
|
@Before
|
|
|
|
void init() throws Exception {
|
|
|
|
sonarInstance = null
|
|
|
|
helper.registerAllowedMethod("withSonarQubeEnv", [String.class, Closure.class], { string, closure ->
|
|
|
|
sonarInstance = string
|
|
|
|
return closure()
|
|
|
|
})
|
2020-09-08 17:28:29 +02:00
|
|
|
helper.registerAllowedMethod("unstash", [String.class], { stashInput -> return [] })
|
2019-05-13 12:29:07 +02:00
|
|
|
helper.registerAllowedMethod("fileExists", [String.class], { file -> return file })
|
|
|
|
helper.registerAllowedMethod('string', [Map], { m -> m })
|
|
|
|
helper.registerAllowedMethod('withCredentials', [List, Closure], { l, c ->
|
|
|
|
try {
|
2020-09-08 17:28:29 +02:00
|
|
|
binding.setProperty(l[0].variable, 'TOKEN_' + l[0].credentialsId)
|
2019-05-13 12:29:07 +02:00
|
|
|
c()
|
|
|
|
} finally {
|
|
|
|
binding.setProperty(l[0].variable, null)
|
|
|
|
}
|
|
|
|
})
|
2020-03-16 11:34:07 +02:00
|
|
|
helper.registerAllowedMethod('withEnv', [List.class, Closure.class], { List envVars, Closure body ->
|
|
|
|
body()
|
|
|
|
})
|
2019-05-13 12:29:07 +02:00
|
|
|
nullScript.commonPipelineEnvironment.setArtifactVersion('1.2.3-20180101')
|
|
|
|
}
|
|
|
|
|
2019-08-11 22:42:34 +02:00
|
|
|
@Test
|
|
|
|
void testWithCustomTlsCertificates() throws Exception {
|
2020-04-08 12:55:46 +02:00
|
|
|
jsr.step.sonarExecuteScan.loadCertificates(
|
2019-08-11 22:42:34 +02:00
|
|
|
customTlsCertificateLinks: [
|
|
|
|
'http://url.to/my.cert'
|
|
|
|
]
|
|
|
|
)
|
|
|
|
// asserts
|
|
|
|
assertThat(jscr.shell, allOf(
|
|
|
|
hasItem(containsString('wget --directory-prefix .certificates/ --no-verbose http://url.to/my.cert')),
|
2019-12-20 11:51:33 +02:00
|
|
|
hasItem(containsString('keytool -import -noprompt -storepass changeit -keystore .certificates/cacerts -alias \'my.cert\' -file \'.certificates/my.cert\''))
|
2019-08-11 22:42:34 +02:00
|
|
|
))
|
|
|
|
assertJobStatusSuccess()
|
|
|
|
}
|
2019-05-13 12:29:07 +02:00
|
|
|
}
|