Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor test categorizing #137

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace Yubico.YubiKey.Fido2.Commands
{
[Trait(TraitTypes.Category, TestCategories.FirmwareOrHardwareMismatch)]
[Trait(TraitTypes.Category, TestCategories.Elevated)]
public class EnumCredsCommandTests : SimpleIntegrationTestConnection
{
public EnumCredsCommandTests()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace Yubico.YubiKey.Fido2.Commands
{
[Trait(TraitTypes.Category, TestCategories.FirmwareOrHardwareMismatch)]
[Trait(TraitTypes.Category, TestCategories.Elevated)]
public class EnumRpsCommandTests : SimpleIntegrationTestConnection
{
public EnumRpsCommandTests()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace Yubico.YubiKey.Fido2.Commands
{
[Trait(TraitTypes.Category, TestCategories.FirmwareOrHardwareMismatch)]
[Trait(TraitTypes.Category, TestCategories.Elevated)]
public class UpdateUserInfoCommandTests : SimpleIntegrationTestConnection
{
public UpdateUserInfoCommandTests()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

namespace Yubico.YubiKey.Fido2
{
[Trait(TraitTypes.Category, TestCategories.FirmwareOrHardwareMismatch)]
[Trait(TraitTypes.Category, TestCategories.Elevated)]
public class SimpleCredMgmtTests : SimpleIntegrationTestConnection
{
public SimpleCredMgmtTests()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
namespace Yubico.YubiKey.Management
{
[Trait(TraitTypes.Category, TestCategories.Simple)]
[Trait(TraitTypes.Category, TestCategories.RequiresFips)]

public class SetDeviceInfoCommandTests
{
[SkippableTheory(typeof(DeviceNotFoundException))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ namespace Yubico.YubiKey
/// Tests device that it will not accept PINs or PUKs which violate PIN complexity
/// Before running the tests, reset the FIDO2/PIV application on the device
/// </summary>
[Trait(TraitTypes.Category, TestCategories.RequiresFips)]
public class PinComplexityTests
{

private readonly ReadOnlyMemory<byte> _defaultPin = new ReadOnlyMemory<byte>(Encoding.ASCII.GetBytes("123456"));
private readonly ReadOnlyMemory<byte> _complexPin = new ReadOnlyMemory<byte>(Encoding.ASCII.GetBytes("11234567"));
private readonly ReadOnlyMemory<byte> _invalidPin = new ReadOnlyMemory<byte>(Encoding.ASCII.GetBytes("33333333"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)

public class ReclaimTimeoutTests
{
[Trait(TraitTypes.Category, TestCategories.Elevated)]
[Fact]
public void SwitchingBetweenTransports_ForcesThreeSecondWait()
{
Expand All @@ -57,7 +58,7 @@ public void SwitchingBetweenTransports_ForcesThreeSecondWait()
.AddFilter(level => level >= LogLevel.Information));

// TEST ASSUMPTION: This test requires FIDO. On Windows, that means this test case must run elevated (admin).
IYubiKeyDevice testDevice = IntegrationTestDeviceEnumeration.GetTestDevice(StandardTestDevice.Fw5);
IYubiKeyDevice testDevice = IntegrationTestDeviceEnumeration.GetTestDevice();

// Ensure all interfaces are active
if (testDevice.EnabledUsbCapabilities != YubiKeyCapabilities.All)
Expand Down
28 changes: 14 additions & 14 deletions Yubico.YubiKey/tests/integration/Yubico/YubiKey/U2f/PinTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public PinTests()
}
}

IEnumerable<HidDevice> devices = HidDevice.GetHidDevices();
var devices = HidDevice.GetHidDevices();
Assert.NotNull(devices);

HidDevice? deviceToUse = CommandTests.GetFidoHid(devices);
var deviceToUse = CommandTests.GetFidoHid(devices);
Assert.NotNull(deviceToUse);

if (deviceToUse is null)
Expand Down Expand Up @@ -69,7 +69,7 @@ public void SetPin_Succeeds()
};

var cmd = new GetPagedDeviceInfoCommand();
GetPagedDeviceInfoResponse rsp = _fidoConnection.SendCommand(cmd);
var rsp = _fidoConnection.SendCommand(cmd);
Assert.Equal(ResponseStatus.Success, rsp.Status);

var getData = YubiKeyDeviceInfo.CreateFromResponseData(rsp.GetData());
Expand All @@ -79,13 +79,13 @@ public void SetPin_Succeeds()
}

var vfyCmd = new VerifyFipsModeCommand();
VerifyFipsModeResponse vfyRsp = _fidoConnection.SendCommand(vfyCmd);
var vfyRsp = _fidoConnection.SendCommand(vfyCmd);
Assert.Equal(ResponseStatus.Success, vfyRsp.Status);
bool isFipsMode = vfyRsp.GetData();
var isFipsMode = vfyRsp.GetData();
Assert.True(isFipsMode);

var setCmd = new SetPinCommand(currentPin, newPin);
SetPinResponse setRsp = _fidoConnection.SendCommand(setCmd);
var setRsp = _fidoConnection.SendCommand(setCmd);
Assert.Equal(ResponseStatus.Success, setRsp.Status);

setCmd = new SetPinCommand(newPin, currentPin);
Expand All @@ -108,7 +108,7 @@ public void InvalidPin_CorrectError()
};

var setCmd = new SetPinCommand(currentPin, badPin);
SetPinResponse setRsp = _fidoConnection.SendCommand(setCmd);
var setRsp = _fidoConnection.SendCommand(setCmd);
Assert.Equal(ResponseStatus.Failed, setRsp.Status);
}

Expand All @@ -123,7 +123,7 @@ public void VerifyPin_Succeeds()
};

var cmd = new GetPagedDeviceInfoCommand();
GetPagedDeviceInfoResponse rsp = _fidoConnection.SendCommand(cmd);
var rsp = _fidoConnection.SendCommand(cmd);
Assert.Equal(ResponseStatus.Success, rsp.Status);

var getData = YubiKeyDeviceInfo.CreateFromResponseData(rsp.GetData());
Expand All @@ -133,7 +133,7 @@ public void VerifyPin_Succeeds()
}

var vfyCmd = new VerifyPinCommand(correctPin);
VerifyPinResponse vfyRsp = _fidoConnection.SendCommand(vfyCmd);
var vfyRsp = _fidoConnection.SendCommand(vfyCmd);
Assert.Equal(ResponseStatus.Success, vfyRsp.Status);

vfyCmd = new VerifyPinCommand(wrongPin);
Expand Down Expand Up @@ -161,7 +161,7 @@ public void WrongPin_ThreeTimes() // Not sure how to run this test
0x41, 0x42, 0x43, 0x44, 0x45, 0x46
};

bool isValid = IsYubiKeyVersion4Fips(out bool isFipsMode);
var isValid = IsYubiKeyVersion4Fips(out var isFipsMode);
Skip.IfNot(isValid);
if (!isFipsMode)
{
Expand All @@ -170,7 +170,7 @@ public void WrongPin_ThreeTimes() // Not sure how to run this test
}

var vfyCmd = new VerifyPinCommand(correctPin);
VerifyPinResponse vfyRsp = _fidoConnection.SendCommand(vfyCmd);
var vfyRsp = _fidoConnection.SendCommand(vfyCmd);
Assert.Equal(ResponseStatus.Success, vfyRsp.Status);

// Verify with the wrong PIN 3 times.
Expand Down Expand Up @@ -198,7 +198,7 @@ private bool IsYubiKeyVersion4Fips(out bool isFipsMode)
isFipsMode = false;

var cmd = new GetPagedDeviceInfoCommand();
GetPagedDeviceInfoResponse rsp = _fidoConnection.SendCommand(cmd);
var rsp = _fidoConnection.SendCommand(cmd);
if (rsp.Status != ResponseStatus.Success)
{
return false;
Expand All @@ -214,7 +214,7 @@ private bool IsYubiKeyVersion4Fips(out bool isFipsMode)
}

var vfyCmd = new VerifyFipsModeCommand();
VerifyFipsModeResponse vfyRsp = _fidoConnection.SendCommand(vfyCmd);
var vfyRsp = _fidoConnection.SendCommand(vfyCmd);
if (vfyRsp.Status != ResponseStatus.Success)
{
return false;
Expand All @@ -230,7 +230,7 @@ private bool IsYubiKeyVersion4Fips(out bool isFipsMode)
private bool SetU2fPin(byte[] newPin)
{
var setCmd = new SetPinCommand(ReadOnlyMemory<byte>.Empty, newPin);
SetPinResponse setRsp = _fidoConnection.SendCommand(setCmd);
var setRsp = _fidoConnection.SendCommand(setCmd);

return setRsp.Status == ResponseStatus.Success;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,26 @@

namespace Yubico.YubiKey.TestUtilities
{
public class TestCategories
public static class TestCategories
{
/// <summary>
/// When touch is required, the user should touch the YubiKey.
/// It's recommended to use a debug break point at the code where touch is required, so that you're
/// 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
/// 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 FirmwareOrHardwareMismatch = "FirmwareOrHardwareMismatch";

/// <summary>
/// These tests require a Yubikey with biometric capabilities
/// </summary>
Expand All @@ -46,10 +47,15 @@ public class TestCategories
/// <summary>
/// These tests may require step debugging to avoid timing issues
/// </summary>
public const string RequiresStepDebug = "RequiresStepDebug";
public const string RequiresStepDebug = "RequiresStepDebug";

/// <summary>
/// These tests require a Yubikey with FIPS
/// </summary>
public const string RequiresFips = "RequiresFips";
}

public class TraitTypes
public static class TraitTypes
{
public const string Category = "Category";
}
Expand Down
Loading