Ejemplo n.º 1
0
        public static async Task CorrelationIdTestAsync(Sts sts)
        {
            SetCredential(sts);
            var  context       = new AuthenticationContextProxy(sts.Authority, sts.ValidateAuthority);
            Guid correlationId = Guid.NewGuid();
            AuthenticationResultProxy result = null;

            var eventListener = new SampleEventListener();

            eventListener.EnableEvents(AdalOption.AdalEventSource, EventLevel.Verbose);

            context.SetCorrelationId(correlationId);
            result = await context.AcquireTokenAsync(sts.ValidResource, sts.ValidClientId, sts.ValidDefaultRedirectUri, PlatformParameters, sts.ValidUserId);

            VerifySuccessResult(sts, result);
            Verify.IsTrue(eventListener.TraceBuffer.Contains(correlationId.ToString()));

            eventListener.TraceBuffer = string.Empty;

            context.SetCorrelationId(Guid.Empty);
            AuthenticationResultProxy result2 = await context.AcquireTokenSilentAsync(sts.ValidResource, sts.ValidClientId);

            Verify.IsNotNullOrEmptyString(result2.AccessToken);
            Verify.IsFalse(eventListener.TraceBuffer.Contains(correlationId.ToString()));
        }
 public void AdalTraceTest()
 {
     Verify.IsFalse(AdalOption.AdalEventSource.IsEnabled());
     var eventListener = new SampleEventListener();
     eventListener.EnableEvents(AdalOption.AdalEventSource, EventLevel.Verbose);
     Verify.IsNullOrEmptyString(eventListener.TraceBuffer);
     Verify.IsTrue(AdalOption.AdalEventSource.IsEnabled());
     AuthenticationContext context = new AuthenticationContext("https://login.windows.net/commmon");
     Verify.IsNotNullOrEmptyString(eventListener.TraceBuffer);
     eventListener.DisableEvents(AdalOption.AdalEventSource);
     Verify.IsFalse(AdalOption.AdalEventSource.IsEnabled());
 }
        public static async Task CorrelationIdTestAsync(Sts sts)
        {
            SetCredential(sts);
            var context = new AuthenticationContextProxy(sts.Authority, sts.ValidateAuthority);
            Guid correlationId = Guid.NewGuid();
            AuthenticationResultProxy result = null;

            var eventListener = new SampleEventListener();
            eventListener.EnableEvents(AdalOption.AdalEventSource, EventLevel.Verbose);

            context.SetCorrelationId(correlationId);
            result = await context.AcquireTokenAsync(sts.ValidResource, sts.ValidClientId, sts.ValidDefaultRedirectUri, PlatformParameters, sts.ValidUserId);
            VerifySuccessResult(sts, result);
            Verify.IsTrue(eventListener.TraceBuffer.Contains(correlationId.ToString()));

            eventListener.TraceBuffer = string.Empty;

            context.SetCorrelationId(Guid.Empty);
            AuthenticationResultProxy result2 = await context.AcquireTokenSilentAsync(sts.ValidResource, sts.ValidClientId);
            Verify.IsNotNullOrEmptyString(result2.AccessToken);
            Verify.IsFalse(eventListener.TraceBuffer.Contains(correlationId.ToString()));
        }
        internal static async Task LoggerTestAsync(Sts sts)
        {
            var eventListener = new SampleEventListener();
            eventListener.EnableEvents(AdalOption.AdalEventSource, EventLevel.Verbose);

            Trace.TraceInformation("$$$$$");

            var context = new AuthenticationContextProxy(sts.Authority, sts.ValidateAuthority, TokenCacheType.Null);

            var credential = new ClientCredential(sts.ValidConfidentialClientId, sts.ValidConfidentialClientSecret);
            await context.AcquireTokenAsync(sts.ValidResource, credential);
            var invalidCredential = new ClientCredential(sts.ValidConfidentialClientId, sts.ValidConfidentialClientSecret + "x");
            await context.AcquireTokenAsync(sts.ValidResource, invalidCredential);

            Verify.IsTrue(eventListener.TraceBuffer.IndexOf("$$") < 0);

            eventListener.TraceBuffer = string.Empty;

            credential = new ClientCredential(sts.ValidConfidentialClientId, sts.ValidConfidentialClientSecret);
            await context.AcquireTokenAsync(sts.ValidResource, credential);
            invalidCredential = new ClientCredential(sts.ValidConfidentialClientId, sts.ValidConfidentialClientSecret + "x");
            await context.AcquireTokenAsync(sts.ValidResource, invalidCredential);

            Verify.IsFalse(string.IsNullOrEmpty(eventListener.TraceBuffer));

            eventListener.TraceBuffer = string.Empty;
            eventListener.DisableEvents(AdalOption.AdalEventSource);

            credential = new ClientCredential(sts.ValidConfidentialClientId, sts.ValidConfidentialClientSecret);
            await context.AcquireTokenAsync(sts.ValidResource, credential);
            invalidCredential = new ClientCredential(sts.ValidConfidentialClientId, sts.ValidConfidentialClientSecret + "x");
            await context.AcquireTokenAsync(sts.ValidResource, invalidCredential);

            Verify.IsTrue(string.IsNullOrEmpty(eventListener.TraceBuffer));
        }