private static async Task <LabUserData> GetTempLabUserDataAsync() { var api = new LabServiceApi(); var labUser = (await api.CreateTempLabUserAsync().ConfigureAwait(false)).User; return(new LabUserData(labUser.Upn, labUser.GetOrFetchPassword())); }
private static async Task <LabUserData> GetLabUserDataAsync(string upn) { var api = new LabServiceApi(); var labUser = (await api.GetLabResponseAsync(new UserQuery()).ConfigureAwait(false)).User; return(new LabUserData(labUser.Upn, labUser.GetOrFetchPassword())); }
private static async Task <LabUserData> GetPublicAadUserDataAsync() { var api = new LabServiceApi(); LabResponse labResponse = (await api.GetLabResponseAsync(UserQuery.PublicAadUserQuery).ConfigureAwait(false)); return(new LabUserData( labResponse.User.Upn, labResponse.User.GetOrFetchPassword(), labResponse.User.AppId, labResponse.User.TenantId)); }
private static async Task <LabUserData> GetPublicAadUserDataAsync() { var api = new LabServiceApi(); LabResponse labResponse = (await api.GetLabResponseFromApiAsync(UserQuery.PublicAadUserQuery).ConfigureAwait(false)); return(new LabUserData( labResponse.User.Upn, labResponse.User.GetOrFetchPassword(), labResponse.User.AppId, labResponse.User.TenantId)); //return new LabUserData( // "user", // "", // "1d18b3b0-251b-4714-a02a-9956cec86c2d", // "49f548d0-12b7-4169-a390-bb5304d24462"); }
public async Task ExecuteAsync(CancellationToken cancellationToken) { LogExecution(); CommonCacheTestUtils.DeleteAllTestCaches(); CommonCacheTestUtils.EnsureCacheFileDirectoryExists(); var api = new LabServiceApi(); var labUser = api.GetLabResponse( new UserQuery { UserType = UserType.Member, IsFederatedUser = false }).User; Console.WriteLine($"Received LabUser: {labUser.Upn} from LabServiceApi."); var cacheProgramFirst = CacheProgramFactory.CreateCacheProgram(_firstProgram, _cacheStorageType); var cacheProgramSecond = CacheProgramFactory.CreateCacheProgram(_secondProgram, _cacheStorageType); var firstResults = await cacheProgramFirst.ExecuteAsync(labUser.Upn, labUser.GetOrFetchPassword(), cancellationToken).ConfigureAwait(false); var secondResults = await cacheProgramSecond.ExecuteAsync(labUser.Upn, labUser.GetOrFetchPassword(), cancellationToken).ConfigureAwait(false); Console.WriteLine(); Console.WriteLine("------------------------------------"); Console.WriteLine($"FirstResults: {_firstProgram}"); Console.WriteLine("stdout:"); Console.WriteLine(firstResults.StdOut); Console.WriteLine(); Console.WriteLine("stderr:"); Console.WriteLine(firstResults.StdErr); Console.WriteLine("------------------------------------"); Console.WriteLine($"SecondResults: {_secondProgram}"); Console.WriteLine("stdout:"); Console.WriteLine(secondResults.StdOut); Console.WriteLine("stderr:"); Console.WriteLine(secondResults.StdErr); Console.WriteLine("------------------------------------"); Console.WriteLine(); Assert.IsFalse(firstResults.ProcessExecutionFailed, $"{cacheProgramFirst.ExecutablePath} should not fail"); Assert.IsFalse(secondResults.ProcessExecutionFailed, $"{cacheProgramSecond.ExecutablePath} should not fail"); Assert.IsFalse(firstResults.ExecutionResults.ReceivedTokenFromCache, "First result should not be from the cache"); if (File.Exists(CommonCacheTestUtils.AdalV3CacheFilePath)) { Console.WriteLine($"Adal Cache Exists at: {CommonCacheTestUtils.AdalV3CacheFilePath}"); Console.WriteLine("Adal Cache Size: " + Convert.ToInt32(new FileInfo(CommonCacheTestUtils.AdalV3CacheFilePath).Length)); } else { Console.WriteLine($"Adal Cache DOES NOT EXIST at: {CommonCacheTestUtils.AdalV3CacheFilePath}"); } if (File.Exists(CommonCacheTestUtils.MsalV2CacheFilePath)) { Console.WriteLine($"MSAL V2 Cache Exists at: {CommonCacheTestUtils.MsalV2CacheFilePath}"); Console.WriteLine("MSAL V2 Cache Size: " + Convert.ToInt32(new FileInfo(CommonCacheTestUtils.MsalV2CacheFilePath).Length)); } else { Console.WriteLine($"MSAL V2 Cache DOES NOT EXIST at: {CommonCacheTestUtils.MsalV2CacheFilePath}"); } if (File.Exists(CommonCacheTestUtils.MsalV3CacheFilePath)) { Console.WriteLine($"MSAL V3 Cache Exists at: {CommonCacheTestUtils.MsalV3CacheFilePath}"); Console.WriteLine("MSAL V3 Cache Size: " + Convert.ToInt32(new FileInfo(CommonCacheTestUtils.MsalV3CacheFilePath).Length)); } else { Console.WriteLine($"MSAL V3 Cache DOES NOT EXIST at: {CommonCacheTestUtils.MsalV3CacheFilePath}"); } if (_expectSecondTokenFromCache) { Assert.IsTrue( secondResults.ExecutionResults.ReceivedTokenFromCache, "Second result should be from the cache"); } else { Assert.IsFalse( secondResults.ExecutionResults.ReceivedTokenFromCache, "Second result should NOT be from the cache"); } if (_expectSecondTokenException) { Assert.IsTrue( secondResults.ExecutionResults.IsError, "Second result should have thrown an exception"); } else { Assert.IsFalse( secondResults.ExecutionResults.IsError, "Second result should NOT have thrown an exception"); } }
public async Task ExecuteAsync(CancellationToken cancellationToken) { LogExecution(); CommonCacheTestUtils.DeleteAllTestCaches(); CommonCacheTestUtils.EnsureCacheFileDirectoryExists(); var api = new LabServiceApi(new KeyVaultSecretsProvider()); var labUser = api.GetLabResponse( new UserQuery { UserType = UserType.Member, IsFederatedUser = false }).User; Console.WriteLine($"Received LabUser: {labUser.Upn} from LabServiceApi."); var cacheProgramFirst = CacheProgramFactory.CreateCacheProgram(_firstProgram); var cacheProgramSecond = CacheProgramFactory.CreateCacheProgram(_secondProgram); var firstResults = await cacheProgramFirst.ExecuteAsync(labUser.Upn, labUser.Password, cancellationToken).ConfigureAwait(false); var secondResults = await cacheProgramSecond.ExecuteAsync(labUser.Upn, labUser.Password, cancellationToken).ConfigureAwait(false); Console.WriteLine($"FirstResults: {_firstProgram}"); Console.WriteLine($"stdout: {firstResults.StdOut}"); Console.WriteLine($"stderr: {firstResults.StdErr}"); Console.WriteLine($"SecondResults: {_secondProgram}"); Console.WriteLine($"stdout: {secondResults.StdOut}"); Console.WriteLine($"stderr: {secondResults.StdErr}"); Assert.IsFalse(firstResults.ProcessExecutionFailed, $"{cacheProgramFirst.ExecutablePath} should not fail"); Assert.IsFalse(secondResults.ProcessExecutionFailed, $"{cacheProgramSecond.ExecutablePath} should not fail"); Assert.IsFalse(firstResults.ExecutionResults.ReceivedTokenFromCache, "First result should not be from the cache"); if (File.Exists(CommonCacheTestUtils.AdalV3CacheFilePath)) { Console.WriteLine($"Adal Cache Exists at: {CommonCacheTestUtils.AdalV3CacheFilePath}"); Console.WriteLine("Adal Cache Size: " + Convert.ToInt32(new FileInfo(CommonCacheTestUtils.AdalV3CacheFilePath).Length)); } else { Console.WriteLine($"Adal Cache DOES NOT EXIST at: {CommonCacheTestUtils.AdalV3CacheFilePath}"); } if (File.Exists(CommonCacheTestUtils.MsalV2CacheFilePath)) { Console.WriteLine($"MSAL Cache Exists at: {CommonCacheTestUtils.MsalV2CacheFilePath}"); Console.WriteLine("MSAL Cache Size: " + Convert.ToInt32(new FileInfo(CommonCacheTestUtils.MsalV2CacheFilePath).Length)); } else { Console.WriteLine($"MSAL Cache DOES NOT EXIST at: {CommonCacheTestUtils.MsalV2CacheFilePath}"); } // TODO: cache size seems to be variant/inconsistent. Need to validate if it should be the same every time. //if (_expectedAdalCacheSizeBytes > 0) //{ // Assert.AreEqual(_expectedAdalCacheSizeBytes, Convert.ToInt32(new FileInfo(CommonCacheTestUtils.AdalV3CacheFilePath).Length), "Expected Adal Cache Size"); //} //if (_expectedMsalCacheSizeBytes > 0) //{ // Assert.AreEqual(_expectedMsalCacheSizeBytes, Convert.ToInt32(new FileInfo(CommonCacheTestUtils.MsalV2CacheFilePath).Length), "Expected Msal Cache Size"); //} if (_expectSecondTokenFromCache) { Assert.IsTrue( secondResults.ExecutionResults.ReceivedTokenFromCache, "Second result should be from the cache"); } else { Assert.IsFalse( secondResults.ExecutionResults.ReceivedTokenFromCache, "Second result should NOT be from the cache"); } if (_expectSecondTokenException) { Assert.IsTrue( secondResults.ExecutionResults.IsError, "Second result should have thrown an exception"); } else { Assert.IsFalse( secondResults.ExecutionResults.IsError, "Second result should NOT have thrown an exception"); } }