use of com.github.dedis.popstellar.model.objects.RollCall in project popstellar by dedis.
the class RollCallHandlerTest method testHandleCloseRollCall.
@Test
public void testHandleCloseRollCall() throws DataHandlingException {
// Create the close Roll Call message
CloseRollCall closeRollCall = new CloseRollCall(CREATE_LAO.getId(), rollCall.getId(), rollCall.getEnd(), new ArrayList<>());
MessageGeneral message = new MessageGeneral(SENDER_KEY, closeRollCall, GSON);
// Call the message handler
messageHandler.handleMessage(laoRepository, messageSender, LAO_CHANNEL, message);
// Check the Roll Call is present with state CLOSED and the correct ID
Optional<RollCall> rollCallOpt = laoRepository.getLaoByChannel(LAO_CHANNEL).getRollCall(closeRollCall.getUpdateId());
assertTrue(rollCallOpt.isPresent());
assertEquals(EventState.CLOSED, rollCallOpt.get().getState());
assertEquals(closeRollCall.getUpdateId(), rollCallOpt.get().getId());
// Check the WitnessMessage has been created
Optional<WitnessMessage> witnessMessage = laoRepository.getLaoByChannel(LAO_CHANNEL).getWitnessMessage(message.getMessageId());
assertTrue(witnessMessage.isPresent());
// Check the Witness message contains the expected title and description
WitnessMessage expectedMessage = closeRollCallWitnessMessage(message.getMessageId(), rollCallOpt.get());
assertEquals(expectedMessage.getTitle(), witnessMessage.get().getTitle());
assertEquals(expectedMessage.getDescription(), witnessMessage.get().getDescription());
}
use of com.github.dedis.popstellar.model.objects.RollCall in project popstellar by dedis.
the class KeyManagerTest method popTokenRetrievingWorks.
@Test
public void popTokenRetrievingWorks() throws KeyException {
PoPToken token = Base64DataUtils.generatePoPToken();
when(wallet.recoverKey(any(), any(), any())).thenReturn(token);
// create LAO and RollCalls
Lao lao = new Lao("lao", Base64DataUtils.generatePublicKey(), 54213424);
RollCall rollCall1 = new RollCall(lao.getId(), 5421364, "rollcall1");
RollCall rollCall2 = new RollCall(lao.getId(), 5421363, "rollcall2");
lao.updateRollCall(rollCall1.getId(), rollCall1);
lao.updateRollCall(rollCall2.getId(), rollCall2);
KeyManager manager = new KeyManager(androidKeysetManager, wallet);
assertEquals(token, manager.getValidPoPToken(lao));
assertEquals(token, manager.getValidPoPToken(lao, rollCall1));
// make sure that rollcall1 was taken and not rollcall2 as the oldest is rollcall 1
verify(wallet, atLeast(1)).recoverKey(eq(lao.getId()), eq(rollCall1.getId()), any());
}
use of com.github.dedis.popstellar.model.objects.RollCall 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