Skip to content

Commit

Permalink
Fix NFC timeout for tests, add test suites
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamVe committed Jul 10, 2024
1 parent 7b110c2 commit 5951b4b
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2024 Yubico.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.yubico.yubikit.testing;

import com.yubico.yubikit.testing.openpgp.OpenPgpTests;
import com.yubico.yubikit.testing.piv.PivTests;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;

/**
* All integration tests.
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({
PivTests.class,
OpenPgpTests.class,
})
public class DeviceTests {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2024 Yubico.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.yubico.yubikit.testing;

import org.junit.experimental.categories.Categories;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

/**
* All device tests excluding tests considered too slow.
*/
@RunWith(Categories.class)
@Categories.ExcludeCategory(SlowTest.class)
@Suite.SuiteClasses({
DeviceTests.class
})
public class FastDeviceTests {
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import androidx.annotation.Nullable;

import com.yubico.yubikit.core.smartcard.scp.ScpKid;
import com.yubico.yubikit.testing.SlowTest;
import com.yubico.yubikit.testing.framework.OpenPgpInstrumentedTests;

import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

Expand Down Expand Up @@ -73,6 +75,7 @@ public void testSetPinAttempts() throws Throwable {
}

@Test
@Category(SlowTest.class)
public void testGenerateRsaKeys() throws Throwable {
withOpenPgpSession(OpenPgpDeviceTests::testGenerateRsaKeys);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,25 @@
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.yubico.yubikit.core.smartcard.scp.ScpKid;
import com.yubico.yubikit.testing.SlowTest;
import com.yubico.yubikit.testing.framework.PivInstrumentedTests;

import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class PivJcaProviderTests {

public static class NoScpTests extends PivInstrumentedTests {
@Test
@Category(SlowTest.class)
public void testGenerateKeys() throws Throwable {
withPivSession(PivJcaDeviceTests::testGenerateKeys);
}

@Test
@Category(SlowTest.class)
public void testGenerateKeysPreferBC() throws Throwable {
withPivSession(PivJcaDeviceTests::testGenerateKeysPreferBC);
}
Expand All @@ -45,11 +49,13 @@ public void testImportKeys() throws Throwable {
}

@Test
@Category(SlowTest.class)
public void testSigning() throws Throwable {
withPivSession(PivJcaSigningTests::testSign);
}

@Test
@Category(SlowTest.class)
public void testDecrypt() throws Throwable {
withPivSession(PivJcaDecryptTests::testDecrypt);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (C) 2024 Yubico.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.yubico.yubikit.testing;

public interface SlowTest {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Yubico.
* Copyright (C) 2022-2024 Yubico.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -80,7 +80,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
protected void onResume() {
super.onResume();
try {
yubiKitManager.startNfcDiscovery(new NfcConfiguration().timeout(15000), this, sessionQueue::add);
yubiKitManager.startNfcDiscovery(new NfcConfiguration().timeout(1000 * 60 * 5), this, sessionQueue::add);
} catch (NfcNotAvailable e) {
if (e.isDisabled()) {
logger.error("NFC is disabled", e);
Expand Down Expand Up @@ -139,7 +139,17 @@ public synchronized void returnSession(YubiKeyDevice device) throws InterruptedE
setBusy(false);
});
if (device instanceof NfcYubiKeyDevice) {
((NfcYubiKeyDevice) device).remove(lock::release);
// TODO make waitForRemoval configurable from a test case
final boolean waitForRemoval = false;

//noinspection ConstantValue
if (waitForRemoval) {
// this causes the app to wait for removal of NFC key from the NFC sensor
((NfcYubiKeyDevice) device).remove(lock::release);
} else {
lock.release();
}

lock.acquire();
}
}
Expand Down

0 comments on commit 5951b4b

Please sign in to comment.