From 618710919ccb011bf23f8e3a2c22fe9aed853a58 Mon Sep 17 00:00:00 2001 From: Dennis Dyall Date: Tue, 13 Aug 2024 20:36:52 +0200 Subject: [PATCH] Dotnet format --- .../SmartCardLoggerExtensions.Legacy.cs | 2 +- .../src/Yubico/Core/Logging/Log.Legacy.cs | 2 +- Yubico.Core/src/Yubico/Core/Logging/Log.cs | 6 ++--- .../Yubico/Core/Logging/LoggerExtensions.cs | 26 +++++++++---------- .../tests/Yubico/Core/Logging/LogTests.cs | 12 ++++----- .../YubiKey/Piv/PivSession.ManagementKey.cs | 6 ++--- .../Yubico/YubiKey/ReclaimTimeoutTests.cs | 2 +- .../sandbox/Plugins/EventManagerPlugin.cs | 2 +- .../tests/sandbox/Plugins/GregPlugin.cs | 6 ++--- .../IntegrationTestDeviceEnumeration.cs | 6 ++--- .../YubiKey/TestUtilities/TestCategories.cs | 18 ++++++------- .../TestUtilities/TestDeviceSelection.cs | 26 +++++++++---------- 12 files changed, 57 insertions(+), 57 deletions(-) diff --git a/Yubico.Core/src/Yubico/Core/Devices/SmartCard/SmartCardLoggerExtensions.Legacy.cs b/Yubico.Core/src/Yubico/Core/Devices/SmartCard/SmartCardLoggerExtensions.Legacy.cs index 18b1435e..d1290c32 100644 --- a/Yubico.Core/src/Yubico/Core/Devices/SmartCard/SmartCardLoggerExtensions.Legacy.cs +++ b/Yubico.Core/src/Yubico/Core/Devices/SmartCard/SmartCardLoggerExtensions.Legacy.cs @@ -8,7 +8,7 @@ internal static partial class SmartCardLoggerExtensions [Obsolete("Obsolete")] public static IDisposable BeginTransactionScope(this Logger logger, IDisposable transactionScope) => logger.BeginScope("Transaction[{TransactionID}]", transactionScope.GetHashCode())!; - + [Obsolete("Obsolete")] public static void SCardApiCall(this Logger logger, string apiName, uint result) { diff --git a/Yubico.Core/src/Yubico/Core/Logging/Log.Legacy.cs b/Yubico.Core/src/Yubico/Core/Logging/Log.Legacy.cs index 8af586cb..b4d78aa8 100644 --- a/Yubico.Core/src/Yubico/Core/Logging/Log.Legacy.cs +++ b/Yubico.Core/src/Yubico/Core/Logging/Log.Legacy.cs @@ -128,7 +128,7 @@ public static ILoggerFactory LoggerFactory set { _factory = value; - + // Also swap out the new implementation instance Instance = value; } diff --git a/Yubico.Core/src/Yubico/Core/Logging/Log.cs b/Yubico.Core/src/Yubico/Core/Logging/Log.cs index 53df0acc..aa7506d1 100644 --- a/Yubico.Core/src/Yubico/Core/Logging/Log.cs +++ b/Yubico.Core/src/Yubico/Core/Logging/Log.cs @@ -139,7 +139,7 @@ public static ILoggerFactory Instance /// public static ILogger GetLogger(string categoryName) => Instance.CreateLogger(categoryName); - + /// /// /// From your project, you can set up logging dynamically like this, if you don't use this, @@ -175,9 +175,9 @@ private static ILoggerFactory GetDefaultLoggerFactory() _ = builder.AddConsole(); }); } - #pragma warning disable CA1031 +#pragma warning disable CA1031 catch (Exception e) - #pragma warning restore CA1031 +#pragma warning restore CA1031 { Console.Error.WriteLine(e); } diff --git a/Yubico.Core/src/Yubico/Core/Logging/LoggerExtensions.cs b/Yubico.Core/src/Yubico/Core/Logging/LoggerExtensions.cs index d3f404d6..c84cd7b2 100644 --- a/Yubico.Core/src/Yubico/Core/Logging/LoggerExtensions.cs +++ b/Yubico.Core/src/Yubico/Core/Logging/LoggerExtensions.cs @@ -70,7 +70,7 @@ public static void SensitiveLogDebug(this ILogger logger, EventId eventId, strin #else NoOp(eventId, message, args); #endif - + /// /// Formats and writes a debug log message that contains potentially sensitive information. /// @@ -107,7 +107,7 @@ public static void SensitiveLogDebug(this ILogger logger, string message, params #endif //------------------------------------------TRACE------------------------------------------// - + /// /// Formats and writes a trace log message that contains potentially sensitive information. /// @@ -144,7 +144,7 @@ public static void SensitiveLogTrace(this ILogger logger, EventId eventId, strin #else NoOp(eventId, message, args); #endif - + /// /// Formats and writes a trace log message that contains potentially sensitive information. /// @@ -254,7 +254,7 @@ public static void SensitiveLogInformation(this ILogger logger, string message, #else NoOp(message, args); #endif - + /// /// Formats and writes a warning log message that contains potentially sensitive information. /// @@ -291,7 +291,7 @@ public static void SensitiveLogWarning(this ILogger logger, EventId eventId, str #else NoOp(eventId, message, args); #endif - + /// /// Formats and writes a warning log message that contains potentially sensitive information. /// @@ -309,7 +309,7 @@ public static void SensitiveLogWarning(this ILogger logger, Exception exception, #else NoOp(exception, message, args); #endif - + /// /// Formats and writes a warning log message that contains potentially sensitive information. /// @@ -328,7 +328,7 @@ public static void SensitiveLogWarning(this ILogger logger, string message, para #endif //------------------------------------------ERROR------------------------------------------// - + /// /// Formats and writes an error log message that contains potentially sensitive information. /// @@ -347,7 +347,7 @@ public static void SensitiveLogError(this ILogger logger, EventId eventId, Excep #else NoOp(eventId, exception, message, args); #endif - + /// /// Formats and writes an error log message that contains potentially sensitive information. /// @@ -365,7 +365,7 @@ public static void SensitiveLogError(this ILogger logger, EventId eventId, strin #else NoOp(eventId, message, args); #endif - + /// /// Formats and writes an error log message that contains potentially sensitive information. /// @@ -383,7 +383,7 @@ public static void SensitiveLogError(this ILogger logger, Exception exception, s #else NoOp(exception, message, args); #endif - + /// /// Formats and writes an error log message that contains potentially sensitive information. /// @@ -421,7 +421,7 @@ public static void SensitiveLogCritical(this ILogger logger, EventId eventId, Ex #else NoOp(eventId, exception, message, args); #endif - + /// /// Formats and writes a critical log message that contains potentially sensitive information. /// @@ -439,7 +439,7 @@ public static void SensitiveLogCritical(this ILogger logger, EventId eventId, st #else NoOp(eventId, message, args); #endif - + /// /// Formats and writes a critical log message that contain potentially sensitive information. /// @@ -489,7 +489,7 @@ public static void SensitiveLog(this ILogger logger, LogLevel logLevel, string m #else NoOp(logLevel, message, args); #endif - + /// /// Formats and writes a log message that may contain sensitive information at the specified log level. /// diff --git a/Yubico.Core/tests/Yubico/Core/Logging/LogTests.cs b/Yubico.Core/tests/Yubico/Core/Logging/LogTests.cs index b443b7c5..41c5eaae 100644 --- a/Yubico.Core/tests/Yubico/Core/Logging/LogTests.cs +++ b/Yubico.Core/tests/Yubico/Core/Logging/LogTests.cs @@ -30,20 +30,20 @@ public void Dispose() // Reset to the original factory after each test Log.Instance = _originalFactory; } - + // Ensure that the default LoggerFactory is created when no configuration is provided. [Fact] public void DefaultLoggerFactory_IsCreated_WhenNoConfigurationProvided() { // Act ILoggerFactory loggerFactory = Log.Instance; - + // Assert Assert.NotNull(loggerFactory); ILogger logger = loggerFactory.CreateLogger(); Assert.NotNull(logger); } - + // Ensure that LoggerFactory can be replaced manually using the Instance property. [Fact] public void ManualLoggerFactory_SettingInstance_OverridesDefaultFactory() @@ -51,14 +51,14 @@ public void ManualLoggerFactory_SettingInstance_OverridesDefaultFactory() // Arrange var mockLoggerFactory = new Mock(); Log.Instance = mockLoggerFactory.Object; - + // Act ILoggerFactory actualFactory = Log.Instance; - + // Assert Assert.Same(mockLoggerFactory.Object, actualFactory); } - + // Ensure that LoggerFactory can be replaced manually using the Instance property. // Remove this once we remove Log.Legacy.cs [Fact] diff --git a/Yubico.YubiKey/src/Yubico/YubiKey/Piv/PivSession.ManagementKey.cs b/Yubico.YubiKey/src/Yubico/YubiKey/Piv/PivSession.ManagementKey.cs index c5874a35..9b58dd18 100644 --- a/Yubico.YubiKey/src/Yubico/YubiKey/Piv/PivSession.ManagementKey.cs +++ b/Yubico.YubiKey/src/Yubico/YubiKey/Piv/PivSession.ManagementKey.cs @@ -907,14 +907,14 @@ private bool TryForcedChangeManagementKey(ReadOnlyMemory currentKey, { var setCommand = new SetManagementKeyCommand(newKey, touchPolicy, newKeyAlgorithm); SetManagementKeyResponse setResponse = Connection.SendCommand(setCommand); - + if (setResponse.Status == ResponseStatus.Success) { ManagementKeyAlgorithm = newKeyAlgorithm; return true; } - + _logger.LogInformation($"Failed to set management key. Message: {setResponse.StatusMessage}"); } @@ -1057,7 +1057,7 @@ private bool TryAuthenticateManagementKey(bool mutualAuthentication, ManagementKeyAuthenticated = true; } - + _logger.LogInformation($"Failed to authenticate management key. Message: {completeResponse.StatusMessage}"); return ManagementKeyAuthenticated; diff --git a/Yubico.YubiKey/tests/integration/Yubico/YubiKey/ReclaimTimeoutTests.cs b/Yubico.YubiKey/tests/integration/Yubico/YubiKey/ReclaimTimeoutTests.cs index aa0493a8..6aca5611 100644 --- a/Yubico.YubiKey/tests/integration/Yubico/YubiKey/ReclaimTimeoutTests.cs +++ b/Yubico.YubiKey/tests/integration/Yubico/YubiKey/ReclaimTimeoutTests.cs @@ -53,7 +53,7 @@ public void SwitchingBetweenTransports_ForcesThreeSecondWait() outputTemplate: "{Timestamp:HH:mm:ss.fffffff} [{Level}] ({ThreadId}) {Message}{NewLine}{Exception}") .CreateLogger(); - Log.ConfigureLoggerFactory(builder => + Log.ConfigureLoggerFactory(builder => builder .ClearProviders() .AddSerilog(log) diff --git a/Yubico.YubiKey/tests/sandbox/Plugins/EventManagerPlugin.cs b/Yubico.YubiKey/tests/sandbox/Plugins/EventManagerPlugin.cs index 45ac9e9c..374a7a68 100644 --- a/Yubico.YubiKey/tests/sandbox/Plugins/EventManagerPlugin.cs +++ b/Yubico.YubiKey/tests/sandbox/Plugins/EventManagerPlugin.cs @@ -46,7 +46,7 @@ public override bool Execute() outputTemplate: "[{Level}] ({ThreadId}) {Message}{NewLine}{Exception}") .CreateLogger(); - Log.ConfigureLoggerFactory(builder => + Log.ConfigureLoggerFactory(builder => builder .AddSerilog(log) .AddFilter(level => level >= LogLevel.Information)); diff --git a/Yubico.YubiKey/tests/sandbox/Plugins/GregPlugin.cs b/Yubico.YubiKey/tests/sandbox/Plugins/GregPlugin.cs index efcfb551..01505a9b 100644 --- a/Yubico.YubiKey/tests/sandbox/Plugins/GregPlugin.cs +++ b/Yubico.YubiKey/tests/sandbox/Plugins/GregPlugin.cs @@ -37,8 +37,8 @@ public override bool Execute() return true; } - + } - - + + } diff --git a/Yubico.YubiKey/tests/utilities/Yubico/YubiKey/TestUtilities/IntegrationTestDeviceEnumeration.cs b/Yubico.YubiKey/tests/utilities/Yubico/YubiKey/TestUtilities/IntegrationTestDeviceEnumeration.cs index 588283a9..8da5e7d6 100644 --- a/Yubico.YubiKey/tests/utilities/Yubico/YubiKey/TestUtilities/IntegrationTestDeviceEnumeration.cs +++ b/Yubico.YubiKey/tests/utilities/Yubico/YubiKey/TestUtilities/IntegrationTestDeviceEnumeration.cs @@ -89,7 +89,7 @@ public IntegrationTestDeviceEnumeration(string? configDirectory = null) /// /// /// - public static IYubiKeyDevice GetBySerial(int serialNumber) + public static IYubiKeyDevice GetBySerial(int serialNumber) => GetTestDevices().Single(d => d.SerialNumber == serialNumber); /// @@ -116,7 +116,7 @@ static bool IsAllowedKey(IYubiKeyDevice key) /// The allow-list filtered YubiKey that was found. public static IYubiKeyDevice GetTestDevice( StandardTestDevice testDeviceType = StandardTestDevice.Fw5, - Transport transport = Transport.All) + Transport transport = Transport.All) => GetTestDevices(transport) .SelectByStandardTestDevice(testDeviceType); @@ -132,7 +132,7 @@ public static IYubiKeyDevice GetTestDevice(Transport transport, FirmwareVersion => GetTestDevices(transport) .SelectByMinimumVersion(minimumFirmwareVersion); - + private static void CreateAllowListFileIfMissing(string allowListFilePath) { if (File.Exists(allowListFilePath)) diff --git a/Yubico.YubiKey/tests/utilities/Yubico/YubiKey/TestUtilities/TestCategories.cs b/Yubico.YubiKey/tests/utilities/Yubico/YubiKey/TestUtilities/TestCategories.cs index 5b4b01ae..9d868380 100644 --- a/Yubico.YubiKey/tests/utilities/Yubico/YubiKey/TestUtilities/TestCategories.cs +++ b/Yubico.YubiKey/tests/utilities/Yubico/YubiKey/TestUtilities/TestCategories.cs @@ -22,28 +22,28 @@ public static class TestCategories /// aware of when touch is about to be expected. /// public const string RequiresTouch = "RequiresTouch"; - + /// /// These tests are considered to be simple and should not require any special circumstances to run successfully. /// public const string Simple = "Simple"; - + /// /// These tests require that you run your tests in an elevated session, e.g. 'Run as Administrator' on Windows. /// For example, all FIDO tests require an elevated session on Windows. /// - public const string Elevated = "Elevated"; - + public const string Elevated = "Elevated"; + /// /// These tests require a Yubikey with biometric capabilities /// - public const string RequiresBio = "RequiresBio"; - + public const string RequiresBio = "RequiresBio"; + /// /// These tests require certain setup on the Yubikey in order to succeed. /// - public const string RequiresSetup = "RequiresSetup"; - + public const string RequiresSetup = "RequiresSetup"; + /// /// These tests may require step debugging to avoid timing issues /// @@ -54,7 +54,7 @@ public static class TestCategories /// public const string RequiresFips = "RequiresFips"; } - + public static class TraitTypes { public const string Category = "Category"; diff --git a/Yubico.YubiKey/tests/utilities/Yubico/YubiKey/TestUtilities/TestDeviceSelection.cs b/Yubico.YubiKey/tests/utilities/Yubico/YubiKey/TestUtilities/TestDeviceSelection.cs index ea0bf63c..09662c0e 100644 --- a/Yubico.YubiKey/tests/utilities/Yubico/YubiKey/TestUtilities/TestDeviceSelection.cs +++ b/Yubico.YubiKey/tests/utilities/Yubico/YubiKey/TestUtilities/TestDeviceSelection.cs @@ -84,9 +84,9 @@ IYubiKeyDevice SelectDevice(int majorVersion, FormFactor? formFactor = null, boo IYubiKeyDevice device = null!; try { - bool MatchingDeviceSelector(IYubiKeyDevice d) => - d.FirmwareVersion.Major == majorVersion && - (formFactor is null || d.FormFactor == formFactor) && + bool MatchingDeviceSelector(IYubiKeyDevice d) => + d.FirmwareVersion.Major == majorVersion && + (formFactor is null || d.FormFactor == formFactor) && d.IsFipsSeries == isFipsSeries; device = devices.First(MatchingDeviceSelector); @@ -115,25 +115,25 @@ public static IYubiKeyDevice SelectByMinimumVersion( { ThrowDeviceNotFoundException("No matching YubiKey found", devices); } - + return device!; } - private static void ThrowDeviceNotFoundException(string errorMessage,IYubiKeyDevice[] devices) + private static void ThrowDeviceNotFoundException(string errorMessage, IYubiKeyDevice[] devices) { var connectedDevicesText = FormatConnectedDevices(devices); throw new DeviceNotFoundException($"{errorMessage}. {connectedDevicesText}"); } private static string FormatConnectedDevices(IReadOnlyCollection devices) - { - var deviceText = - devices.Select(y => $"{{{y.FirmwareVersion}, {y.FormFactor}, IsFipsSeries: {y.IsFipsSeries}}}"); - - return devices.Any() - ? $"Connected devices: {string.Join(", ", deviceText)}" - : string.Empty; - } + { + var deviceText = + devices.Select(y => $"{{{y.FirmwareVersion}, {y.FormFactor}, IsFipsSeries: {y.IsFipsSeries}}}"); + + return devices.Any() + ? $"Connected devices: {string.Join(", ", deviceText)}" + : string.Empty; + } } // Custom test exception inheriting from InvalidOperationException as some test code depends on InvalidOperationExceptions