@@ -2157,6 +2157,8 @@ public void ConfidentialClient_WithInvalidAuthority_ThrowsArgumentException()
21572157 [ TestMethod ]
21582158 public async Task WithAccessTokenSha256ToRefresh_MatchingHash_GetsTokenFromIdp_Async ( )
21592159 {
2160+ const string accessToken = "access-token" ;
2161+
21602162 // Arrange
21612163 using ( var httpManager = new MockHttpManager ( ) )
21622164 {
@@ -2170,19 +2172,19 @@ public async Task WithAccessTokenSha256ToRefresh_MatchingHash_GetsTokenFromIdp_A
21702172 . BuildConcrete ( ) ;
21712173
21722174 // 1) First network call: populates the cache with "access-token"
2173- httpManager . AddMockHandlerSuccessfulClientCredentialTokenResponseMessage ( token : "access-token" ) ;
2175+ httpManager . AddMockHandlerSuccessfulClientCredentialTokenResponseMessage ( token : accessToken ) ;
21742176 AuthenticationResult initialResult = await app . AcquireTokenForClient ( TestConstants . s_scope ) . ExecuteAsync ( ) . ConfigureAwait ( false ) ;
21752177
2176- Assert . AreEqual ( "access-token" , initialResult . AccessToken ) ;
2178+ Assert . AreEqual ( accessToken , initialResult . AccessToken ) ;
21772179 Assert . AreEqual ( TokenSource . IdentityProvider , initialResult . AuthenticationResultMetadata . TokenSource ) ;
21782180
21792181 // 2) Second call: re-check the cache. Should see the same token from cache
21802182 AuthenticationResult secondResult = await app . AcquireTokenForClient ( TestConstants . s_scope ) . ExecuteAsync ( ) . ConfigureAwait ( false ) ;
2181- Assert . AreEqual ( "access-token" , secondResult . AccessToken ) ;
2183+ Assert . AreEqual ( accessToken , secondResult . AccessToken ) ;
21822184 Assert . AreEqual ( TokenSource . Cache , secondResult . AuthenticationResultMetadata . TokenSource ) ;
21832185
21842186 // 3) Now specify the same token's hash as "bad" => expect a new token from IdP
2185- string tokenHash = ComputeSHA256 ( "access-token" ) ;
2187+ string tokenHash = ComputeSHA256 ( accessToken ) ;
21862188
21872189 // Add another network response to simulate fetching a new token
21882190 httpManager . AddMockHandlerSuccessfulClientCredentialTokenResponseMessage ( token : "new-access-token" ) ;
@@ -2263,6 +2265,9 @@ public async Task ForceRefreshAndAccessTokenHash_ThrowsException_Async()
22632265 [ TestMethod ]
22642266 public async Task AcquireTokenForClient_WithClaims_And_MatchingHash_SkipsCache_Async ( )
22652267 {
2268+ const string oldToken = "old-token" ;
2269+ const string freshToken = "fresh-token" ;
2270+
22662271 using ( var httpManager = new MockHttpManager ( ) )
22672272 {
22682273 httpManager . AddInstanceDiscoveryMockHandler ( ) ;
@@ -2275,16 +2280,16 @@ public async Task AcquireTokenForClient_WithClaims_And_MatchingHash_SkipsCache_A
22752280 . WithExperimentalFeatures ( true )
22762281 . BuildConcrete ( ) ;
22772282
2278- httpManager . AddMockHandlerSuccessfulClientCredentialTokenResponseMessage ( token : "old-token" ) ;
2283+ httpManager . AddMockHandlerSuccessfulClientCredentialTokenResponseMessage ( token : oldToken ) ;
22792284 AuthenticationResult firstResult = await app . AcquireTokenForClient ( TestConstants . s_scope ) . ExecuteAsync ( ) . ConfigureAwait ( false ) ;
22802285
2281- Assert . AreEqual ( "old-token" , firstResult . AccessToken ) ;
2286+ Assert . AreEqual ( oldToken , firstResult . AccessToken ) ;
22822287
22832288 // 2) We do matching hash => a new token is returned
2284- string tokenHash = ComputeSHA256 ( "old-token" ) ;
2289+ string tokenHash = ComputeSHA256 ( oldToken ) ;
22852290
22862291 // Add second network response for the new token
2287- httpManager . AddMockHandlerSuccessfulClientCredentialTokenResponseMessage ( token : "fresh-token" ) ;
2292+ httpManager . AddMockHandlerSuccessfulClientCredentialTokenResponseMessage ( token : freshToken ) ;
22882293
22892294 // Act
22902295 AuthenticationResult result = await app . AcquireTokenForClient ( TestConstants . s_scope )
@@ -2294,14 +2299,16 @@ public async Task AcquireTokenForClient_WithClaims_And_MatchingHash_SkipsCache_A
22942299 . ConfigureAwait ( false ) ;
22952300
22962301 // Assert => new token from the IDP
2297- Assert . AreEqual ( "fresh-token" , result . AccessToken ) ;
2302+ Assert . AreEqual ( freshToken , result . AccessToken ) ;
22982303 Assert . AreEqual ( TokenSource . IdentityProvider , result . AuthenticationResultMetadata . TokenSource ) ;
22992304 }
23002305 }
23012306
23022307 [ TestMethod ]
23032308 public async Task AcquireTokenForClient_WithClaims_And_MismatchedHash_UsesCache_Async ( )
23042309 {
2310+ const string cacheToken = "cache-token" ;
2311+
23052312 using ( var httpManager = new MockHttpManager ( ) )
23062313 {
23072314 httpManager . AddInstanceDiscoveryMockHandler ( ) ;
@@ -2315,13 +2322,13 @@ public async Task AcquireTokenForClient_WithClaims_And_MismatchedHash_UsesCache_
23152322 . BuildConcrete ( ) ;
23162323
23172324 // First network call: populates the cache with "cache-token"
2318- httpManager . AddMockHandlerSuccessfulClientCredentialTokenResponseMessage ( token : "cache-token" ) ;
2325+ httpManager . AddMockHandlerSuccessfulClientCredentialTokenResponseMessage ( token : cacheToken ) ;
23192326
23202327 var initialResult = await app . AcquireTokenForClient ( TestConstants . s_scope )
23212328 . ExecuteAsync ( )
23222329 . ConfigureAwait ( false ) ;
23232330
2324- Assert . AreEqual ( "cache-token" , initialResult . AccessToken ) ;
2331+ Assert . AreEqual ( cacheToken , initialResult . AccessToken ) ;
23252332 Assert . AreEqual ( TokenSource . IdentityProvider , initialResult . AuthenticationResultMetadata . TokenSource ) ;
23262333
23272334 // 2) We'll do a mismatched hash => expect to keep using the cached token
@@ -2335,7 +2342,7 @@ public async Task AcquireTokenForClient_WithClaims_And_MismatchedHash_UsesCache_
23352342 . ConfigureAwait ( false ) ;
23362343
23372344 // Assert => we keep using the cached token
2338- Assert . AreEqual ( "cache-token" , result . AccessToken ,
2345+ Assert . AreEqual ( cacheToken , result . AccessToken ,
23392346 "We reuse the cache if the hash does not match the 'bad' token’s hash." ) ;
23402347 Assert . AreEqual ( TokenSource . Cache , result . AuthenticationResultMetadata . TokenSource ) ;
23412348 }
0 commit comments