-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Identity] Fix SharedTokenCacheCredential default behavior. (#28309)
* Fix SharedTokenCacheCredential default behavior * revert live test * revert inadvertant regional test update * adding stcc cache test * update API spec
- Loading branch information
Showing
8 changed files
with
127 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...ure.Identity.BrokeredAuthentication/tests/SharedTokenCacheCredentialBrokerOptionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using NUnit.Framework; | ||
|
||
namespace Azure.Identity.BrokeredAuthentication.Tests | ||
{ | ||
public class SharedTokenCacheCredentialBrokerOptionsTests | ||
{ | ||
[Test] | ||
public void VerifyTokenCacheOptionsCtorParam() | ||
{ | ||
// verify passed in TokenCachePeristenceOptions are honored | ||
var persistenceOptions = new TokenCachePersistenceOptions { Name = "mocktokencachename" }; | ||
|
||
var credentialOptions = new SharedTokenCacheCredentialBrokerOptions(persistenceOptions); | ||
|
||
Assert.AreEqual(persistenceOptions, credentialOptions.TokenCachePersistenceOptions); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace Azure.Identity.Tests.Mock | ||
{ | ||
public class MockTokenCache : UnsafeTokenCacheOptions | ||
{ | ||
private readonly Func<Task<ReadOnlyMemory<byte>>> _refreshCacheDelegate; | ||
private readonly Func<TokenCacheUpdatedArgs, Task> _cacheUpdatedDelegate; | ||
|
||
public MockTokenCache(Func<Task<ReadOnlyMemory<byte>>> refreshDelegate = default, Func<TokenCacheUpdatedArgs, Task> updatedDelegate = default) | ||
{ | ||
_refreshCacheDelegate = refreshDelegate; | ||
|
||
_cacheUpdatedDelegate = updatedDelegate; | ||
} | ||
|
||
protected internal override Task<ReadOnlyMemory<byte>> RefreshCacheAsync() | ||
{ | ||
return (_refreshCacheDelegate != null) ? _refreshCacheDelegate() : null; | ||
} | ||
|
||
protected internal override async Task TokenCacheUpdatedAsync(TokenCacheUpdatedArgs tokenCacheUpdatedArgs) | ||
{ | ||
if (_cacheUpdatedDelegate != null) | ||
{ | ||
await _cacheUpdatedDelegate(tokenCacheUpdatedArgs).ConfigureAwait(false); | ||
} | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
sdk/identity/Azure.Identity/tests/SharedTokenCacheCredentialOptionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using NUnit.Framework; | ||
|
||
namespace Azure.Identity.Tests | ||
{ | ||
public class SharedTokenCacheCredentialOptionsTests | ||
{ | ||
[Test] | ||
public void VerifyCachePersistenceOptionsCtorParam() | ||
{ | ||
// verify passed in TokenCachePeristenceOptions are honored | ||
var persistenceOptions = new TokenCachePersistenceOptions { Name = "mocktokencachename" }; | ||
|
||
var credentialOptions = new SharedTokenCacheCredentialOptions(persistenceOptions); | ||
|
||
Assert.AreEqual(persistenceOptions, credentialOptions.TokenCachePersistenceOptions); | ||
|
||
// verify passing null uses the default token cache persistence settings | ||
credentialOptions = new SharedTokenCacheCredentialOptions(null); | ||
|
||
Assert.AreEqual(SharedTokenCacheCredentialOptions.s_defaulTokenCachetPersistenceOptions, credentialOptions.TokenCachePersistenceOptions); | ||
|
||
// verify calling the default constructor uses the default token cache persistence settings | ||
credentialOptions = new SharedTokenCacheCredentialOptions(); | ||
|
||
Assert.AreEqual(SharedTokenCacheCredentialOptions.s_defaulTokenCachetPersistenceOptions, credentialOptions.TokenCachePersistenceOptions); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters