fix unit test
This commit is contained in:
@@ -210,7 +210,8 @@ public class SecurityTokenConnection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void determineTokenType() throws IOException {
|
@VisibleForTesting
|
||||||
|
void determineTokenType() throws IOException {
|
||||||
tokenType = mTransport.getTokenTypeIfAvailable();
|
tokenType = mTransport.getTokenTypeIfAvailable();
|
||||||
if (tokenType != null) {
|
if (tokenType != null) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -8,9 +8,12 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.InOrder;
|
import org.mockito.InOrder;
|
||||||
|
import org.mockito.internal.verification.VerificationModeFactory;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.shadows.ShadowLog;
|
import org.robolectric.shadows.ShadowLog;
|
||||||
import org.sufficientlysecure.keychain.KeychainTestRunner;
|
import org.sufficientlysecure.keychain.KeychainTestRunner;
|
||||||
|
import org.sufficientlysecure.keychain.securitytoken.SecurityTokenInfo.TokenType;
|
||||||
|
import org.sufficientlysecure.keychain.securitytoken.SecurityTokenInfo.TransportType;
|
||||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||||
|
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
@@ -23,19 +26,25 @@ import static org.mockito.Mockito.when;
|
|||||||
@RunWith(KeychainTestRunner.class)
|
@RunWith(KeychainTestRunner.class)
|
||||||
public class SecurityTokenConnectionTest {
|
public class SecurityTokenConnectionTest {
|
||||||
|
|
||||||
|
private Transport transport;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
ShadowLog.stream = System.out;
|
ShadowLog.stream = System.out;
|
||||||
|
|
||||||
|
transport = mock(Transport.class);
|
||||||
|
when(transport.getTransportType()).thenReturn(TransportType.USB);
|
||||||
|
when(transport.getTokenTypeIfAvailable()).thenReturn(TokenType.YUBIKEY_NEO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_connectToDevice() throws Exception {
|
public void test_connectToDevice() throws Exception {
|
||||||
Transport transport = mock(Transport.class);
|
|
||||||
SecurityTokenConnection securityTokenConnection =
|
SecurityTokenConnection securityTokenConnection =
|
||||||
new SecurityTokenConnection(transport, new Passphrase("123456"), new OpenPgpCommandApduFactory());
|
new SecurityTokenConnection(transport, new Passphrase("123456"), new OpenPgpCommandApduFactory());
|
||||||
|
String[] dialog = {
|
||||||
String[] dialog = { "00a4040006d27600012401", "9000",
|
"00a4040006d27600012401", // select openpgp applet
|
||||||
"00ca006e00",
|
"9000",
|
||||||
|
"00ca006e00", // get application related data
|
||||||
"6e81de4f10d27600012401020000060364311500005f520f0073000080000000000000000000007381b7c00af" +
|
"6e81de4f10d27600012401020000060364311500005f520f0073000080000000000000000000007381b7c00af" +
|
||||||
"00000ff04c000ff00ffc106010800001103c206010800001103c306010800001103c407007f7f7f03030" +
|
"00000ff04c000ff00ffc106010800001103c206010800001103c306010800001103c407007f7f7f03030" +
|
||||||
"3c53c4ec5fee25c4e89654d58cad8492510a89d3c3d8468da7b24e15bfc624c6a792794f15b7599915f7" +
|
"3c53c4ec5fee25c4e89654d58cad8492510a89d3c3d8468da7b24e15bfc624c6a792794f15b7599915f7" +
|
||||||
@@ -55,7 +64,6 @@ public class SecurityTokenConnectionTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_getTokenInfo() throws Exception {
|
public void test_getTokenInfo() throws Exception {
|
||||||
Transport transport = mock(Transport.class);
|
|
||||||
SecurityTokenConnection securityTokenConnection =
|
SecurityTokenConnection securityTokenConnection =
|
||||||
new SecurityTokenConnection(transport, new Passphrase("123456"), new OpenPgpCommandApduFactory());
|
new SecurityTokenConnection(transport, new Passphrase("123456"), new OpenPgpCommandApduFactory());
|
||||||
OpenPgpCapabilities openPgpCapabilities = new OpenPgpCapabilities(
|
OpenPgpCapabilities openPgpCapabilities = new OpenPgpCapabilities(
|
||||||
@@ -68,6 +76,7 @@ public class SecurityTokenConnectionTest {
|
|||||||
"000000000cd0c59cd0f2a59cd0af059cd0c95"
|
"000000000cd0c59cd0f2a59cd0af059cd0c95"
|
||||||
));
|
));
|
||||||
securityTokenConnection.setConnectionCapabilities(openPgpCapabilities);
|
securityTokenConnection.setConnectionCapabilities(openPgpCapabilities);
|
||||||
|
securityTokenConnection.determineTokenType();
|
||||||
|
|
||||||
String[] dialog = {
|
String[] dialog = {
|
||||||
"00ca006500",
|
"00ca006500",
|
||||||
@@ -98,6 +107,5 @@ public class SecurityTokenConnectionTest {
|
|||||||
CommandApdu command = CommandApdu.fromBytes(Hex.decode(dialog[i]));
|
CommandApdu command = CommandApdu.fromBytes(Hex.decode(dialog[i]));
|
||||||
inOrder.verify(transport).transceive(eq(command));
|
inOrder.verify(transport).transceive(eq(command));
|
||||||
}
|
}
|
||||||
inOrder.verifyNoMoreInteractions();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user