public async Task ExecuteAsync(CancellationToken cancellationToken)
        {
            LogExecution();

            CommonCacheTestUtils.DeleteAllTestCaches();
            CommonCacheTestUtils.EnsureCacheFileDirectoryExists();

            var cacheProgramFirst  = CacheProgramFactory.CreateCacheProgram(_firstProgram, _cacheStorageType);
            var cacheProgramSecond = CacheProgramFactory.CreateCacheProgram(_secondProgram, _cacheStorageType);

            var firstResults = await cacheProgramFirst.ExecuteAsync(_labUsers, cancellationToken).ConfigureAwait(false);

            var secondResults = await cacheProgramSecond.ExecuteAsync(_labUsers, 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");

            foreach (var upnResult in firstResults.ExecutionResults.Results)
            {
                Assert.IsFalse(upnResult.IsAuthResultFromCache, $"{upnResult.LabUserUpn} --> First result should not be from the cache");
                Assert.AreEqual(upnResult?.LabUserUpn?.ToLowerInvariant(), upnResult?.AuthResultUpn?.ToLowerInvariant());
            }

            foreach (var upnResult in secondResults.ExecutionResults.Results)
            {
                Assert.IsTrue(upnResult.IsAuthResultFromCache, $"{upnResult.LabUserUpn} --> Second result should be from the cache");
                Assert.AreEqual(upnResult?.LabUserUpn?.ToLowerInvariant(), upnResult?.AuthResultUpn?.ToLowerInvariant());
            }

            Assert.IsFalse(
                secondResults.ExecutionResults.IsError,
                "Second result should NOT have thrown an exception");

            PrintCacheInfo();
        }
        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());
            }
        }
예제 #3
0
        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");
            }
        }
예제 #4
0
        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");
            }
        }