Skip to content

Commit a6d043d

Browse files
author
Neil Campbell
committed
Updating to the latest standalone core version
1 parent 981b600 commit a6d043d

File tree

6 files changed

+97
-11
lines changed

6 files changed

+97
-11
lines changed

Build/Download-Standalone-Core.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ New-Item -ItemType directory -Path $OutputPath | Out-Null
2626

2727
Import-Module -Name $7ZipSnapIn
2828

29-
$StandaloneCoreVersion = '1.61.2'
29+
$StandaloneCoreVersion = '1.66.0'
3030
$StandaloneCoreDownloadBaseUri = "https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v$StandaloneCoreVersion"
3131

3232
# Download and extract the Windows core

PactNet.Tests/Core/PactVerifierHostConfigTests.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void Ctor_WhenCalledWithAHttpPactUri_SetsTheCorrectArgs()
5555
}
5656

5757
[Fact]
58-
public void Ctor_WhenCalledWithAAuthenticatedHttpsPactUri_SetsTheCorrectArgs()
58+
public void Ctor_WhenCalledWithABasicAuthenticatedHttpsPactUri_SetsTheCorrectArgs()
5959
{
6060
var baseUri = new Uri("http://127.0.0.1");
6161
var pactUri = "https://broker:9292/test";
@@ -69,6 +69,21 @@ public void Ctor_WhenCalledWithAAuthenticatedHttpsPactUri_SetsTheCorrectArgs()
6969
Assert.Equal(expectedArguments, config.Arguments);
7070
}
7171

72+
[Fact]
73+
public void Ctor_WhenCalledWithATokenAuthenticatedHttpsPactUri_SetsTheCorrectArgs()
74+
{
75+
var baseUri = new Uri("http://127.0.0.1");
76+
var pactUri = "https://broker:9292/test";
77+
var pactUriOptions = new PactUriOptions("token");
78+
var providerStateSetupUri = new Uri("http://127.0.0.1/states/");
79+
80+
var config = GetSubject(baseUri, pactUri, pactUriOptions, providerStateSetupUri);
81+
82+
var expectedArguments = BuildExpectedArguments(baseUri, pactUri, providerStateSetupUri, pactUriOptions);
83+
84+
Assert.Equal(expectedArguments, config.Arguments);
85+
}
86+
7287
[Fact]
7388
public void Ctor_WhenCalledWithNoProviderStateSetupUri_SetsTheCorrectArgs()
7489
{
@@ -233,7 +248,11 @@ private string BuildExpectedArguments(
233248
bool verbose = false)
234249
{
235250
var providerStateOption = providerStateSetupUri != null ? $" --provider-states-setup-url {providerStateSetupUri.OriginalString}" : "";
236-
var brokerCredentials = pactUriOptions != null ? $" --broker-username \"{pactUriOptions.Username}\" --broker-password \"{pactUriOptions.Password}\"" : "";
251+
var brokerCredentials = pactUriOptions != null ?
252+
!String.IsNullOrEmpty(pactUriOptions.Username) && !String.IsNullOrEmpty(pactUriOptions.Password) ?
253+
$" --broker-username \"{pactUriOptions.Username}\" --broker-password \"{pactUriOptions.Password}\"" :
254+
$" --broker-token \"{pactUriOptions.Token}\""
255+
: string.Empty;
237256
var publishResults = publishVerificationResults ? $" --publish-verification-results=true --provider-app-version=\"{providerVersion}\"" : string.Empty;
238257
var customProviderHeader = customHeader != null ?
239258
$" --custom-provider-header \"{customHeader.Value.Key}:{customHeader.Value.Value}\"" :

PactNet.Tests/PactUriOptionsTests.cs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public void Ctor_WithValidUsernameAndPassword_ReturnsCorrectAuthorizationSchemeA
3737
{
3838
const string username = "Aladdin";
3939
const string password = "open sesame";
40-
var expectedAuthScheme = "Basic";
41-
var expectedAuthValue = "QWxhZGRpbjpvcGVuIHNlc2FtZQ==";
40+
const string expectedAuthScheme = "Basic";
41+
const string expectedAuthValue = "QWxhZGRpbjpvcGVuIHNlc2FtZQ==";
4242

4343
var options = new PactUriOptions(username, password);
4444

@@ -57,5 +57,36 @@ public void Ctor_WithValidUsernameAndPassword_ReturnsCorrectUsernameAndPassword(
5757
Assert.Equal(username, options.Username);
5858
Assert.Equal(password, options.Password);
5959
}
60+
61+
[Fact]
62+
public void Ctor_WithEmptyToken_ThrowsArgumentException()
63+
{
64+
const string token = "";
65+
66+
Assert.Throws<ArgumentException>(() => new PactUriOptions(token));
67+
}
68+
69+
[Fact]
70+
public void Ctor_WithValidToken_ReturnsCorrectAuthorizationSchemeAndValue()
71+
{
72+
const string token = "MyToken";
73+
const string expectedAuthScheme = "Bearer";
74+
const string expectedAuthValue = token;
75+
76+
var options = new PactUriOptions(token);
77+
78+
Assert.Equal(expectedAuthScheme, options.AuthorizationScheme);
79+
Assert.Equal(expectedAuthValue, options.AuthorizationValue);
80+
}
81+
82+
[Fact]
83+
public void Ctor_WithValidToken_ReturnsCorrectToken()
84+
{
85+
const string token = "MyToken";
86+
87+
var options = new PactUriOptions(token);
88+
89+
Assert.Equal(token, options.Token);
90+
}
6091
}
6192
}

PactNet.Tests/PactVerifierTests.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public void Verify_WhenTheVerifierIsCorrectlySetUpWithAHttpPactFile_PactVerifyCo
248248
}
249249

250250
[Fact]
251-
public void Verify_WhenTheVerifierIsCorrectlySetUpWithAHttpsPactFileWithCredentials_PactVerifyCoreHostIsStarted()
251+
public void Verify_WhenTheVerifierIsCorrectlySetUpWithAHttpsPactFileWithBasicAuthCredentials_PactVerifyCoreHostIsStarted()
252252
{
253253
var serviceProvider = "Event API";
254254
var serviceConsumer = "My client";
@@ -265,5 +265,24 @@ public void Verify_WhenTheVerifierIsCorrectlySetUpWithAHttpsPactFileWithCredenti
265265

266266
_mockVerifierCoreHost.Received(1).Start();
267267
}
268+
269+
[Fact]
270+
public void Verify_WhenTheVerifierIsCorrectlySetUpWithAHttpsPactFileWitTokenAuthCredentials_PactVerifyCoreHostIsStarted()
271+
{
272+
var serviceProvider = "Event API";
273+
var serviceConsumer = "My client";
274+
var pactUri = "https://broker/consumer/test/provider/hello/latest";
275+
var pactUriOptions = new PactUriOptions("mytoken");
276+
277+
var pactVerifier = GetSubject();
278+
pactVerifier
279+
.ServiceProvider(serviceProvider, "http://localhost")
280+
.HonoursPactWith(serviceConsumer)
281+
.PactUri(pactUri, pactUriOptions);
282+
283+
pactVerifier.Verify();
284+
285+
_mockVerifierCoreHost.Received(1).Start();
286+
}
268287
}
269288
}

PactNet/Core/PactVerifierHostConfig.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ internal class PactVerifierHostConfig : IPactCoreHostConfig
1515
public PactVerifierHostConfig(Uri baseUri, string pactUri, PactUriOptions pactBrokerUriOptions, Uri providerStateSetupUri, PactVerifierConfig config, IDictionary<string, string> environment)
1616
{
1717
var providerStateOption = providerStateSetupUri != null ? $" --provider-states-setup-url {providerStateSetupUri.OriginalString}" : string.Empty;
18-
var brokerCredentials = pactBrokerUriOptions != null ? $" --broker-username \"{pactBrokerUriOptions.Username}\" --broker-password \"{pactBrokerUriOptions.Password}\"" : string.Empty;
18+
var brokerCredentials = pactBrokerUriOptions != null ?
19+
!String.IsNullOrEmpty(pactBrokerUriOptions.Username) && !String.IsNullOrEmpty(pactBrokerUriOptions.Password) ?
20+
$" --broker-username \"{pactBrokerUriOptions.Username}\" --broker-password \"{pactBrokerUriOptions.Password}\"" :
21+
$" --broker-token \"{pactBrokerUriOptions.Token}\""
22+
: string.Empty;
1923
var publishResults = config?.PublishVerificationResults == true ? $" --publish-verification-results=true --provider-app-version=\"{config.ProviderVersion}\"" : string.Empty;
2024
var customHeader = config?.CustomHeader != null && !string.IsNullOrEmpty(config.CustomHeader?.Key) && !string.IsNullOrEmpty(config.CustomHeader?.Value) ?
2125
$" --custom-provider-header \"{config.CustomHeader?.Key}:{config.CustomHeader?.Value}\"" :

PactNet/PactUriOptions.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ namespace PactNet
55
{
66
public class PactUriOptions
77
{
8-
private const string AuthScheme = "Basic";
9-
108
public string Username { get; }
119
public string Password { get; }
12-
public string AuthorizationScheme => AuthScheme;
13-
public string AuthorizationValue => Convert.ToBase64String(Encoding.UTF8.GetBytes($"{Username}:{Password}"));
10+
public string Token { get; }
11+
public string AuthorizationScheme { get; }
12+
public string AuthorizationValue { get; }
1413

1514
public PactUriOptions(string username, string password)
1615
{
@@ -31,6 +30,20 @@ public PactUriOptions(string username, string password)
3130

3231
Username = username;
3332
Password = password;
33+
AuthorizationScheme = "Basic";
34+
AuthorizationValue = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{Username}:{Password}"));
35+
}
36+
37+
public PactUriOptions(string token)
38+
{
39+
if (String.IsNullOrEmpty(token))
40+
{
41+
throw new ArgumentException("token is null or empty.");
42+
}
43+
44+
Token = token;
45+
AuthorizationScheme = "Bearer";
46+
AuthorizationValue = token;
3447
}
3548
}
3649
}

0 commit comments

Comments
 (0)