Skip to content

Commit 3a3a753

Browse files
authored
HTTP authentication with client certificate
1 parent 50ebd36 commit 3a3a753

File tree

12 files changed

+176
-61
lines changed

12 files changed

+176
-61
lines changed

.github/workflows/dotnet-core.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ jobs:
2424
uses: actions/setup-dotnet@v1
2525
with:
2626
dotnet-version: '5.0.x'
27+
- name: Clean
28+
run: dotnet clean --configuration Release && dotnet nuget locals all --clear
2729
- name: Install dependencies
28-
run: dotnet restore
30+
run: dotnet restore qatoolkit-engine-httptester-net.sln
2931
- name: Build
3032
run: dotnet build --configuration Release --no-restore
3133
- name: Test

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>0.3.0</Version>
3+
<Version>0.3.1</Version>
44
</PropertyGroup>
55
</Project>

Nuget.config

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageRestore>
4+
<add key="enabled" value="True" />
5+
</packageRestore>
6+
<packageManagement>
7+
<add key="format" value="1" />
8+
</packageManagement>
9+
<packageSources>
10+
<clear />
11+
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
12+
</packageSources>
13+
<activePackageSource>
14+
<add key="All" value="(Aggregate source)" />
15+
</activePackageSource>
16+
</configuration>

README.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ using (var client = new HttpTesterClient())
3030
.WithBearerAuthentication("eXy....")
3131
.Start();
3232

33-
var msg = await response.GetResponseBody<List<Bicycle>>();
33+
var msg = await response.GetResponseJsonBody<List<Bicycle>>();
3434

35-
var expecterResponse = BicycleFixture.GetBicycles().ToExpectedObject();
36-
expecterResponse.ShouldEqual(msg);
35+
var expectedResponse = BicycleFixture.GetBicycles().ToExpectedObject();
36+
expectedResponse.ShouldEqual(msg);
3737

3838
Assert.True(client.Duration < 2000); //Start() method execution duration
3939
Assert.True(client.HttpDuration < 2000); //HTTP request duration
@@ -64,10 +64,10 @@ using (var client = new HttpTesterClient())
6464
.WithBasicAuthentication("user", "pass")
6565
.Start();
6666

67-
var msg = await response.GetResponseBody<Bicycle>();
67+
var msg = await response.GetResponseJsonBody<Bicycle>();
6868

69-
var expecterResponse = bicycle.ToExpectedObject();
70-
expecterResponse.ShouldEqual(msg);
69+
var expectedResponse = bicycle.ToExpectedObject();
70+
expectedResponse.ShouldEqual(msg);
7171

7272
Assert.True(client.Duration < 2000);
7373
Assert.True(response.IsSuccessStatusCode);
@@ -196,6 +196,18 @@ Currently `HttpTesterClient` supports:
196196
.Start();
197197
```
198198

199+
##### Client certificate authentication
200+
201+
You can pass `X509Certificate2` objet to the `WithCertificateAuthentication` method from certificate store or file.
202+
203+
```csharp
204+
var response = await client
205+
.CreateHttpRequest(new Uri("https://qatoolkitapi.azurewebsites.net"))
206+
....
207+
.WithCertificateAuthentication(new X509Certificate2(...))
208+
.Start();
209+
```
210+
199211
### HttpTestAsserter
200212

201213
This is an implementation of the HTTP response message asserter, which can be used to assert different parameters.

src/QAToolKit.Engine.HttpTester.Test/Exceptions/QAToolKitEngineHttpTesterExceptionTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using QAToolKit.Engine.HttpTester.Exceptions;
22
using System;
3+
using System.Runtime.Serialization;
34
using Xunit;
45

56
namespace QAToolKit.Engine.HttpTester.Test.Exceptions

src/QAToolKit.Engine.HttpTester.Test/HttpTestAsserterTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public async Task HttpTestAsserterSimple_Success()
2525
.WithPath("/api/bicycles")
2626
.Start();
2727

28-
var msg = await response.GetResponseBody<List<Bicycle>>();
28+
var msg = await response.GetResponseJsonBody<List<Bicycle>>();
2929

3030
var asserter = new HttpTestAsserter(response);
3131

@@ -56,7 +56,7 @@ public async Task HttpTestAsserterDoesNotContainHeader_Success()
5656
.WithPath("/api/bicycles")
5757
.Start();
5858

59-
var msg = await response.GetResponseBody<List<Bicycle>>();
59+
var msg = await response.GetResponseJsonBody<List<Bicycle>>();
6060

6161
var asserter = new HttpTestAsserter(response);
6262

@@ -83,7 +83,7 @@ public async Task HttpTestAsserterDoesNotContainKeywordInBody_Success()
8383
.WithPath("/api/bicycles")
8484
.Start();
8585

86-
var msg = await response.GetResponseBody<List<Bicycle>>();
86+
var msg = await response.GetResponseJsonBody<List<Bicycle>>();
8787

8888
var asserter = new HttpTestAsserter(response);
8989

@@ -110,7 +110,7 @@ public async Task HttpTestAsserterHeaderMissing_Fails()
110110
.WithPath("/api/bicycles")
111111
.Start();
112112

113-
var msg = await response.GetResponseBody<List<Bicycle>>();
113+
var msg = await response.GetResponseJsonBody<List<Bicycle>>();
114114

115115
var asserter = new HttpTestAsserter(response);
116116

@@ -138,7 +138,7 @@ public async Task HttpTestAsserterBodyNull_Fails()
138138
.WithPath("/api/bicycles")
139139
.Start();
140140

141-
var msg = await response.GetResponseBody<List<Bicycle>>();
141+
var msg = await response.GetResponseJsonBody<List<Bicycle>>();
142142

143143
var asserter = new HttpTestAsserter(response);
144144

@@ -163,7 +163,7 @@ public async Task HttpTestAsserterAlternativeDurationPredicate_Success()
163163
.WithPath("/api/bicycles")
164164
.Start();
165165

166-
var msg = await response.GetResponseBody<List<Bicycle>>();
166+
var msg = await response.GetResponseJsonBody<List<Bicycle>>();
167167

168168
var asserter = new HttpTestAsserter(response);
169169
var duration = client.Duration;

0 commit comments

Comments
 (0)