From 264537df3419fe339bbdd009655a80048b023e59 Mon Sep 17 00:00:00 2001 From: pmaytak <34331512+pmaytak@users.noreply.github.com> Date: Fri, 5 Nov 2021 14:02:32 -0700 Subject: [PATCH] Fix merge issues. --- .../TestConstants.cs | 1 + .../HeadlessTests/OboTests2.cs | 4 ++-- .../CacheTests/CacheKeyFactoryTests.cs | 6 +++--- ...emoryPartitionedTokenCacheAccessorTests.cs | 1 + .../CacheTests/TokenCacheTests.cs | 19 +++++-------------- .../PublicApiTests/OBOTests.cs | 11 +---------- tests/devapps/NetFxConsoleTestApp/Program.cs | 2 +- 7 files changed, 14 insertions(+), 30 deletions(-) diff --git a/tests/Microsoft.Identity.Test.Common/TestConstants.cs b/tests/Microsoft.Identity.Test.Common/TestConstants.cs index 99b0d9963c..7b57fdda2d 100644 --- a/tests/Microsoft.Identity.Test.Common/TestConstants.cs +++ b/tests/Microsoft.Identity.Test.Common/TestConstants.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System; using System.Collections.Generic; using System.Globalization; using System.Text.RegularExpressions; diff --git a/tests/Microsoft.Identity.Test.Integration.netfx/HeadlessTests/OboTests2.cs b/tests/Microsoft.Identity.Test.Integration.netfx/HeadlessTests/OboTests2.cs index 8e01d11cec..80663f2a0f 100644 --- a/tests/Microsoft.Identity.Test.Integration.netfx/HeadlessTests/OboTests2.cs +++ b/tests/Microsoft.Identity.Test.Integration.netfx/HeadlessTests/OboTests2.cs @@ -43,7 +43,7 @@ public class OboTests2 private static readonly string[] s_publicCloudOBOServiceScope = { "api://23c64cd8-21e4-41dd-9756-ab9e2c23f58c/access_as_user" }; private static readonly string[] s_arlingtonOBOServiceScope = { "https://arlmsidlab1.us/IDLABS_APP_Confidential_Client/user_impersonation" }; - //TODO: acquire scenario specific client ids from the lab resonse + //TODO: acquire scenario specific client ids from the lab response private const string PublicCloudPublicClientIDOBO = "be9b0186-7dfd-448a-a944-f771029105bf"; private const string PublicCloudConfidentialClientIDOBO = "23c64cd8-21e4-41dd-9756-ab9e2c23f58c"; private const string ArlingtonConfidentialClientIDOBO = "c0555d2d-02f2-4838-802e-3463422e571d"; @@ -63,7 +63,7 @@ public class OboTests2 [TestMethod] public async Task ClientCreds_ServicePrincipal_OBO_PPE_Async() { - //An explination of the OBO for service principal scenario can be found here https://aadwiki.windows-int.net/index.php?title=App_OBO_aka._Service_Principal_OBO + //An explanation of the OBO for service principal scenario can be found here https://aadwiki.windows-int.net/index.php?title=App_OBO_aka._Service_Principal_OBO X509Certificate2 cert = GetCertificate(); IReadOnlyList scopes = new List() { OBOServicePpeClientID + "/.default" }; IReadOnlyList scopes2 = new List() { OBOServiceDownStreamApiPpeClientID + "/.default" }; diff --git a/tests/Microsoft.Identity.Test.Unit/CacheTests/CacheKeyFactoryTests.cs b/tests/Microsoft.Identity.Test.Unit/CacheTests/CacheKeyFactoryTests.cs index 418a88a9ed..d6cc7e5390 100644 --- a/tests/Microsoft.Identity.Test.Unit/CacheTests/CacheKeyFactoryTests.cs +++ b/tests/Microsoft.Identity.Test.Unit/CacheTests/CacheKeyFactoryTests.cs @@ -137,7 +137,7 @@ public void PartitionKeyForCache() Assert.AreEqual(acc.HomeAccountId, CacheKeyFactory.GetKeyFromCachedItem(acc)); at = at.WithUserAssertion("at_hash"); - rt.UserAssertionHash = "rt_hash"; + rt.OboCacheKey = "rt_hash"; Assert.AreEqual("at_hash", CacheKeyFactory.GetKeyFromCachedItem(at)); Assert.AreEqual("rt_hash", CacheKeyFactory.GetKeyFromCachedItem(rt)); Assert.AreEqual(idt.HomeAccountId, CacheKeyFactory.GetKeyFromCachedItem(idt)); @@ -170,7 +170,7 @@ public void TestCacheKeyForObo() }; // Act - var actualKey = SuggestedWebCacheKeyFactory.GetKeyFromRequest(parameters); + var actualKey = CacheKeyFactory.GetKeyFromRequest(parameters); // Assert Assert.IsNotNull(actualKey); @@ -204,7 +204,7 @@ public void TestCacheKeyForObo_WithCacheKey() }; // Act - var actualKey = SuggestedWebCacheKeyFactory.GetKeyFromRequest(parameters); + var actualKey = CacheKeyFactory.GetKeyFromRequest(parameters); // Assert Assert.IsNotNull(actualKey); diff --git a/tests/Microsoft.Identity.Test.Unit/CacheTests/InMemoryPartitionedTokenCacheAccessorTests.cs b/tests/Microsoft.Identity.Test.Unit/CacheTests/InMemoryPartitionedTokenCacheAccessorTests.cs index ef4e71316b..215e8c8799 100644 --- a/tests/Microsoft.Identity.Test.Unit/CacheTests/InMemoryPartitionedTokenCacheAccessorTests.cs +++ b/tests/Microsoft.Identity.Test.Unit/CacheTests/InMemoryPartitionedTokenCacheAccessorTests.cs @@ -604,6 +604,7 @@ private ConcurrentDictionary GetAppMetadataCache(ITokenCacheAccessor accessor, bool isAppCache) { if (isAppCache) diff --git a/tests/Microsoft.Identity.Test.Unit/CacheTests/TokenCacheTests.cs b/tests/Microsoft.Identity.Test.Unit/CacheTests/TokenCacheTests.cs index eaa54914c5..012b1258bd 100644 --- a/tests/Microsoft.Identity.Test.Unit/CacheTests/TokenCacheTests.cs +++ b/tests/Microsoft.Identity.Test.Unit/CacheTests/TokenCacheTests.cs @@ -680,7 +680,7 @@ public void GetAccessAndRefreshTokenUserAssertionMismatchInCacheTest() string rtKey = rtItem.GetKey().ToString(); rtItem.Secret = rtKey; - rtItem.OboCacheKey = harness.ServiceBundle.PlatformProxy.CryptographyManager.CreateBase64UrlEncodedSha256Hash(atKey); + rtItem.OboCacheKey = assertion; cache.Accessor.SaveRefreshToken(rtItem); var authParams = harness.CreateAuthenticationRequestParameters( @@ -693,7 +693,7 @@ public void GetAccessAndRefreshTokenUserAssertionMismatchInCacheTest() var itemAT = cache.FindAccessTokenAsync(authParams).Result; var itemRT = cache.FindRefreshTokenAsync(authParams).Result; - // cache lookup should fail because there was userassertion hash did not match the one + // cache lookup should fail because there was user assertion hash did not match the one // stored in token cache item. Assert.IsNull(itemAT); Assert.IsNull(itemRT); @@ -718,15 +718,8 @@ public void GetAccessAndRefreshTokenMatchedUserAssertionInCacheTest() new DateTimeOffset(DateTime.UtcNow + TimeSpan.FromHours(1)), new DateTimeOffset(DateTime.UtcNow + TimeSpan.FromHours(2)), _clientInfo, - _homeAccountId); - - // create key out of access token cache item and then - // set it as the value of the access token. - string atKey = atItem.GetKey().ToString(); - atItem.Secret = atKey; - atItem.OboCacheKey = harness.ServiceBundle.PlatformProxy.CryptographyManager.CreateBase64UrlEncodedSha256Hash(atKey); _homeAccountId, - userAssertionHash: assertionHash); + oboCacheKey: assertionHash); cache.Accessor.SaveAccessToken(atItem); @@ -738,9 +731,7 @@ public void GetAccessAndRefreshTokenMatchedUserAssertionInCacheTest() null, _homeAccountId); - string rtKey = rtItem.GetKey().ToString(); - rtItem.Secret = rtKey; - rtItem.OboCacheKey = harness.ServiceBundle.PlatformProxy.CryptographyManager.CreateBase64UrlEncodedSha256Hash(atKey); + rtItem.OboCacheKey = assertionHash; cache.Accessor.SaveRefreshToken(rtItem); var authParams = harness.CreateAuthenticationRequestParameters( @@ -749,7 +740,7 @@ public void GetAccessAndRefreshTokenMatchedUserAssertionInCacheTest() cache, apiId: ApiEvent.ApiIds.AcquireTokenOnBehalfOf, account: new Account(_homeAccountId, null, TestConstants.ProductionPrefNetworkEnvironment)); - authParams.UserAssertion = new UserAssertion(atKey); + authParams.UserAssertion = new UserAssertion("T"); ((TokenCache)cache).AfterAccess = AfterAccessNoChangeNotification; var itemAT = cache.FindAccessTokenAsync(authParams).Result; diff --git a/tests/Microsoft.Identity.Test.Unit/PublicApiTests/OBOTests.cs b/tests/Microsoft.Identity.Test.Unit/PublicApiTests/OBOTests.cs index 26373d4371..cec00c18ef 100644 --- a/tests/Microsoft.Identity.Test.Unit/PublicApiTests/OBOTests.cs +++ b/tests/Microsoft.Identity.Test.Unit/PublicApiTests/OBOTests.cs @@ -74,16 +74,7 @@ private static IConfidentialClientApplication CreatePcaFromFileWithAuthority( var cca = ccaBuilder.BuildConcrete(); cca.InitializeTokenCacheFromFile(ResourceHelper.GetTestResourceRelativePath(tokenCacheFile), true); - cca.UserTokenCacheInternal.Accessor.AssertItemCount(3, 2, 3, 3, 1); - foreach (var at in cca.UserTokenCacheInternal.Accessor.GetAllAccessTokens()) - { - at.OboCacheKey = "_JPLB-GtkomFJxAOWKHPHR5_ZemiZqb4fzyE_rVBx7M"; // the hash of "jwt" - } - - cca.UserTokenCacheInternal.Accessor.DeleteAccessToken( - cca.UserTokenCacheInternal.Accessor.GetAllAccessTokens().Single( - at => at.HomeAccountId == "ae821e4d-f408-451a-af82-882691148603.49f548d0-12b7-4169-a390-bb5304d24462").GetKey()); - + cca.UserTokenCacheInternal.Accessor.AssertItemCount(2, 2, 3, 3, 1); return cca; } } diff --git a/tests/devapps/NetFxConsoleTestApp/Program.cs b/tests/devapps/NetFxConsoleTestApp/Program.cs index 7ba8594afc..57a64a5a75 100644 --- a/tests/devapps/NetFxConsoleTestApp/Program.cs +++ b/tests/devapps/NetFxConsoleTestApp/Program.cs @@ -460,7 +460,7 @@ x. Exit app atItem.KeyId, atItem.RefreshOn, atItem.TokenType, - atItem.UserAssertionHash); + atItem.OboCacheKey); tokenCacheInternal.Accessor.SaveAccessToken(newAtItem); }