Skip to content

Commit f529bb5

Browse files
authored
Merge pull request #93 from nebula-plugins/fix-validation-sign-error
fix signing error in validation runs
2 parents 59154f8 + d8ab0e9 commit f529bb5

8 files changed

Lines changed: 531 additions & 31 deletions

File tree

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ dependencies {
5454
}
5555
testImplementation("org.spockframework:spock-core:2.3-groovy-4.0")
5656
testImplementation("org.spockframework:spock-junit4:2.3-groovy-4.0")
57+
testImplementation("org.mock-server:mockserver-netty:5.15.0")
5758
}
5859

5960
gradlePlugin {

gradle.lockfile

Lines changed: 108 additions & 7 deletions
Large diffs are not rendered by default.
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
package nebula.plugin.publishing
2+
3+
import org.mockserver.integration.ClientAndServer
4+
import org.mockserver.model.HttpRequest.request
5+
import org.mockserver.model.HttpResponse.response
6+
7+
fun expectPublicationWithChecksums(mockServer: ClientAndServer, path: String): List<(ClientAndServer) -> Unit> {
8+
val verifications = mutableListOf<(ClientAndServer) -> Unit>()
9+
val paths = listOf(
10+
path,
11+
"$path.md5",
12+
"$path.sha1",
13+
"$path.sha256",
14+
"$path.sha512"
15+
)
16+
paths.forEach {
17+
val request = request(it).withMethod("PUT")
18+
mockServer
19+
.`when`(request)
20+
.respond { response().withStatusCode(200) }
21+
verifications.add { it.verify(request) }
22+
}
23+
return verifications
24+
}
25+
26+
fun expectSignedPublicationWithChecksums(mockServer: ClientAndServer, path: String): List<(ClientAndServer) -> Unit> {
27+
return expectPublicationWithChecksums(mockServer, path) +
28+
expectPublicationWithChecksums(mockServer, "$path.asc")
29+
}
30+
31+
class Publication(
32+
val mockServer: ClientAndServer,
33+
val repo: String,
34+
val groupName: String,
35+
val moduleName: String,
36+
val version: String,
37+
) {
38+
private val groupPath = groupName.replace(".", "/")
39+
private val modulePath = "$repo/$groupPath/${moduleName}"
40+
private val fullPath = "$modulePath/${version}"
41+
private val verifications = mutableListOf<(ClientAndServer) -> Unit>()
42+
fun withArtifact(classifier: String, extension: String) {
43+
verifications.addAll(
44+
expectSignedPublicationWithChecksums(
45+
mockServer,
46+
"/$fullPath/$moduleName-${version}-$classifier.$extension"
47+
)
48+
)
49+
}
50+
51+
fun withGradleModuleMetadata() {
52+
verifications.addAll(
53+
expectSignedPublicationWithChecksums(mockServer, "/$fullPath/$moduleName-${version}.module")
54+
)
55+
}
56+
57+
fun withArtifact(extension: String) {
58+
verifications.addAll(
59+
expectSignedPublicationWithChecksums(mockServer, "/$fullPath/$moduleName-${version}.$extension")
60+
)
61+
}
62+
63+
fun verifications(): List<(ClientAndServer) -> Unit> {
64+
return verifications
65+
}
66+
}
67+
68+
fun ClientAndServer.expectPublication(
69+
repo: String,
70+
groupName: String,
71+
moduleName: String,
72+
version: String,
73+
additional: Publication.() -> Unit = {}
74+
): VerificationsContainer {
75+
val groupPath = groupName.replace(".", "/")
76+
val modulePath = "$repo/$groupPath/${moduleName}"
77+
val fullPath = "$modulePath/${version}"
78+
val allVersionsXml = listOf("0.0.0").joinToString("/n") { " <version>$it</version>" }
79+
`when`(request("/$modulePath/maven-metadata.xml"))
80+
.respond {
81+
response().withBody(
82+
"""
83+
<?xml version="1.0" encoding="UTF-8"?>
84+
<metadata>
85+
<groupId>${groupName}</groupId>
86+
<artifactId>${moduleName}</artifactId>
87+
<versioning>
88+
<latest>0.0.0</latest>
89+
<release>0.0.0</release>
90+
<versions>
91+
$allVersionsXml
92+
</versions>
93+
<lastUpdated>20210816163607</lastUpdated>
94+
</versioning>
95+
</metadata>
96+
"""
97+
).withStatusCode(200)
98+
}
99+
val verifications = mutableListOf<(ClientAndServer) -> Unit>()
100+
verifications.addAll(
101+
expectSignedPublicationWithChecksums(this, "/$fullPath/${moduleName}-${version}.pom")
102+
)
103+
verifications.addAll(
104+
expectPublicationWithChecksums(this, "/$modulePath/maven-metadata.xml")
105+
)
106+
107+
verifications.addAll(
108+
Publication(this, repo, groupName, moduleName, version).apply { additional() }.verifications()
109+
)
110+
return VerificationsContainer(verifications)
111+
}
112+
113+
class VerificationsContainer(val verifications: List<(ClientAndServer) -> Unit>) {
114+
fun verify(mockServer: ClientAndServer) {
115+
verifications.forEach { verification ->
116+
verification(mockServer)
117+
}
118+
}
119+
}
Lines changed: 80 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,94 @@
11
package nebula.plugin.plugin
22

3+
import nebula.test.dsl.ProjectBuilder
4+
35
//language=kotlin
4-
const val DISABLE_PUBLISH_TASKS : String = """
6+
const val DISABLE_PUBLISH_TASKS: String = """
57
afterEvaluate {
68
tasks.withType<AbstractPublishToMaven>() {
79
onlyIf { false }
810
}
9-
tasks.withType<Sign>(){
10-
onlyIf { false } // we don't have a signing key in integration tests (yet)
11-
}
11+
project.tasks.findByName("publishPlugins")?.onlyIf { false }
1212
}
1313
"""
1414

15-
1615
//language=kotlin
17-
const val DISABLE_MAVEN_CENTRAL_TASKS : String = """
16+
const val DISABLE_MAVEN_CENTRAL_TASKS: String = """
1817
project.tasks.findByName("initializeSonatypeStagingRepository")?.onlyIf { false }
1918
project.tasks.findByName("closeSonatypeStagingRepository")?.onlyIf { false }
2019
project.tasks.findByName("releaseSonatypeStagingRepository")?.onlyIf { false }
21-
"""
20+
"""
21+
22+
//language=kotlin
23+
fun ProjectBuilder.mockSign() {
24+
rawBuildScript(
25+
//language=kotlin
26+
"""
27+
afterEvaluate {
28+
project.extensions.getByType<SigningExtension>().signatories = object:
29+
org.gradle.plugins.signing.signatory.SignatoryProvider<Signatory> {
30+
override fun configure(settings: SigningExtension?, closure: groovy.lang.Closure<*>?) {
31+
}
32+
33+
override fun getDefaultSignatory(project: Project?): Signatory {
34+
return object: Signatory {
35+
override fun getName(): String {
36+
return "name"
37+
}
38+
39+
override fun sign(toSign: java.io.InputStream?, destination: java.io.OutputStream?) {
40+
destination?.write( sign(toSign))
41+
}
42+
43+
override fun sign(toSign: java.io.InputStream?): ByteArray {
44+
return "signature".toByteArray()
45+
}
46+
47+
override fun getKeyId(): String {
48+
return "id"
49+
}
50+
}
51+
}
52+
53+
override fun getSignatory(name: String?): Signatory {
54+
return object: Signatory {
55+
override fun getName(): String {
56+
return "name"
57+
}
58+
59+
override fun sign(toSign: java.io.InputStream?, destination: java.io.OutputStream?) {
60+
destination?.write( sign(toSign))
61+
}
62+
63+
override fun sign(toSign: java.io.InputStream?): ByteArray {
64+
return "signature".toByteArray()
65+
}
66+
67+
override fun getKeyId(): String {
68+
return "id"
69+
}
70+
}
71+
}
72+
}
73+
}
74+
"""
75+
)
76+
}
77+
78+
fun ProjectBuilder.nebulaOssPublishing(
79+
netflixOssRepositoryBaseUrl: String,
80+
packageGroup: String = "com.netflix",
81+
netflixOssRepository: String = "netflix-oss"
82+
) {
83+
rawBuildScript(
84+
"""
85+
nebulaOssPublishing {
86+
signingKey = "something"
87+
signingPassword = "something"
88+
packageGroup = "$packageGroup"
89+
netflixOssRepositoryBaseUrl = "$netflixOssRepositoryBaseUrl"
90+
netflixOssRepository = "$netflixOssRepository"
91+
}
92+
"""
93+
)
94+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package nebula.plugin.publishing
2+
3+
import org.mockserver.integration.ClientAndServer
4+
import org.mockserver.model.HttpRequest.request
5+
import org.mockserver.model.HttpResponse.response
6+
7+
fun ClientAndServer.mockGradlePluginPortal(pluginId: String) {
8+
`when`(
9+
request()
10+
.withMethod("POST")
11+
.withPath("/api/v1/publish/versions/validate/$pluginId")
12+
)
13+
.respond {
14+
response().withBody(
15+
//language=json
16+
"""{"failed": false}""")
17+
}
18+
}

src/test/kotlin/nebula/plugin/plugin/IntegrationTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ internal class IntegrationTest {
3030
$DISABLE_PUBLISH_TASKS
3131
""".trimIndent()
3232
)
33+
mockSign()
3334
src {
3435
main {
3536
java("example/Main.java", SAMPLE_JAVA_MAIN_CLASS)
@@ -56,6 +57,7 @@ gradlePlugin {
5657
}
5758
"""
5859
)
60+
mockSign()
5961
src {
6062
main {
6163
java("example/MyPlugin.java", SAMPLE_JAVA_PLUGIN)

0 commit comments

Comments
 (0)