-
Notifications
You must be signed in to change notification settings - Fork 459
Expand file tree
/
Copy pathHttpRequestDataTests.cs
More file actions
54 lines (43 loc) · 1.85 KB
/
HttpRequestDataTests.cs
File metadata and controls
54 lines (43 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Security.Cryptography.X509Certificates;
using Microsoft.IdentityModel.TestUtils;
using Xunit;
namespace Microsoft.IdentityModel.Protocols.Tests
{
public class HttpRequestDataTests
{
[Fact]
public void ClientCertificates()
{
var httpRequestData = new HttpRequestData();
Assert.NotNull(httpRequestData.ClientCertificates);
Assert.Empty(httpRequestData.ClientCertificates);
X509Certificate2 cert = TestUtils.CertificateHelper.LoadX509Certificate(KeyingMaterial.AADCertData);
httpRequestData.ClientCertificates.Add(cert);
Assert.Single(httpRequestData.ClientCertificates);
Assert.Equal(cert, httpRequestData.ClientCertificates[0]);
}
[Fact]
public void LazyClientCertificates()
{
var httpRequestData = new HttpRequestData();
Assert.NotNull(httpRequestData.ClientCertificates);
Assert.Empty(httpRequestData.ClientCertificates);
X509Certificate2 cert = TestUtils.CertificateHelper.LoadX509Certificate(KeyingMaterial.AADCertData);
int numberCertsPopulatedCalled = 0;
httpRequestData.SetLazyClientCertificates((c) =>
{
numberCertsPopulatedCalled++;
c.Add(cert);
});
Assert.Equal(0, numberCertsPopulatedCalled);
Assert.Single(httpRequestData.ClientCertificates);
Assert.Equal(cert, httpRequestData.ClientCertificates[0]);
Assert.Equal(1, numberCertsPopulatedCalled);
// Invoke again, should not call the delegate again
_ = httpRequestData.ClientCertificates;
Assert.Equal(1, numberCertsPopulatedCalled);
}
}
}