From 04d911779f17fd752fdb1769121ea57ead69106a Mon Sep 17 00:00:00 2001 From: Ronald Holshausen Date: Tue, 24 Aug 2021 11:39:38 +1000 Subject: [PATCH] fix: Illegal cast of au.com.dius.pact.core.support.Auth to List #1422 --- .../pact/core/pactbroker/PactBrokerClient.kt | 20 ++------ .../pact/core/pactbroker/PactBrokerResult.kt | 1 + .../pactbroker/PactBrokerClientSpec.groovy | 49 ++++++++++--------- 3 files changed, 30 insertions(+), 40 deletions(-) diff --git a/core/pactbroker/src/main/kotlin/au/com/dius/pact/core/pactbroker/PactBrokerClient.kt b/core/pactbroker/src/main/kotlin/au/com/dius/pact/core/pactbroker/PactBrokerClient.kt index 421f8efccc..1f10f6d7d2 100644 --- a/core/pactbroker/src/main/kotlin/au/com/dius/pact/core/pactbroker/PactBrokerClient.kt +++ b/core/pactbroker/src/main/kotlin/au/com/dius/pact/core/pactbroker/PactBrokerClient.kt @@ -193,11 +193,7 @@ open class PactBrokerClient( halClient.navigate(mapOf("provider" to provider), LATEST_PROVIDER_PACTS).forAll(PACTS, Consumer { pact -> val href = pact["href"].toString() val name = pact["name"].toString() - if (options.containsKey("authentication") && options["authentication"] is List<*>) { - consumers.add(PactBrokerResult(name, href, pactBrokerUrl, options["authentication"] as List)) - } else { - consumers.add(PactBrokerResult(name, href, pactBrokerUrl)) - } + consumers.add(PactBrokerResult(name, href, pactBrokerUrl)) }) consumers } catch (e: NotFoundHalResponse) { @@ -218,11 +214,7 @@ open class PactBrokerClient( .forAll(PACTS, Consumer { pact -> val href = pact["href"].toString() val name = pact["name"].toString() - if (options.containsKey("authentication") && options["authentication"] is List<*>) { - consumers.add(PactBrokerResult(name, href, pactBrokerUrl, options["authentication"] as List, tag = tag)) - } else { - consumers.add(PactBrokerResult(name, href, pactBrokerUrl, emptyList(), tag = tag)) - } + consumers.add(PactBrokerResult(name, href, pactBrokerUrl, emptyList(), tag = tag)) }) consumers } catch (e: NotFoundHalResponse) { @@ -304,13 +296,9 @@ open class PactBrokerClient( } val wip = if (properties.has("wip") && properties["wip"].isBoolean) properties["wip"].asBoolean() else false - if (options.containsKey("authentication")) { - PactBrokerResult(name, href, pactBrokerUrl, options["authentication"] as List, notices, pending, - wip = wip, usedNewEndpoint = true) - } else { - PactBrokerResult(name, href, pactBrokerUrl, emptyList(), notices, pending, wip = wip, + + PactBrokerResult(name, href, pactBrokerUrl, emptyList(), notices, pending, wip = wip, usedNewEndpoint = true) - } } } } diff --git a/core/pactbroker/src/main/kotlin/au/com/dius/pact/core/pactbroker/PactBrokerResult.kt b/core/pactbroker/src/main/kotlin/au/com/dius/pact/core/pactbroker/PactBrokerResult.kt index f1c4eccde5..447b216cf1 100644 --- a/core/pactbroker/src/main/kotlin/au/com/dius/pact/core/pactbroker/PactBrokerResult.kt +++ b/core/pactbroker/src/main/kotlin/au/com/dius/pact/core/pactbroker/PactBrokerResult.kt @@ -7,6 +7,7 @@ data class PactBrokerResult( val name: String, val source: String, val pactBrokerUrl: String, + @Deprecated("pactFileAuthentication is not used") val pactFileAuthentication: List = listOf(), val notices: List = listOf(), val pending: Boolean = false, diff --git a/core/pactbroker/src/test/groovy/au/com/dius/pact/core/pactbroker/PactBrokerClientSpec.groovy b/core/pactbroker/src/test/groovy/au/com/dius/pact/core/pactbroker/PactBrokerClientSpec.groovy index ef3510383c..39f168fcc0 100644 --- a/core/pactbroker/src/test/groovy/au/com/dius/pact/core/pactbroker/PactBrokerClientSpec.groovy +++ b/core/pactbroker/src/test/groovy/au/com/dius/pact/core/pactbroker/PactBrokerClientSpec.groovy @@ -1,5 +1,6 @@ package au.com.dius.pact.core.pactbroker +import au.com.dius.pact.core.support.Auth import au.com.dius.pact.core.support.Json import au.com.dius.pact.core.support.json.JsonParser import au.com.dius.pact.core.support.json.JsonValue @@ -37,7 +38,7 @@ class PactBrokerClientSpec extends Specification { pactFile.write pactContents } - def 'when fetching consumers, sets the auth if there is any'() { + def 'fetching consumers with the old auth format'() { given: def halClient = Mock(IHalClient) halClient.navigate() >> halClient @@ -51,13 +52,34 @@ class PactBrokerClientSpec extends Specification { } when: - def consumers = client.fetchConsumersWithSelectors('provider', [], [], false, '').value + def consumers = client.fetchConsumers('provider') + + then: + consumers != [] + consumers.first().name == 'bob' + consumers.first().source == 'http://bob.com/' + } + + def 'fetching consumers with the new auth format'() { + given: + def halClient = Mock(IHalClient) + halClient.navigate() >> halClient + halClient.navigate(_, _) >> halClient + halClient.forAll(_, _) >> { args -> args[1].accept([name: 'bob', href: 'http://bob.com/']) } + + PactBrokerClient client = Spy(PactBrokerClient, constructorArgs: [ + 'http://pactBrokerUrl', MapsKt.mapOf(new Pair('authentication', new Auth.BasicAuthentication('u', 'p'))), + new PactBrokerClientConfig()]) { + newHalClient() >> halClient + } + + when: + def consumers = client.fetchConsumers('provider') then: consumers != [] consumers.first().name == 'bob' consumers.first().source == 'http://bob.com/' - consumers.first().pactFileAuthentication == ['Basic', '1', '2'] } def 'when fetching consumers for an unknown provider, returns an empty pacts list'() { @@ -149,27 +171,6 @@ class PactBrokerClientSpec extends Specification { consumers.last().tag == 'anotherTag' } - def 'when fetching consumers with specified tag, sets the auth if there is any'() { - given: - def halClient = Mock(IHalClient) - halClient.navigate() >> halClient - halClient.navigate(_, _) >> halClient - halClient.forAll(_, _) >> { args -> args[1].accept([name: 'bob', href: 'http://bob.com/']) } - - PactBrokerClient client = Spy(PactBrokerClient, constructorArgs: [ - 'http://pactBrokerUrl', MapsKt.mapOf(new Pair('authentication', ['Basic', '1', '2'])), - new PactBrokerClientConfig()]) { - newHalClient() >> halClient - } - - when: - def consumers = client.fetchConsumersWithSelectors('provider', - [ new ConsumerVersionSelector('tag', true, null, null) ], [], false, '').value - - then: - consumers.first().pactFileAuthentication == ['Basic', '1', '2'] - } - def 'when fetching consumers with specified tag, does not decode the URLs to the pacts'() { given: def halClient = Mock(IHalClient)