Search in sources :

Example 11 with RollCall

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());
}
Also used : MessageGeneral(com.github.dedis.popstellar.model.network.method.message.MessageGeneral) CloseRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.CloseRollCall) CreateRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.CreateRollCall) CloseRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.CloseRollCall) OpenRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.OpenRollCall) RollCall(com.github.dedis.popstellar.model.objects.RollCall) WitnessMessage(com.github.dedis.popstellar.model.objects.WitnessMessage) RollCallHandler.closeRollCallWitnessMessage(com.github.dedis.popstellar.utility.handler.data.RollCallHandler.closeRollCallWitnessMessage) RollCallHandler.createRollCallWitnessMessage(com.github.dedis.popstellar.utility.handler.data.RollCallHandler.createRollCallWitnessMessage) RollCallHandler.openRollCallWitnessMessage(com.github.dedis.popstellar.utility.handler.data.RollCallHandler.openRollCallWitnessMessage) Test(org.junit.Test)

Example 12 with RollCall

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());
}
Also used : PoPToken(com.github.dedis.popstellar.model.objects.security.PoPToken) RollCall(com.github.dedis.popstellar.model.objects.RollCall) Lao(com.github.dedis.popstellar.model.objects.Lao) Test(org.junit.Test) HiltAndroidTest(dagger.hilt.android.testing.HiltAndroidTest)

Example 13 with RollCall

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());
}
Also used : PoPToken(com.github.dedis.popstellar.model.objects.security.PoPToken) InvalidPoPTokenException(com.github.dedis.popstellar.utility.error.keys.InvalidPoPTokenException) GeneralSecurityException(java.security.GeneralSecurityException) RollCall(com.github.dedis.popstellar.model.objects.RollCall) KeyGenerationException(com.github.dedis.popstellar.utility.error.keys.KeyGenerationException) Lao(com.github.dedis.popstellar.model.objects.Lao) UninitializedWalletException(com.github.dedis.popstellar.utility.error.keys.UninitializedWalletException) Test(org.junit.Test) HiltAndroidTest(dagger.hilt.android.testing.HiltAndroidTest)

Aggregations

RollCall (com.github.dedis.popstellar.model.objects.RollCall)13 CloseRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.CloseRollCall)8 CreateRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.CreateRollCall)8 OpenRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.OpenRollCall)8 Lao (com.github.dedis.popstellar.model.objects.Lao)8 MessageGeneral (com.github.dedis.popstellar.model.network.method.message.MessageGeneral)5 LAORepository (com.github.dedis.popstellar.repository.LAORepository)5 Test (org.junit.Test)5 Channel (com.github.dedis.popstellar.model.objects.Channel)4 PoPToken (com.github.dedis.popstellar.model.objects.security.PoPToken)4 WitnessMessage (com.github.dedis.popstellar.model.objects.WitnessMessage)3 MessageID (com.github.dedis.popstellar.model.objects.security.MessageID)3 KeyException (com.github.dedis.popstellar.utility.error.keys.KeyException)3 RollCallHandler.closeRollCallWitnessMessage (com.github.dedis.popstellar.utility.handler.data.RollCallHandler.closeRollCallWitnessMessage)3 RollCallHandler.createRollCallWitnessMessage (com.github.dedis.popstellar.utility.handler.data.RollCallHandler.createRollCallWitnessMessage)3 RollCallHandler.openRollCallWitnessMessage (com.github.dedis.popstellar.utility.handler.data.RollCallHandler.openRollCallWitnessMessage)3 CreateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.CreateLao)2 LAOState (com.github.dedis.popstellar.repository.LAOState)2 InvalidDataException (com.github.dedis.popstellar.utility.error.InvalidDataException)2 InvalidPoPTokenException (com.github.dedis.popstellar.utility.error.keys.InvalidPoPTokenException)2