public static CacheProgram CreateCacheProgram(CacheProgramType cacheProgramType) { string executablePath; string resultsFilePath; switch (cacheProgramType) { case CacheProgramType.AdalV3: executablePath = Path.Combine(BaseExecutablePath, "AdalV3", "CommonCache.Test.AdalV3.exe"); resultsFilePath = Path.Combine(CommonCacheTestUtils.CacheFileDirectory, "adalv3results.json"); break; case CacheProgramType.AdalV4: executablePath = Path.Combine(BaseExecutablePath, "AdalV4", "CommonCache.Test.AdalV4.exe"); resultsFilePath = Path.Combine(CommonCacheTestUtils.CacheFileDirectory, "adalv4results.json"); break; case CacheProgramType.MsalV2: executablePath = Path.Combine(BaseExecutablePath, "MsalV2", "CommonCache.Test.MsalV2.exe"); resultsFilePath = Path.Combine(CommonCacheTestUtils.CacheFileDirectory, "msalv2results.json"); break; default: throw new ArgumentException("Unknown cacheProgramType", nameof(cacheProgramType)); } return(new CacheProgram(executablePath, resultsFilePath)); }
public async Task TestAdalV5CacheCompatibilityAsync( CacheProgramType interactiveType, CacheProgramType silentType, CacheStorageType cacheStorageType) { var executor = new CacheTestExecutor(s_labUsers, cacheStorageType); await executor.ExecuteAsync(interactiveType, silentType, CancellationToken.None).ConfigureAwait(false); }
public CacheTestExecutor( IEnumerable <LabUserData> labUsers, CacheProgramType firstProgram, CacheProgramType secondProgram, CacheStorageType cacheStorageType) { _labUsers = labUsers; _firstProgram = firstProgram; _secondProgram = secondProgram; _cacheStorageType = cacheStorageType; }
public async Task TestMsalV2CacheCompatibilityAsync( CacheProgramType interactiveType, CacheProgramType silentType, CacheStorageType cacheStorageType) { var executor = new CacheTestExecutor( interactiveType, silentType, cacheStorageType, expectSecondTokenFromCache: true); await executor.ExecuteAsync(CancellationToken.None).ConfigureAwait(false); }
public CacheTestExecutor( CacheProgramType firstProgram, CacheProgramType secondProgram, CacheStorageType cacheStorageType, bool expectSecondTokenFromCache = true, bool expectSecondTokenException = false) { _firstProgram = firstProgram; _secondProgram = secondProgram; _cacheStorageType = cacheStorageType; _expectSecondTokenFromCache = expectSecondTokenFromCache; _expectSecondTokenException = expectSecondTokenException; }
public async Task ExecuteAsync( CacheProgramType firstProgram, CacheProgramType secondProgram, CancellationToken cancellationToken) { Console.WriteLine($"Running {firstProgram} -> {secondProgram}..."); CommonCacheTestUtils.DeleteAllTestCaches(); CommonCacheTestUtils.EnsureCacheFileDirectoryExists(); await ExecuteCacheProgramAsync(firstProgram, true, cancellationToken).ConfigureAwait(false); await ExecuteCacheProgramAsync(secondProgram, false, cancellationToken).ConfigureAwait(false); PrintCacheInfo(); }
public CacheTestExecutor( CacheProgramType firstProgram, CacheProgramType secondProgram, int expectedAdalCacheSizeBytes = 0, int expectedMsalCacheSizeBytes = 0, bool expectSecondTokenFromCache = false, bool expectSecondTokenException = false) { _firstProgram = firstProgram; _secondProgram = secondProgram; _expectedAdalCacheSizeBytes = expectedAdalCacheSizeBytes; _expectedMsalCacheSizeBytes = expectedMsalCacheSizeBytes; _expectSecondTokenFromCache = expectSecondTokenFromCache; _expectSecondTokenException = expectSecondTokenException; }
private async Task ExecuteCacheProgramAsync(CacheProgramType cacheProgramType, bool isFirst, CancellationToken cancellationToken) { var cacheProgramFirst = CacheProgramFactory.CreateCacheProgram(cacheProgramType, _cacheStorageType); var results = await cacheProgramFirst.ExecuteAsync(_labUsers, cancellationToken).ConfigureAwait(false); Console.WriteLine(); Console.WriteLine("------------------------------------"); if (isFirst) { Console.WriteLine($"First Results: {cacheProgramType}"); } else { Console.WriteLine($"Second Results: {cacheProgramType}"); } Console.WriteLine("stdout:"); Console.WriteLine(results.StdOut); Console.WriteLine(); Console.WriteLine("stderr:"); Console.WriteLine(results.StdErr); Console.WriteLine("------------------------------------"); Assert.IsFalse(results.ExecutionResults.IsError, $"{cacheProgramType} should not fail: {results.ExecutionResults.ErrorMessage}"); Assert.IsFalse(results.ProcessExecutionFailed, $"{cacheProgramFirst.ExecutablePath} should not fail"); foreach (var upnResult in results.ExecutionResults.Results) { if (isFirst) { Assert.IsFalse(upnResult.IsAuthResultFromCache, $"{upnResult.LabUserUpn} --> First result should not be from the cache"); } else { Assert.IsTrue(upnResult.IsAuthResultFromCache, $"{upnResult.LabUserUpn} --> Second result should be from the cache"); } Assert.AreEqual(upnResult?.LabUserUpn?.ToLowerInvariant(), upnResult?.AuthResultUpn?.ToLowerInvariant()); } }