From fe379686545ca9246f9b7a3250ea147821802cdb Mon Sep 17 00:00:00 2001 From: Michele Balistreri Date: Mon, 25 Sep 2017 14:16:26 +0300 Subject: [PATCH] add testing facilities --- build.gradle | 9 +++- scripts/statuswallet_smoketest.gpshell | 8 --- .../status/wallet/WalletAppletCommandSet.java | 19 +++++++ .../im/status/wallet/WalletAppletTest.java | 54 +++++++++++++++++++ 4 files changed, 81 insertions(+), 9 deletions(-) delete mode 100644 scripts/statuswallet_smoketest.gpshell create mode 100644 src/test/java/im/status/wallet/WalletAppletCommandSet.java create mode 100644 src/test/java/im/status/wallet/WalletAppletTest.java diff --git a/build.gradle b/build.gradle index 1e62fc7..fdba64b 100644 --- a/build.gradle +++ b/build.gradle @@ -27,7 +27,9 @@ repositories { } dependencies { - testCompile 'com.licel:jcardsim:2.2.2' + testCompile("com.licel:jcardsim:2.2.2") + testCompile("org.junit.jupiter:junit-jupiter-api:5.0.0") + testRuntime("org.junit.jupiter:junit-jupiter-engine:5.0.0") } sourceCompatibility = 1.3 @@ -36,3 +38,8 @@ targetCompatibility = 1.3 task wrapper(type: Wrapper) { gradleVersion = '2.10' } + +compileTestJava { + sourceCompatibility = 1.8 + targetCompatibility = 1.8 +} diff --git a/scripts/statuswallet_smoketest.gpshell b/scripts/statuswallet_smoketest.gpshell deleted file mode 100644 index 11f7fb7..0000000 --- a/scripts/statuswallet_smoketest.gpshell +++ /dev/null @@ -1,8 +0,0 @@ -mode_211 -enable_trace -establish_context -card_connect -select -AID 53746174757357616C6C6574417070 -send_apdu_nostop -APDU 80AA008000 -card_disconnect -release_context \ No newline at end of file diff --git a/src/test/java/im/status/wallet/WalletAppletCommandSet.java b/src/test/java/im/status/wallet/WalletAppletCommandSet.java new file mode 100644 index 0000000..53690a8 --- /dev/null +++ b/src/test/java/im/status/wallet/WalletAppletCommandSet.java @@ -0,0 +1,19 @@ +package im.status.wallet; + +import javacard.framework.ISO7816; +import org.bouncycastle.util.encoders.Hex; + +import javax.smartcardio.CardChannel; +import javax.smartcardio.CardException; +import javax.smartcardio.CommandAPDU; +import javax.smartcardio.ResponseAPDU; + +public class WalletAppletCommandSet { + public static final String APPLET_AID = "53746174757357616C6C6574417070"; + public static final byte[] APPLET_AID_BYTES = Hex.decode(APPLET_AID); + + public static ResponseAPDU select(CardChannel apduChannel) throws CardException { + CommandAPDU selectApplet = new CommandAPDU(ISO7816.CLA_ISO7816, ISO7816.INS_SELECT, 4, 0, APPLET_AID_BYTES); + return apduChannel.transmit(selectApplet); + } +} diff --git a/src/test/java/im/status/wallet/WalletAppletTest.java b/src/test/java/im/status/wallet/WalletAppletTest.java new file mode 100644 index 0000000..3aba73e --- /dev/null +++ b/src/test/java/im/status/wallet/WalletAppletTest.java @@ -0,0 +1,54 @@ +package im.status.wallet; + +import org.bouncycastle.util.encoders.Hex; +import org.junit.jupiter.api.*; + +import javax.smartcardio.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@DisplayName("Test the Wallet Applet") +public class WalletAppletTest { + private static final String APPLET_AID = "53746174757357616C6C6574417070"; + private static final byte[] APPLET_AID_BYTES = Hex.decode(APPLET_AID); + + private static CardTerminal cardTerminal; + private static CardChannel apduChannel; + + @BeforeAll + static void initAll() throws CardException { + TerminalFactory tf = TerminalFactory.getDefault(); + + for (CardTerminal t : tf.terminals().list()) { + if (t.isCardPresent()) { + cardTerminal = t; + break; + } + } + + Card apduCard = cardTerminal.connect("T=1"); + apduChannel = apduCard.getBasicChannel(); + } + + @BeforeEach + void init() { + } + + @AfterEach + void tearDown() { + } + + @AfterAll + static void tearDownAll() { + + } + + @Test + @DisplayName("SELECT command") + void selectTest() throws CardException { + //TODO: as soon as secure channel is implemented, check that a public key is returned. + + ResponseAPDU response = WalletAppletCommandSet.select(apduChannel); + assertEquals(0x9000, response.getSW()); + } +}