Skip to content

Commit f5c19eb

Browse files
committed
fix HID integration tests
1 parent bad52f3 commit f5c19eb

File tree

6 files changed

+33
-14
lines changed

6 files changed

+33
-14
lines changed

desktop/src/main/java/com/yubico/yubikit/desktop/YubiKitManager.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ List<? extends UsbYubiKeyDevice> listDevices(Class<? extends YubiKeyConnection>
6060
public Map<YubiKeyDevice, DeviceInfo> listAllDevices(Set<Class<? extends YubiKeyConnection>> connectionTypes) {
6161
Map<UsbPid, UsbPidGroup> groups = new HashMap<>();
6262
for (Class<? extends YubiKeyConnection> connectionType : connectionTypes) {
63-
Logger.trace(logger, "Enumerate devices for {}", connectionType);
63+
Logger.debug(logger, "Enumerate devices for {}", connectionType);
6464
for (UsbYubiKeyDevice device : listDevices(connectionType)) {
6565
UsbPid pid = device.getPid();
66-
Logger.trace(logger, "Found device with PID {}", pid);
66+
Logger.debug(logger, "Found device with PID {}", pid);
6767
if (!groups.containsKey(pid)) {
6868
groups.put(pid, new UsbPidGroup(pid));
6969
}

desktop/src/main/java/com/yubico/yubikit/desktop/hid/HidManager.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public HidManager() {
4646
public List<HidDevice> getHidDevices(int vendorId, @Nullable Integer usagePage) {
4747
List<HidDevice> yubikeys = new ArrayList<>();
4848
for (org.hid4java.HidDevice device: services.getAttachedHidDevices()) {
49-
if(device.getProductId() == vendorId &&
49+
if(device.getVendorId() == vendorId &&
5050
(usagePage != null && (device.getUsagePage() & 0xffff) == usagePage)) {
5151
yubikeys.add(new HidDevice(device));
5252
}

testing-desktop/src/main/java/com/yubico/yubikit/testing/desktop/framework/FidoInstrumentedTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected void withDevice(TestState.StatefulDeviceCallback<FidoTestState> callba
3535
protected void withDevice(boolean setPin, TestState.StatefulDeviceCallback<FidoTestState> callback) throws Throwable {
3636
FidoTestState state = new FidoTestState.Builder(device, usbPid, getPinUvAuthProtocol())
3737
.scpKid(getScpKid())
38-
//.reconnectDeviceCallback(this::reconnectDevice)
38+
.reconnectDeviceCallback(this::reconnectDevice)
3939
.setPin(setPin)
4040
.build();
4141

@@ -45,7 +45,7 @@ protected void withDevice(boolean setPin, TestState.StatefulDeviceCallback<FidoT
4545
protected void withCtap2Session(TestState.StatefulSessionCallback<Ctap2Session, FidoTestState> callback) throws Throwable {
4646
FidoTestState state = new FidoTestState.Builder(device, usbPid, getPinUvAuthProtocol())
4747
.scpKid(getScpKid())
48-
//.reconnectDeviceCallback(this::reconnectDevice)
48+
.reconnectDeviceCallback(this::reconnectDevice)
4949
.setPin(true)
5050
.build();
5151

testing-desktop/src/main/java/com/yubico/yubikit/testing/desktop/framework/OathInstrumentedTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class OathInstrumentedTests extends YKInstrumentedTests {
2525
protected void withDevice(TestState.StatefulDeviceCallback<OathTestState> callback) throws Throwable {
2626
final OathTestState state = new OathTestState.Builder(device, usbPid)
2727
.scpKid(getScpKid())
28-
//.reconnectDeviceCallback(this::reconnectDevice)
28+
.reconnectDeviceCallback(this::reconnectDevice)
2929
.build();
3030

3131
state.withDeviceCallback(callback);

testing-desktop/src/main/java/com/yubico/yubikit/testing/desktop/framework/SecurityDomainInstrumentedTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class SecurityDomainInstrumentedTests extends YKInstrumentedTests {
2323

2424
protected void withState(TestState.StatefulDeviceCallback<SecurityDomainTestState> callback) throws Throwable {
2525
final SecurityDomainTestState state = new SecurityDomainTestState.Builder(device, usbPid)
26-
//.reconnectDeviceCallback(this::reconnectDevice)
26+
.reconnectDeviceCallback(this::reconnectDevice)
2727
.build();
2828

2929
state.withDeviceCallback(callback);

testing-desktop/src/main/java/com/yubico/yubikit/testing/desktop/framework/YKInstrumentedTests.java

+26-7
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,41 @@ public class YKInstrumentedTests {
4141

4242
@Override
4343
protected void before() throws Throwable {
44-
device = testDriver.awaitSession();
45-
if (device instanceof CompositeDevice) {
46-
CompositeDevice compositeDevice = (CompositeDevice) device;
47-
usbPid = compositeDevice.getPidGroup().getPid();
48-
}
44+
getDevice();
4945
}
5046

5147
@Override
5248
protected void after() {
53-
testDriver.returnSession(device);
54-
device = null;
49+
releaseDevice();
5550
}
5651
};
5752

53+
protected YubiKeyDevice reconnectDevice() {
54+
releaseDevice();
55+
getDevice();
56+
return device;
57+
}
58+
5859
@Nullable
5960
protected Byte getScpKid() {
6061
return null;
6162
}
63+
64+
private void getDevice() {
65+
try {
66+
device = testDriver.awaitSession();
67+
if (device instanceof CompositeDevice) {
68+
CompositeDevice compositeDevice = (CompositeDevice) device;
69+
usbPid = compositeDevice.getPidGroup().getPid();
70+
}
71+
} catch (InterruptedException interruptedException) {
72+
throw new RuntimeException("awaitSession failed", interruptedException);
73+
}
74+
}
75+
76+
private void releaseDevice() {
77+
testDriver.returnSession(device);
78+
device = null;
79+
}
80+
6281
}

0 commit comments

Comments
 (0)