diff --git a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/InMemoryLogger.cs b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/InMemoryLogger.cs deleted file mode 100644 index a8bdbe8be4..0000000000 --- a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/InMemoryLogger.cs +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Diagnostics; -using Microsoft.Extensions.Logging; - -namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect -{ - public class InMemoryLogger : ILogger, IDisposable - { - LogLevel _logLevel = 0; - - public InMemoryLogger(LogLevel logLevel = LogLevel.Debug) - { - _logLevel = logLevel; - } - - List _logEntries = new List(); - - public IDisposable BeginScopeImpl(object state) - { - return this; - } - - public void Dispose() - { - } - - public bool IsEnabled(LogLevel logLevel) - { - return (logLevel >= _logLevel); - } - - public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func formatter) - { - if (IsEnabled(logLevel)) - { - var logEntry = - new LogEntry - { - EventId = eventId, - Exception = exception, - Formatter = formatter, - Level = logLevel, - State = state, - }; - - _logEntries.Add(logEntry); - Debug.WriteLine(logEntry.ToString()); - } - } - - public List Logs { get { return _logEntries; } } - } -} diff --git a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/InMemoryLoggerFactory.cs b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/InMemoryLoggerFactory.cs deleted file mode 100644 index 3185e6518f..0000000000 --- a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/InMemoryLoggerFactory.cs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using Microsoft.Extensions.Logging; - -namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect -{ - public class InMemoryLoggerFactory : ILoggerFactory - { - InMemoryLogger _logger; - LogLevel _logLevel = LogLevel.Debug; - - public InMemoryLoggerFactory(LogLevel logLevel) - { - _logLevel = logLevel; - _logger = new InMemoryLogger(_logLevel); - } - - public LogLevel MinimumLevel - { - get { return _logLevel; } - set { _logLevel = value; } - } - - public void AddProvider(ILoggerProvider provider) - { - } - - public ILogger CreateLogger(string categoryName) - { - return _logger; - } - - public void Dispose() - { - } - - public InMemoryLogger Logger { get { return _logger; } } - } -} diff --git a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/LogEntry.cs b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/LogEntry.cs deleted file mode 100644 index 285d42a66c..0000000000 --- a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/LogEntry.cs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -// this controls if the logs are written to the console. -// they can be reviewed for general content. - -using System; -using Microsoft.Extensions.Logging; - -namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect -{ - public class LogEntry - { - public LogEntry() { } - - public int EventId { get; set; } - - public Exception Exception { get; set; } - - public Func Formatter { get; set; } - - public LogLevel Level { get; set; } - - public object State { get; set; } - - public override string ToString() - { - if (Formatter != null) - { - return Formatter(this.State, this.Exception); - } - else - { - string message = (Formatter != null ? Formatter(State, Exception) : (State?.ToString() ?? "null")); - message += ", LogLevel: " + Level.ToString(); - message += ", EventId: " + EventId.ToString(); - message += ", Exception: " + (Exception == null ? "null" : Exception.Message); - return message; - } - } - } -} diff --git a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/LoggingUtilities.cs b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/LoggingUtilities.cs deleted file mode 100644 index b8d9e6e0c9..0000000000 --- a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/LoggingUtilities.cs +++ /dev/null @@ -1,148 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -// this controls if the logs are written to the console. -// they can be reviewed for general content. - -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.Extensions.Logging; - -namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect -{ - public class LoggingUtilities - { - static List CompleteLogEntries; - static Dictionary LogEntries; - - static LoggingUtilities() - { - LogEntries = - new Dictionary() - { - { "OIDCH_0000:", LogLevel.Debug }, - { "OIDCH_0001:", LogLevel.Debug }, - { "OIDCH_0002:", LogLevel.Verbose }, - { "OIDCH_0003:", LogLevel.Verbose }, - { "OIDCH_0004:", LogLevel.Warning }, - { "OIDCH_0005:", LogLevel.Error }, - { "OIDCH_0006:", LogLevel.Error }, - { "OIDCH_0007:", LogLevel.Verbose }, - { "OIDCH_0008:", LogLevel.Verbose }, - { "OIDCH_0009:", LogLevel.Verbose }, - { "OIDCH_0010:", LogLevel.Error }, - { "OIDCH_0011:", LogLevel.Error }, - { "OIDCH_0012:", LogLevel.Verbose }, - { "OIDCH_0013:", LogLevel.Verbose }, - { "OIDCH_0014:", LogLevel.Debug }, - { "OIDCH_0015:", LogLevel.Verbose }, - { "OIDCH_0016:", LogLevel.Verbose }, - { "OIDCH_0017:", LogLevel.Error }, - { "OIDCH_0018:", LogLevel.Verbose }, - { "OIDCH_0019:", LogLevel.Verbose }, - { "OIDCH_0020:", LogLevel.Debug }, - { "OIDCH_0021:", LogLevel.Verbose }, - { "OIDCH_0026:", LogLevel.Error }, - { "OIDCH_0038:", LogLevel.Debug }, - { "OIDCH_0040:", LogLevel.Debug }, - { "OIDCH_0042:", LogLevel.Debug }, - { "OIDCH_0043:", LogLevel.Verbose }, - { "OIDCH_0044:", LogLevel.Verbose }, - { "OIDCH_0045:", LogLevel.Debug } - }; - - BuildLogEntryList(); - } - - /// - /// Builds the complete list of OpenIdConnect log entries that are available in the runtime. - /// - private static void BuildLogEntryList() - { - CompleteLogEntries = new List(); - foreach (var entry in LogEntries) - { - CompleteLogEntries.Add(new LogEntry { State = entry.Key, Level = entry.Value }); - } - } - - /// - /// Adds to errors if a variation if any are found. - /// - /// if this has been seen before, errors will be appended, test results are easier to understand if this is unique. - /// these are the logs the runtime generated - /// these are the errors that were expected - /// the dictionary to record any errors - public static void CheckLogs(List capturedLogs, List expectedLogs, List> errors) - { - if (capturedLogs.Count >= expectedLogs.Count) - { - for (int i = 0; i < capturedLogs.Count; i++) - { - if (i + 1 > expectedLogs.Count) - { - errors.Add(new Tuple(capturedLogs[i], null)); - } - else - { - if (!TestUtilities.AreEqual(capturedLogs[i], expectedLogs[i])) - { - errors.Add(new Tuple(capturedLogs[i], expectedLogs[i])); - } - } - } - } - else - { - for (int i = 0; i < expectedLogs.Count; i++) - { - if (i + 1 > capturedLogs.Count) - { - errors.Add(new Tuple(null, expectedLogs[i])); - } - else - { - if (!TestUtilities.AreEqual(expectedLogs[i], capturedLogs[i])) - { - errors.Add(new Tuple(capturedLogs[i], expectedLogs[i])); - } - } - } - } - } - - public static string LoggingErrors(List> errors) - { - string loggingErrors = null; - if (errors.Count > 0) - { - var stringBuilder = new StringBuilder(); - stringBuilder.AppendLine(""); - foreach (var error in errors) - { - stringBuilder.AppendLine("*Captured*, *Expected* : *" + (error.Item1?.ToString() ?? "null") + "*, *" + (error.Item2?.ToString() ?? "null") + "*"); - } - - loggingErrors = stringBuilder.ToString(); - } - - return loggingErrors; - } - - /// - /// Populates a list of expected log entries for a test variation. - /// - /// the index for the in CompleteLogEntries of interest. - /// a that represents the expected entries for a test variation. - public static List PopulateLogEntries(int[] items) - { - var entries = new List(); - foreach (var item in items) - { - entries.Add(CompleteLogEntries[item]); - } - - return entries; - } - } -} diff --git a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectHandlerTests.cs b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectHandlerTests.cs index 1f695d97de..b7d9608744 100644 --- a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectHandlerTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectHandlerTests.cs @@ -14,7 +14,6 @@ using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http.Authentication; using Microsoft.AspNet.TestHost; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; using Microsoft.Extensions.WebEncoders; using Microsoft.IdentityModel.Protocols.OpenIdConnect; using Xunit; @@ -30,29 +29,6 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect private static SecurityToken specCompliantOpenIdConnect = new JwtSecurityToken("issuer", "audience", new List { new Claim("iat", EpochTime.GetIntDate(DateTime.UtcNow).ToString()), new Claim("nonce", nonceForOpenIdConnect) }, DateTime.UtcNow, DateTime.UtcNow + TimeSpan.FromDays(1)); private const string ExpectedStateParameter = "expectedState"; - /// - /// Sanity check that logging is filtering, hi / low water marks are checked - /// - [Fact] - public void LoggingLevel() - { - var logger = new InMemoryLogger(LogLevel.Debug); - Assert.True(logger.IsEnabled(LogLevel.Critical)); - Assert.True(logger.IsEnabled(LogLevel.Debug)); - Assert.True(logger.IsEnabled(LogLevel.Error)); - Assert.True(logger.IsEnabled(LogLevel.Information)); - Assert.True(logger.IsEnabled(LogLevel.Verbose)); - Assert.True(logger.IsEnabled(LogLevel.Warning)); - - logger = new InMemoryLogger(LogLevel.Critical); - Assert.True(logger.IsEnabled(LogLevel.Critical)); - Assert.False(logger.IsEnabled(LogLevel.Debug)); - Assert.False(logger.IsEnabled(LogLevel.Error)); - Assert.False(logger.IsEnabled(LogLevel.Information)); - Assert.False(logger.IsEnabled(LogLevel.Verbose)); - Assert.False(logger.IsEnabled(LogLevel.Warning)); - } - [Theory, MemberData(nameof(AuthenticateCoreStateDataSet))] public async Task AuthenticateCoreState(Action action, OpenIdConnectMessage message) { diff --git a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareForTestingAuthenticate.cs b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareForTestingAuthenticate.cs index c39e0798d9..7d7afa56ec 100644 --- a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareForTestingAuthenticate.cs +++ b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareForTestingAuthenticate.cs @@ -21,7 +21,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect OpenIdConnectHandler _handler; public OpenIdConnectMiddlewareForTestingAuthenticate( - RequestDelegate next, + RequestDelegate next, IDataProtectionProvider dataProtectionProvider, ILoggerFactory loggerFactory, IUrlEncoder encoder, @@ -34,9 +34,6 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect : base(next, dataProtectionProvider, loggerFactory, encoder, services, sharedOptions, options, htmlEncoder) { _handler = handler; - var customFactory = loggerFactory as InMemoryLoggerFactory; - if (customFactory != null) - Logger = customFactory.Logger; } protected override AuthenticationHandler CreateHandler() diff --git a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/TestUtilities.cs b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/TestUtilities.cs index dc138dec46..b5371965ca 100644 --- a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/TestUtilities.cs +++ b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/TestUtilities.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using Microsoft.IdentityModel.Protocols; using Microsoft.IdentityModel.Protocols.OpenIdConnect; @@ -14,97 +13,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect { public const string DefaultHost = @"http://localhost"; - public static bool AreEqual(object obj1, object obj2, Func comparer = null) where T : class - { - if (obj1 == null && obj2 == null) - { - return true; - } - - if (obj1 == null || obj2 == null) - { - return false; - } - - if (obj1.GetType() != obj2.GetType()) - { - return false; - } - - if (obj1.GetType() != typeof(T)) - { - return false; - } - - if (comparer != null) - { - return comparer(obj1, obj2); - } - - if (typeof(T) == typeof(LogEntry)) - { - return AreEqual(obj1 as LogEntry, obj2 as LogEntry); - } - else if (typeof(T) == typeof(Exception)) - { - return AreEqual(obj1 as Exception, obj2 as Exception); - } - - throw new ArithmeticException("Unknown type, no comparer. Type: " + typeof(T).ToString()); - - } - - /// - /// Never call this method directly, call AreObjectsEqual, as it deals with nulls and types"/> - /// - /// - /// - /// - private static bool AreEqual(LogEntry logEntry1, LogEntry logEntry2) - { - if (logEntry1.EventId != logEntry2.EventId) - { - return false; - } - - if (logEntry1.State == null && logEntry2.State == null) - { - return true; - } - - if (logEntry1.State == null) - { - return false; - } - - if (logEntry2.State == null) - { - return false; - } - - string logValue1 = logEntry1.Formatter == null ? logEntry1.State.ToString() : logEntry1.Formatter(logEntry1.State, logEntry1.Exception); - string logValue2 = logEntry2.Formatter == null ? logEntry2.State.ToString() : logEntry2.Formatter(logEntry2.State, logEntry2.Exception); - - return (logValue1.StartsWith(logValue2) || (logValue2.StartsWith(logValue1))); - } - - /// - /// Never call this method directly, call AreObjectsEqual, as it deals with nulls and types"/> - /// - /// - /// - /// - private static bool AreEqual(Exception exception1, Exception exception2) - { - if (!string.Equals(exception1.Message, exception2.Message)) - { - return false; - } - - return AreEqual(exception1.InnerException, exception2.InnerException); - } - - static public IConfigurationManager DefaultOpenIdConnectConfigurationManager + public static IConfigurationManager DefaultOpenIdConnectConfigurationManager { get { @@ -112,7 +21,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect } } - static public OpenIdConnectConfiguration DefaultOpenIdConnectConfiguration + public static OpenIdConnectConfiguration DefaultOpenIdConnectConfiguration { get {