Skip to content

Commit

Permalink
add DeviceReset integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamVe committed Jun 28, 2024
1 parent 6add086 commit f5d3872
Showing 1 changed file with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,56 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Text;
using Xunit;
using Yubico.YubiKey.Fido2;
using Yubico.YubiKey.Piv;
using Yubico.YubiKey.TestUtilities;

namespace Yubico.YubiKey
{
/// <summary>
/// Executes device wide reset and check that PINs are set to default values (where applicable).
/// </summary>
/// <remarks>
/// Device wide reset is only available on YubiKey Bio Multi-protocol Edition devices.
/// </remarks>
public class DeviceResetTests
{
[SkippableFact]

private readonly ReadOnlyMemory<byte> _defaultPin = new ReadOnlyMemory<byte>(Encoding.ASCII.GetBytes("123456"));
private readonly ReadOnlyMemory<byte> _complexPin = new ReadOnlyMemory<byte>(Encoding.ASCII.GetBytes("11234567"));

[SkippableFact(typeof(DeviceNotFoundException))]
public void Reset()
{
var testDevice = IntegrationTestDeviceEnumeration.GetTestDevice(StandardTestDevice.Fw5Bio);
Skip.IfNot(testDevice.HasFeature(YubiKeyFeature.DeviceReset), "Device does not support DeviceReset.");
Skip.IfNot(testDevice.AvailableUsbCapabilities.HasFlag(YubiKeyCapabilities.Piv), "Device does not support DeviceReset.");

testDevice.DeviceReset();

/* set PIN for PIV - this will also set the FIDO2 PIN */
using (var pivSession = new PivSession(testDevice))
{
Assert.True(pivSession.TryChangePin(_defaultPin, _complexPin, out _));
}

testDevice.DeviceReset();

using var fido2Session = new Fido2Session(testDevice);
var optionValue = fido2Session.AuthenticatorInfo.GetOptionValue(AuthenticatorOptions.clientPin);
Assert.True(optionValue == OptionValue.False);

/* verify that PIV has default PIN */
using (var pivSession = new PivSession(testDevice))
{
Assert.True(pivSession.TryVerifyPin(_defaultPin, out _));
}

/* verify that FIDO2 does not have a PIN set */
using (var fido2Session = new Fido2Session(testDevice))
{
var optionValue = fido2Session.AuthenticatorInfo.GetOptionValue(AuthenticatorOptions.clientPin);
Assert.Equal(OptionValue.False, optionValue);
}
}
}
}

0 comments on commit f5d3872

Please sign in to comment.