Skip to content

Commit

Permalink
Dotnet format
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisDyallo committed Aug 13, 2024
1 parent debd0b4 commit 6187109
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion Yubico.Core/src/Yubico/Core/Logging/Log.Legacy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public static ILoggerFactory LoggerFactory
set
{
_factory = value;

// Also swap out the new implementation instance
Instance = value;
}
Expand Down
6 changes: 3 additions & 3 deletions Yubico.Core/src/Yubico/Core/Logging/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public static ILoggerFactory Instance

/// <inheritdoc cref="LoggerFactoryExtensions.CreateLogger"/>
public static ILogger GetLogger(string categoryName) => Instance.CreateLogger(categoryName);

/// <summary>
/// <example>
/// From your project, you can set up logging dynamically like this, if you don't use this,
Expand Down Expand Up @@ -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);
}
Expand Down
26 changes: 13 additions & 13 deletions Yubico.Core/src/Yubico/Core/Logging/LoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static void SensitiveLogDebug(this ILogger logger, EventId eventId, strin
#else
NoOp(eventId, message, args);
#endif

/// <summary>
/// Formats and writes a debug log message that contains potentially sensitive information.
/// </summary>
Expand Down Expand Up @@ -107,7 +107,7 @@ public static void SensitiveLogDebug(this ILogger logger, string message, params
#endif

//------------------------------------------TRACE------------------------------------------//

/// <summary>
/// Formats and writes a trace log message that contains potentially sensitive information.
/// </summary>
Expand Down Expand Up @@ -144,7 +144,7 @@ public static void SensitiveLogTrace(this ILogger logger, EventId eventId, strin
#else
NoOp(eventId, message, args);
#endif

/// <summary>
/// Formats and writes a trace log message that contains potentially sensitive information.
/// </summary>
Expand Down Expand Up @@ -254,7 +254,7 @@ public static void SensitiveLogInformation(this ILogger logger, string message,
#else
NoOp(message, args);
#endif

/// <summary>
/// Formats and writes a warning log message that contains potentially sensitive information.
/// </summary>
Expand Down Expand Up @@ -291,7 +291,7 @@ public static void SensitiveLogWarning(this ILogger logger, EventId eventId, str
#else
NoOp(eventId, message, args);
#endif

/// <summary>
/// Formats and writes a warning log message that contains potentially sensitive information.
/// </summary>
Expand All @@ -309,7 +309,7 @@ public static void SensitiveLogWarning(this ILogger logger, Exception exception,
#else
NoOp(exception, message, args);
#endif

/// <summary>
/// Formats and writes a warning log message that contains potentially sensitive information.
/// </summary>
Expand All @@ -328,7 +328,7 @@ public static void SensitiveLogWarning(this ILogger logger, string message, para
#endif

//------------------------------------------ERROR------------------------------------------//

/// <summary>
/// Formats and writes an error log message that contains potentially sensitive information.
/// </summary>
Expand All @@ -347,7 +347,7 @@ public static void SensitiveLogError(this ILogger logger, EventId eventId, Excep
#else
NoOp(eventId, exception, message, args);
#endif

/// <summary>
/// Formats and writes an error log message that contains potentially sensitive information.
/// </summary>
Expand All @@ -365,7 +365,7 @@ public static void SensitiveLogError(this ILogger logger, EventId eventId, strin
#else
NoOp(eventId, message, args);
#endif

/// <summary>
/// Formats and writes an error log message that contains potentially sensitive information.
/// </summary>
Expand All @@ -383,7 +383,7 @@ public static void SensitiveLogError(this ILogger logger, Exception exception, s
#else
NoOp(exception, message, args);
#endif

/// <summary>
/// Formats and writes an error log message that contains potentially sensitive information.
/// </summary>
Expand Down Expand Up @@ -421,7 +421,7 @@ public static void SensitiveLogCritical(this ILogger logger, EventId eventId, Ex
#else
NoOp(eventId, exception, message, args);
#endif

/// <summary>
/// Formats and writes a critical log message that contains potentially sensitive information.
/// </summary>
Expand All @@ -439,7 +439,7 @@ public static void SensitiveLogCritical(this ILogger logger, EventId eventId, st
#else
NoOp(eventId, message, args);
#endif

/// <summary>
/// Formats and writes a critical log message that contain potentially sensitive information.
/// </summary>
Expand Down Expand Up @@ -489,7 +489,7 @@ public static void SensitiveLog(this ILogger logger, LogLevel logLevel, string m
#else
NoOp(logLevel, message, args);
#endif

/// <summary>
/// Formats and writes a log message that may contain sensitive information at the specified log level.
/// </summary>
Expand Down
12 changes: 6 additions & 6 deletions Yubico.Core/tests/Yubico/Core/Logging/LogTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,35 @@ 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<LogTests>();
Assert.NotNull(logger);
}

// Ensure that LoggerFactory can be replaced manually using the Instance property.
[Fact]
public void ManualLoggerFactory_SettingInstance_OverridesDefaultFactory()
{
// Arrange
var mockLoggerFactory = new Mock<ILoggerFactory>();
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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -907,14 +907,14 @@ private bool TryForcedChangeManagementKey(ReadOnlyMemory<byte> 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}");

}
Expand Down Expand Up @@ -1057,7 +1057,7 @@ private bool TryAuthenticateManagementKey(bool mutualAuthentication,

ManagementKeyAuthenticated = true;
}

_logger.LogInformation($"Failed to authenticate management key. Message: {completeResponse.StatusMessage}");

return ManagementKeyAuthenticated;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Yubico.YubiKey/tests/sandbox/Plugins/EventManagerPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
6 changes: 3 additions & 3 deletions Yubico.YubiKey/tests/sandbox/Plugins/GregPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public override bool Execute()

return true;
}

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public IntegrationTestDeviceEnumeration(string? configDirectory = null)
/// </summary>
/// <param name="serialNumber"></param>
/// <returns></returns>
public static IYubiKeyDevice GetBySerial(int serialNumber)
public static IYubiKeyDevice GetBySerial(int serialNumber)
=> GetTestDevices().Single(d => d.SerialNumber == serialNumber);

/// <summary>
Expand All @@ -116,7 +116,7 @@ static bool IsAllowedKey(IYubiKeyDevice key)
/// <returns>The allow-list filtered YubiKey that was found.</returns>
public static IYubiKeyDevice GetTestDevice(
StandardTestDevice testDeviceType = StandardTestDevice.Fw5,
Transport transport = Transport.All)
Transport transport = Transport.All)
=> GetTestDevices(transport)
.SelectByStandardTestDevice(testDeviceType);

Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,28 @@ public static class TestCategories
/// aware of when touch is about to be expected.
/// </summary>
public const string RequiresTouch = "RequiresTouch";

/// <summary>
/// These tests are considered to be simple and should not require any special circumstances to run successfully.
/// </summary>
public const string Simple = "Simple";

/// <summary>
/// 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.
/// </summary>
public const string Elevated = "Elevated";
public const string Elevated = "Elevated";

/// <summary>
/// These tests require a Yubikey with biometric capabilities
/// </summary>
public const string RequiresBio = "RequiresBio";
public const string RequiresBio = "RequiresBio";

/// <summary>
/// These tests require certain setup on the Yubikey in order to succeed.
/// </summary>
public const string RequiresSetup = "RequiresSetup";
public const string RequiresSetup = "RequiresSetup";

/// <summary>
/// These tests may require step debugging to avoid timing issues
/// </summary>
Expand All @@ -54,7 +54,7 @@ public static class TestCategories
/// </summary>
public const string RequiresFips = "RequiresFips";
}

public static class TraitTypes
{
public const string Category = "Category";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<IYubiKeyDevice> 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
Expand Down

0 comments on commit 6187109

Please sign in to comment.