Skip to content

Commit

Permalink
Merge branch 'v4.1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald Holshausen committed Aug 24, 2021
2 parents a6be37e + 04d9117 commit b462966
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>))
} else {
consumers.add(PactBrokerResult(name, href, pactBrokerUrl))
}
consumers.add(PactBrokerResult(name, href, pactBrokerUrl))
})
consumers
} catch (e: NotFoundHalResponse) {
Expand All @@ -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<String>, 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) {
Expand Down Expand Up @@ -305,13 +297,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<String>, 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)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ data class PactBrokerResult(
val name: String,
val source: String,
val pactBrokerUrl: String,
@Deprecated("pactFileAuthentication is not used")
val pactFileAuthentication: List<String> = listOf(),
val notices: List<VerificationNotice> = listOf(),
val pending: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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'() {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b462966

Please sign in to comment.