3
3
4
4
using System ;
5
5
using System . Security . Cryptography . X509Certificates ;
6
+ using System . Threading . Tasks ;
6
7
using Microsoft . Identity . Client ;
7
8
using Microsoft . Identity . Web . Test . Common ;
9
+ using Microsoft . Identity . Web . Test . Common . Mocks ;
8
10
using Xunit ;
9
11
10
12
namespace Microsoft . Identity . Web . Test
11
13
{
12
14
public class MsAuth10AtPopTests
13
15
{
14
16
[ Fact ]
15
- public void MsAuth10AtPop_WithAtPop_ShouldPopulateBuilderWithProofOfPosessionKeyIdAndOnBeforeTokenRequestTest ( )
17
+ public async Task MsAuth10AtPop_WithAtPop_ShouldPopulateBuilderWithProofOfPosessionKeyIdAndOnBeforeTokenRequestTestAsync ( )
16
18
{
17
19
// Arrange
18
- var builder = ConfidentialClientApplicationBuilder . Create ( TestConstants . ClientId ) ;
19
- builder . WithExperimentalFeatures ( ) ;
20
- builder . WithClientSecret ( TestConstants . ClientSecret ) ;
21
- var app = builder . Build ( ) ;
22
- var clientCertificate = new X509Certificate2 ( new byte [ 0 ] ) ;
20
+
21
+ MockHttpClientFactory mockHttpClientFactory = new MockHttpClientFactory ( ) ;
22
+ var tokenHandler = MockHttpCreator . CreateClientCredentialTokenHandler ( ) ;
23
+ mockHttpClientFactory . AddMockHandler ( MockHttpCreator . CreateInstanceDiscoveryMockHandler ( ) ) ;
24
+ mockHttpClientFactory . AddMockHandler ( tokenHandler ) ;
25
+
26
+ var certificateDescription = CertificateDescription . FromBase64Encoded (
27
+ TestConstants . CertificateX5cWithPrivateKey ,
28
+ TestConstants . CertificateX5cWithPrivateKeyPassword ) ;
29
+ ICertificateLoader loader = new DefaultCertificateLoader ( ) ;
30
+ loader . LoadIfNeeded ( certificateDescription ) ;
31
+
32
+ Assert . NotNull ( certificateDescription . Certificate ) ;
33
+
34
+ var app = ConfidentialClientApplicationBuilder . Create ( TestConstants . ClientId )
35
+ . WithExperimentalFeatures ( )
36
+ . WithCertificate ( certificateDescription . Certificate )
37
+ . WithHttpClientFactory ( mockHttpClientFactory )
38
+ . Build ( ) ;
39
+
40
+
23
41
var popPublicKey = "pop_key" ;
24
42
var jwkClaim = "jwk_claim" ;
25
43
var clientId = "client_id" ;
26
44
27
45
// Act
28
- var result = MsAuth10AtPop . WithAtPop ( app . AcquireTokenForClient ( new [ ] { TestConstants . Scopes } ) , clientCertificate , popPublicKey , jwkClaim , clientId ) ;
46
+ AuthenticationResult result = await app . AcquireTokenForClient ( new [ ] { TestConstants . Scopes } )
47
+ . WithAtPop ( certificateDescription . Certificate , popPublicKey , jwkClaim , clientId , true )
48
+ . ExecuteAsync ( ) ;
29
49
30
50
// Assert
31
51
Assert . NotNull ( result ) ;
@@ -41,7 +61,13 @@ public void MsAuth10AtPop_ThrowsWithNullPopKeyTest()
41
61
var clientId = "client_id" ;
42
62
43
63
// Act & Assert
44
- Assert . Throws < ArgumentNullException > ( ( ) => MsAuth10AtPop . WithAtPop ( app . AcquireTokenForClient ( new [ ] { TestConstants . Scopes } ) , clientCertificate , string . Empty , jwkClaim , clientId ) ) ;
64
+ Assert . Throws < ArgumentNullException > ( ( ) => MsAuth10AtPop . WithAtPop (
65
+ app . AcquireTokenForClient ( new [ ] { TestConstants . Scopes } ) ,
66
+ clientCertificate ,
67
+ string . Empty ,
68
+ jwkClaim ,
69
+ clientId ,
70
+ true ) ) ;
45
71
}
46
72
47
73
[ Fact ]
@@ -55,7 +81,9 @@ public void MsAuth10AtPop_ThrowsWithNullJwkClaimTest()
55
81
56
82
// Act & Assert
57
83
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
58
- Assert . Throws < ArgumentNullException > ( ( ) => MsAuth10AtPop . WithAtPop ( app . AcquireTokenForClient ( new [ ] { TestConstants . Scopes } ) , clientCertificate , popPublicKey , null , clientId ) ) ;
84
+ Assert . Throws < ArgumentNullException > ( ( ) => MsAuth10AtPop . WithAtPop (
85
+ app . AcquireTokenForClient ( new [ ] { TestConstants . Scopes } ) ,
86
+ clientCertificate , popPublicKey , null , clientId , true ) ) ;
59
87
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
60
88
}
61
89
0 commit comments