Skip to content

Commit 98ff985

Browse files
committed
test: add integration tests for serial number visibility in OTP operations
Add comprehensive integration tests for all Configure* OTP operation classes to verify the new serial number visibility methods work correctly with actual YubiKey devices. Tests added: - ConfigureYubicoOtp_WithSerialNumberVisibility_Succeeds - ConfigureStaticPassword_WithSerialNumberVisibility_Succeeds - ConfigureHotp_WithSerialNumberVisibility_Succeeds - ConfigureChallengeResponse_WithSerialNumberVisibility_Succeeds - ConfigureNdef_WithSerialNumberVisibility_Succeeds Each test verifies that SetSerialNumberApiVisible, SetSerialNumberButtonVisible, and SetSerialNumberUsbVisible methods can be called and successfully execute on Fw5 and Fw5Fips test devices.
1 parent 1039a44 commit 98ff985

File tree

1 file changed

+188
-0
lines changed

1 file changed

+188
-0
lines changed

Yubico.YubiKey/tests/integration/Yubico/YubiKey/Otp/OtpSessionTests.cs

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,193 @@ public void ConfigureStaticPassword_WithWScp_Succeeds(StandardTestDevice testDev
7979
configObj = configObj.GeneratePassword(generatedPassword);
8080
configObj.Execute();
8181
}
82+
83+
[Trait(TraitTypes.Category, TestCategories.Simple)]
84+
[SkippableTheory(typeof(DeviceNotFoundException))]
85+
[InlineData(StandardTestDevice.Fw5)]
86+
[InlineData(StandardTestDevice.Fw5Fips)]
87+
public void ConfigureYubicoOtp_WithSerialNumberVisibility_Succeeds(StandardTestDevice testDeviceType)
88+
{
89+
IYubiKeyDevice testDevice = IntegrationTestDeviceEnumeration.GetTestDevice(testDeviceType);
90+
91+
using (var otpSession = new OtpSession(testDevice))
92+
{
93+
if (otpSession.IsLongPressConfigured)
94+
{
95+
otpSession.DeleteSlot(Slot.LongPress);
96+
}
97+
}
98+
99+
using (var otpSession = new OtpSession(testDevice))
100+
{
101+
Memory<byte> privateId = new byte[ConfigureYubicoOtp.PrivateIdentifierSize];
102+
Memory<byte> aesKey = new byte[ConfigureYubicoOtp.KeySize];
103+
104+
otpSession.ConfigureYubicoOtp(Slot.LongPress)
105+
.SetSerialNumberApiVisible()
106+
.SetSerialNumberButtonVisible()
107+
.SetSerialNumberUsbVisible()
108+
.UseSerialNumberAsPublicId()
109+
.GeneratePrivateId(privateId)
110+
.GenerateKey(aesKey)
111+
.Execute();
112+
}
113+
114+
using (var otpSession = new OtpSession(testDevice))
115+
{
116+
Assert.True(otpSession.IsLongPressConfigured, "Slot should be configured after Execute()");
117+
}
118+
}
119+
120+
[Trait(TraitTypes.Category, TestCategories.Simple)]
121+
[SkippableTheory(typeof(DeviceNotFoundException))]
122+
[InlineData(StandardTestDevice.Fw5)]
123+
[InlineData(StandardTestDevice.Fw5Fips)]
124+
public void ConfigureStaticPassword_WithSerialNumberVisibility_Succeeds(StandardTestDevice testDeviceType)
125+
{
126+
IYubiKeyDevice testDevice = IntegrationTestDeviceEnumeration.GetTestDevice(testDeviceType);
127+
128+
using (var otpSession = new OtpSession(testDevice))
129+
{
130+
if (otpSession.IsLongPressConfigured)
131+
{
132+
otpSession.DeleteSlot(Slot.LongPress);
133+
}
134+
}
135+
136+
using (var otpSession = new OtpSession(testDevice))
137+
{
138+
Memory<char> generatedPassword = new char[16];
139+
140+
otpSession.ConfigureStaticPassword(Slot.LongPress)
141+
.WithKeyboard(KeyboardLayout.en_US)
142+
.SetSerialNumberApiVisible()
143+
.SetSerialNumberButtonVisible()
144+
.SetSerialNumberUsbVisible()
145+
.GeneratePassword(generatedPassword)
146+
.Execute();
147+
}
148+
149+
using (var otpSession = new OtpSession(testDevice))
150+
{
151+
Assert.True(otpSession.IsLongPressConfigured, "Slot should be configured after Execute()");
152+
}
153+
}
154+
155+
[Trait(TraitTypes.Category, TestCategories.Simple)]
156+
[SkippableTheory(typeof(DeviceNotFoundException))]
157+
[InlineData(StandardTestDevice.Fw5)]
158+
[InlineData(StandardTestDevice.Fw5Fips)]
159+
public void ConfigureHotp_WithSerialNumberVisibility_Succeeds(StandardTestDevice testDeviceType)
160+
{
161+
IYubiKeyDevice testDevice = IntegrationTestDeviceEnumeration.GetTestDevice(testDeviceType);
162+
163+
using (var otpSession = new OtpSession(testDevice))
164+
{
165+
if (otpSession.IsLongPressConfigured)
166+
{
167+
otpSession.DeleteSlot(Slot.LongPress);
168+
}
169+
}
170+
171+
using (var otpSession = new OtpSession(testDevice))
172+
{
173+
Memory<byte> hmacKey = new byte[ConfigureHotp.HmacKeySize];
174+
175+
otpSession.ConfigureHotp(Slot.LongPress)
176+
.SetSerialNumberApiVisible()
177+
.SetSerialNumberButtonVisible()
178+
.SetSerialNumberUsbVisible()
179+
.GenerateKey(hmacKey)
180+
.Execute();
181+
}
182+
183+
using (var otpSession = new OtpSession(testDevice))
184+
{
185+
Assert.True(otpSession.IsLongPressConfigured, "Slot should be configured after Execute()");
186+
}
187+
}
188+
189+
[Trait(TraitTypes.Category, TestCategories.Simple)]
190+
[SkippableTheory(typeof(DeviceNotFoundException))]
191+
[InlineData(StandardTestDevice.Fw5)]
192+
[InlineData(StandardTestDevice.Fw5Fips)]
193+
public void ConfigureChallengeResponse_WithSerialNumberVisibility_Succeeds(StandardTestDevice testDeviceType)
194+
{
195+
IYubiKeyDevice testDevice = IntegrationTestDeviceEnumeration.GetTestDevice(testDeviceType);
196+
197+
using (var otpSession = new OtpSession(testDevice))
198+
{
199+
if (otpSession.IsLongPressConfigured)
200+
{
201+
otpSession.DeleteSlot(Slot.LongPress);
202+
}
203+
}
204+
205+
using (var otpSession = new OtpSession(testDevice))
206+
{
207+
Memory<byte> hmacKey = new byte[ConfigureChallengeResponse.HmacSha1KeySize];
208+
209+
otpSession.ConfigureChallengeResponse(Slot.LongPress)
210+
.SetSerialNumberApiVisible()
211+
.SetSerialNumberButtonVisible()
212+
.SetSerialNumberUsbVisible()
213+
.UseHmacSha1()
214+
.GenerateKey(hmacKey)
215+
.Execute();
216+
}
217+
218+
using (var otpSession = new OtpSession(testDevice))
219+
{
220+
Assert.True(otpSession.IsLongPressConfigured, "Slot should be configured after Execute()");
221+
}
222+
}
223+
224+
[Trait(TraitTypes.Category, TestCategories.Simple)]
225+
[SkippableTheory(typeof(DeviceNotFoundException))]
226+
[InlineData(StandardTestDevice.Fw5)]
227+
[InlineData(StandardTestDevice.Fw5Fips)]
228+
public void ConfigureNdef_WithSerialNumberVisibility_Succeeds(StandardTestDevice testDeviceType)
229+
{
230+
IYubiKeyDevice testDevice = IntegrationTestDeviceEnumeration.GetTestDevice(testDeviceType);
231+
232+
using (var otpSession = new OtpSession(testDevice))
233+
{
234+
if (otpSession.IsLongPressConfigured)
235+
{
236+
otpSession.DeleteSlot(Slot.LongPress);
237+
}
238+
}
239+
240+
// NDEF requires an already configured slot - configure with HOTP first
241+
using (var otpSession = new OtpSession(testDevice))
242+
{
243+
Memory<byte> hmacKey = new byte[ConfigureHotp.HmacKeySize];
244+
245+
otpSession.ConfigureHotp(Slot.LongPress)
246+
.GenerateKey(hmacKey)
247+
.Execute();
248+
}
249+
250+
// Configure NDEF to use that slot with serial number visibility settings
251+
// Note: NDEF configuration does not alter slot state, it only sets NDEF to use the slot.
252+
// Verification would require NFC hardware to read the NDEF tag, so we verify
253+
// that Execute() succeeds without throwing an exception.
254+
using (var otpSession = new OtpSession(testDevice))
255+
{
256+
otpSession.ConfigureNdef(Slot.LongPress)
257+
.SetSerialNumberApiVisible()
258+
.SetSerialNumberButtonVisible()
259+
.SetSerialNumberUsbVisible()
260+
.AsUri(new Uri("https://example.com"))
261+
.Execute();
262+
}
263+
264+
// Verify the slot is still configured (NDEF doesn't change slot configuration)
265+
using (var otpSession = new OtpSession(testDevice))
266+
{
267+
Assert.True(otpSession.IsLongPressConfigured, "Slot should remain configured");
268+
}
269+
}
82270
}
83271
}

0 commit comments

Comments
 (0)