add testing facilities

This commit is contained in:
Michele Balistreri 2017-09-25 14:16:26 +03:00
parent 6b600182dd
commit fe37968654
4 changed files with 81 additions and 9 deletions

View File

@ -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
}

View File

@ -1,8 +0,0 @@
mode_211
enable_trace
establish_context
card_connect
select -AID 53746174757357616C6C6574417070
send_apdu_nostop -APDU 80AA008000
card_disconnect
release_context

View File

@ -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);
}
}

View File

@ -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());
}
}