use of com.github.dedis.popstellar.model.objects.Lao in project popstellar by dedis.
the class KeyManagerTest method popTokenRetrievingFailsWhenWalletFails.
@Test
public void popTokenRetrievingFailsWhenWalletFails() throws KeyException {
PoPToken token = Base64DataUtils.generatePoPToken();
// create LAO and RollCall
Lao lao = new Lao("lao", Base64DataUtils.generatePublicKey(), 54213424);
RollCall rollCall = new RollCall(lao.getId(), 5421364, "rollcall");
lao.updateRollCall(rollCall.getId(), rollCall);
KeyManager manager = new KeyManager(androidKeysetManager, wallet);
// Test with every possible errors
when(wallet.recoverKey(any(), any(), any())).thenThrow(new KeyGenerationException(new GeneralSecurityException()));
assertThrows(KeyGenerationException.class, () -> manager.getValidPoPToken(lao));
verify(wallet, times(1)).recoverKey(eq(lao.getId()), eq(rollCall.getId()), any());
reset(wallet);
when(wallet.recoverKey(any(), any(), any())).thenThrow(new UninitializedWalletException());
assertThrows(UninitializedWalletException.class, () -> manager.getValidPoPToken(lao));
verify(wallet, times(1)).recoverKey(eq(lao.getId()), eq(rollCall.getId()), any());
reset(wallet);
when(wallet.recoverKey(any(), any(), any())).thenThrow(new InvalidPoPTokenException(token));
assertThrows(InvalidPoPTokenException.class, () -> manager.getValidPoPToken(lao));
verify(wallet, times(1)).recoverKey(eq(lao.getId()), eq(rollCall.getId()), any());
}
Aggregations