Skip to content

Commit

Permalink
Fix merge issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmaytak committed Nov 5, 2021
1 parent 0235449 commit 264537d
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 30 deletions.
1 change: 1 addition & 0 deletions tests/Microsoft.Identity.Test.Common/TestConstants.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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<string> scopes = new List<string>() { OBOServicePpeClientID + "/.default" };
IReadOnlyList<string> scopes2 = new List<string>() { OBOServiceDownStreamApiPpeClientID + "/.default" };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -170,7 +170,7 @@ public void TestCacheKeyForObo()
};

// Act
var actualKey = SuggestedWebCacheKeyFactory.GetKeyFromRequest(parameters);
var actualKey = CacheKeyFactory.GetKeyFromRequest(parameters);

// Assert
Assert.IsNotNull(actualKey);
Expand Down Expand Up @@ -204,7 +204,7 @@ public void TestCacheKeyForObo_WithCacheKey()
};

// Act
var actualKey = SuggestedWebCacheKeyFactory.GetKeyFromRequest(parameters);
var actualKey = CacheKeyFactory.GetKeyFromRequest(parameters);

// Assert
Assert.IsNotNull(actualKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ private ConcurrentDictionary<string, ConcurrentDictionary<string, MsalAccessToke
return (accessor as InMemoryPartitionedUserTokenCacheAccessor)?.AccessTokenCacheDictionary;
}
}

private ConcurrentDictionary<string, MsalAppMetadataCacheItem> GetAppMetadataCache(ITokenCacheAccessor accessor, bool isAppCache)
{
if (isAppCache)
Expand Down
19 changes: 5 additions & 14 deletions tests/Microsoft.Identity.Test.Unit/CacheTests/TokenCacheTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
Expand All @@ -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);

Expand All @@ -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(
Expand All @@ -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;
Expand Down
11 changes: 1 addition & 10 deletions tests/Microsoft.Identity.Test.Unit/PublicApiTests/OBOTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/devapps/NetFxConsoleTestApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ x. Exit app
atItem.KeyId,
atItem.RefreshOn,
atItem.TokenType,
atItem.UserAssertionHash);
atItem.OboCacheKey);

tokenCacheInternal.Accessor.SaveAccessToken(newAtItem);
}
Expand Down

0 comments on commit 264537d

Please sign in to comment.