Skip to content

Commit 4cf45a1

Browse files
committed
fix: Allow the Pact publish task to set insecure TLS flag #1817
1 parent ba845e8 commit 4cf45a1

File tree

6 files changed

+67
-6
lines changed

6 files changed

+67
-6
lines changed

core/pactbroker/src/main/kotlin/au/com/dius/pact/core/pactbroker/PactBrokerClient.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ interface IPactBrokerClient {
415415
data class PactBrokerClientConfig @JvmOverloads constructor(
416416
val retryCountWhileUnknown: Int = 0,
417417
val retryWhileUnknownInterval: Int = 10,
418-
val insecureTLS: Boolean = false
418+
var insecureTLS: Boolean = false
419419
)
420420

421421
/**

provider/gradle/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,8 @@ pact {
913913
}
914914
```
915915

916+
If your broker uses self-signed certificates, set the property `pactBrokerInsecureTLS` to `true`.
917+
916918
## Excluding pacts from being published
917919

918920
You can exclude some of the pact files from being published by providing a list of regular expressions that match

provider/gradle/src/main/groovy/au/com/dius/pact/provider/gradle/PactPublishTask.groovy

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ abstract class PactPublishTask extends DefaultTask {
7070

7171
def publishConfig = new PublishConfiguration(version.toString(), pactPublish.tags, pactPublish.consumerBranch,
7272
pactPublish.consumerBuildUrl)
73-
def brokerClient = new PactBrokerClient(brokerConfig.pactBrokerUrl, options, new PactBrokerClientConfig())
73+
74+
PactBrokerClientConfig brokerClientConfig = configureBrokerClient(pactPublish, broker)
75+
def brokerClient = new PactBrokerClient(brokerConfig.pactBrokerUrl, options, brokerClientConfig)
7476

7577
File pactDirectory = pactPublish.pactDirectory as File
7678
boolean anyFailed = false
@@ -102,6 +104,16 @@ abstract class PactPublishTask extends DefaultTask {
102104
}
103105
}
104106

107+
private static PactBrokerClientConfig configureBrokerClient(PactPublish pactPublish, Broker broker) {
108+
def brokerClientConfig = new PactBrokerClientConfig()
109+
if (pactPublish.pactBrokerInsecureTLS != null) {
110+
brokerClientConfig.insecureTLS = pactPublish.pactBrokerInsecureTLS
111+
} else if (broker?.pactBrokerInsecureTLS != null) {
112+
brokerClientConfig.insecureTLS = broker.pactBrokerInsecureTLS
113+
}
114+
brokerClientConfig
115+
}
116+
105117
static boolean pactFileIsExcluded(PactPublish pactPublish, File pactFile) {
106118
pactPublish.excludes.any {
107119
FilenameUtils.getBaseName(pactFile.name) ==~ it

provider/gradle/src/main/kotlin/au/com/dius/pact/provider/gradle/Broker.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@ data class Broker(
1313
var pactBrokerAuthenticationScheme: String? = null,
1414
var pactBrokerAuthenticationHeader: String = Auth.DEFAULT_AUTH_HEADER,
1515
var retryCountWhileUnknown: Int? = null,
16-
var retryWhileUnknownInterval: Int? = null
16+
var retryWhileUnknownInterval: Int? = null,
17+
var pactBrokerInsecureTLS: Boolean? = null
1718
) {
1819
override fun toString(): String {
1920
val password = if (pactBrokerPassword != null) "".padEnd(pactBrokerPassword!!.length, '*') else null
2021
return "Broker(pactBrokerUrl=$pactBrokerUrl, pactBrokerToken=$pactBrokerToken, " +
2122
"pactBrokerUsername=$pactBrokerUsername, pactBrokerPassword=$password, " +
2223
"pactBrokerAuthenticationScheme=$pactBrokerAuthenticationScheme, " +
2324
"pactBrokerAuthenticationHeader=$pactBrokerAuthenticationHeader, " +
24-
"retryCountWhileUnknown=$retryCountWhileUnknown, retryWhileUnknownInterval=$retryWhileUnknownInterval)"
25+
"pactBrokerInsecureTLS=$pactBrokerInsecureTLS, " +
26+
"retryCountWhileUnknown=$retryCountWhileUnknown, " +
27+
"retryWhileUnknownInterval=$retryWhileUnknownInterval)"
2528
}
2629
}

provider/gradle/src/main/kotlin/au/com/dius/pact/provider/gradle/PactPublish.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,19 @@ data class PactPublish @JvmOverloads constructor(
1717
var tags: List<String> = listOf(),
1818
var excludes: List<String> = listOf(),
1919
var consumerBranch: String? = null,
20-
var consumerBuildUrl: String? = null
20+
var consumerBuildUrl: String? = null,
21+
var pactBrokerInsecureTLS: Boolean? = null
2122
) {
2223
override fun toString(): String {
2324
val password = if (pactBrokerPassword != null) "".padEnd(pactBrokerPassword!!.length, '*') else null
2425
return "PactPublish(pactDirectory=$pactDirectory, pactBrokerUrl=$pactBrokerUrl, " +
2526
"consumerVersion=$consumerVersion, pactBrokerToken=$pactBrokerToken, " +
2627
"pactBrokerUsername=$pactBrokerUsername, pactBrokerPassword=$password, " +
2728
"pactBrokerAuthenticationScheme=$pactBrokerAuthenticationScheme, " +
28-
"pactBrokerAuthenticationHeader=$pactBrokerAuthenticationHeader, tags=$tags, excludes=$excludes, " +
29+
"pactBrokerAuthenticationHeader=$pactBrokerAuthenticationHeader, " +
30+
"pactBrokerInsecureTLS=$pactBrokerInsecureTLS, " +
31+
"tags=$tags, " +
32+
"excludes=$excludes, " +
2933
"consumerBranch=$consumerBranch, consumerBuildUrl=$consumerBuildUrl)"
3034
}
3135
}

provider/gradle/src/test/groovy/au/com/dius/pact/provider/gradle/PactPublishTaskSpec.groovy

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,44 @@ class PactPublishTaskSpec extends Specification {
191191
then:
192192
1 * brokerClient.uploadPactFile(_, new PublishConfiguration('1.2.3')) >> new Result.Ok(null)
193193
}
194+
195+
def 'allows insecure TLS to be set'() {
196+
given:
197+
project.pact {
198+
publish {
199+
pactBrokerToken = 'token1234'
200+
pactBrokerUrl = 'pactBrokerUrl'
201+
pactBrokerInsecureTLS = true
202+
}
203+
}
204+
project.evaluate()
205+
206+
when:
207+
project.tasks.pactPublish.publishPacts()
208+
209+
then:
210+
1 * new PactBrokerClient(_, _, { it.insecureTLS == true }) >> brokerClient
211+
1 * brokerClient.uploadPactFile(_, _) >> new Result.Ok(null)
212+
}
213+
214+
def 'allows insecure TLS to be set on the broker block'() {
215+
given:
216+
project.pact {
217+
broker {
218+
pactBrokerInsecureTLS = true
219+
}
220+
publish {
221+
pactBrokerToken = 'token1234'
222+
pactBrokerUrl = 'pactBrokerUrl'
223+
}
224+
}
225+
project.evaluate()
226+
227+
when:
228+
project.tasks.pactPublish.publishPacts()
229+
230+
then:
231+
1 * new PactBrokerClient(_, _, { it.insecureTLS == true }) >> brokerClient
232+
1 * brokerClient.uploadPactFile(_, _) >> new Result.Ok(null)
233+
}
194234
}

0 commit comments

Comments
 (0)