summaryrefslogtreecommitdiffstats
path: root/base/javacard/src/test/org/dogtagpki/javacard/MainTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'base/javacard/src/test/org/dogtagpki/javacard/MainTest.java')
-rw-r--r--base/javacard/src/test/org/dogtagpki/javacard/MainTest.java77
1 files changed, 77 insertions, 0 deletions
diff --git a/base/javacard/src/test/org/dogtagpki/javacard/MainTest.java b/base/javacard/src/test/org/dogtagpki/javacard/MainTest.java
new file mode 100644
index 000000000..fa2875a90
--- /dev/null
+++ b/base/javacard/src/test/org/dogtagpki/javacard/MainTest.java
@@ -0,0 +1,77 @@
+package org.dogtagpki.javacard;
+
+import com.licel.jcardsim.base.Simulator;
+import javacard.framework.AID;
+import org.bouncycastle.util.encoders.Hex;
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.smartcardio.*;
+import java.io.FileReader;
+import java.util.Properties;
+
+/**
+ * @author Endi Sukma Dewata
+ */
+public class MainTest {
+
+ @Test
+ public void testMainApplet() throws Exception {
+
+ Properties props = new Properties();
+ props.load(new FileReader("conf/jcardsim.cfg"));
+
+ String s = (String)props.get("com.licel.jcardsim.smartcardio.applet.0.AID");
+ byte[] aidBytes = Hex.decode(s);
+ AID appletAID = new AID(aidBytes, (short) 0, (byte) aidBytes.length);
+
+ Simulator simulator = new Simulator();
+
+ simulator.installApplet(appletAID, TestApplet.class);
+ simulator.selectApplet(appletAID);
+
+ // test NOP
+ ResponseAPDU response = simulator.transmitCommand(new CommandAPDU(0x01, 0x02, 0x00, 0x00));
+ Assert.assertEquals(0x9000, response.getSW());
+
+ // test hello world from card
+ response = simulator.transmitCommand(new CommandAPDU(0x01, 0x01, 0x00, 0x00));
+ Assert.assertEquals(0x9000, response.getSW());
+ Assert.assertEquals("TestApplet", new String(response.getData()));
+
+ // test echo
+ response = simulator.transmitCommand(new CommandAPDU(0x01, 0x01, 0x01, 0x00, ("Hello javacard world !").getBytes()));
+ Assert.assertEquals(0x9000, response.getSW());
+ Assert.assertEquals("Hello javacard world !", new String(response.getData()));
+ }
+
+ @Test
+ public void testProxyApplet() throws Exception {
+
+ Properties props = new Properties();
+ props.load(new FileReader("conf/jcardsim.cfg"));
+
+ String s = (String)props.get("com.licel.jcardsim.smartcardio.applet.1.AID");
+ byte[] aidBytes = Hex.decode(s);
+ AID appletAID = new AID(aidBytes, (short) 0, (byte) aidBytes.length);
+
+ Simulator simulator = new Simulator();
+
+ simulator.installApplet(appletAID, ProxyApplet.class);
+ simulator.selectApplet(appletAID);
+
+ // test NOP
+ ResponseAPDU response = simulator.transmitCommand(new CommandAPDU(0x01, 0x02, 0x00, 0x00));
+ Assert.assertEquals(0x9000, response.getSW());
+
+ // test hello world from card
+ response = simulator.transmitCommand(new CommandAPDU(0x01, 0x01, 0x00, 0x00));
+ Assert.assertEquals(0x9000, response.getSW());
+ Assert.assertEquals("ProxyApplet", new String(response.getData()));
+
+ // test echo
+ response = simulator.transmitCommand(new CommandAPDU(0x01, 0x01, 0x01, 0x00, ("Hello javacard world !").getBytes()));
+ Assert.assertEquals(0x9000, response.getSW());
+ Assert.assertEquals("Hello javacard world !", new String(response.getData()));
+ }
+}