Skip to content

Commit

Permalink
martinpaljak#153: Simple tests for DelegatedManagementHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorjohannson committed Feb 13, 2019
1 parent 21b1865 commit d3ba331
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/test/java/pro/javacard/gp/TestDelegatedManagementHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package pro.javacard.gp;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import javax.smartcardio.CommandAPDU;

import java.io.File;
import java.io.FileInputStream;
import java.security.PrivateKey;

import static pro.javacard.gp.GlobalPlatform.CLA_GP;
import static pro.javacard.gp.GlobalPlatform.INS_INSTALL;

public class TestDelegatedManagementHandler {

private PrivateKey key;

@Before
public void setUp() {
try (FileInputStream fin = new FileInputStream(new File("test.pem"))) {
key = GPCrypto.pem2PrivateKey(fin);
} catch (Exception e) {
e.printStackTrace();
}
}

@Test
public void testApplyToken() {
CommandAPDU command = new CommandAPDU(CLA_GP, INS_INSTALL, 0x02, 0x00, new byte[]{0});
DelegatedManagementHandler dmHandler = new DelegatedManagementHandler(key);
command = dmHandler.applyToken(command);
Assert.assertTrue(command.getData().length > 1);
}

@Test
public void testApplyEmptyToken() {
CommandAPDU command = new CommandAPDU(CLA_GP, INS_INSTALL, 0x02, 0x00, new byte[]{0});
DelegatedManagementHandler dmHandler = new DelegatedManagementHandler(null);
command = dmHandler.applyToken(command);
Assert.assertArrayEquals(command.getData(), new byte[]{0, 0});
}
}
15 changes: 15 additions & 0 deletions src/test/resources/test.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-----BEGIN RSA PRIVATE KEY-----
MIICXgIBAAKBgQCweHHNANr7knZY8c+vfdurFmFzAsLHQfnpr57HF6d7DvUddQiC
Edl2iJWRKKZRDA0jJt5M6rk6Fn8juWujI3zwDSy9vOKygiqpNzeRRUz57JObzgUY
AldoZCajs9wQssszvF229jDCgv9Z02IQqiwPP4W9Gy+Dx8tap0FwcA7STQIDAQAB
AoGAT8zniVDNtd2xbt9Kj41WfLOONbgV5I1NOgOUxWtI7TkCVuPJiSgRMqzpFc9Q
Bm5wsmitNhMe18m8jKcYqZkusY3K3CXYD7uNhpizAb9VQ/UepWV3+SoE2PXyQhIy
UIIQ22rGCjSSye87/zMU+eF4WHdgSttuwXZKMf82SxpcTHECQQDrPQY53YcKltpW
nD0yfcq0JxWEJyP/SrNnl/6pdFlIqdzT963cCA94wi/oi8X4ZXTwGmU0Ir0kesG9
fHIIdInvAkEAwAueWfhNeFx4i7tWZyBJFGXMtKg8WQiaoiPO2Gd8XGasdpHf0ucq
gVwIX+8pS6dZu9+PFdrOIHeazShP+kiTgwJBAM3uUjD9+WYPwXvosros3PLw9CkI
ir7Gil+587osnKy75xG41X61n7W7aW1OTzSwvLokoUwOzT3OKSTUeI9mVgkCQQCh
aKJ8587k/INsndWu81m4xR7aMBQYmLyuzf3JsKC7YKhPN6exMQ1ukBWR3AcPSOaI
mws9yRs5+oynJdyidWFVAkEAr+AGRuKKN4GD/rC/KtSDx7RhESkkONY/pIuQgVoH
hpF9NrULJNQvE5tL4d4SyaAF+E8DXv9FrXzFDoEOsXthoQ==
-----END RSA PRIVATE KEY-----

0 comments on commit d3ba331

Please sign in to comment.