use of com.github.dedis.popstellar.utility.error.keys.InvalidPoPTokenException in project popstellar by dedis.
the class RollCallHandler method handleCloseRollCall.
/**
* Process a CloseRollCall message.
*
* @param context the HandlerContext of the message
* @param closeRollCall the message that was received
*/
public static void handleCloseRollCall(HandlerContext context, CloseRollCall closeRollCall) throws DataHandlingException {
LAORepository laoRepository = context.getLaoRepository();
Channel channel = context.getChannel();
MessageID messageId = context.getMessageId();
Lao lao = laoRepository.getLaoByChannel(channel);
Log.d(TAG, "handleCloseRollCall: " + channel);
String updateId = closeRollCall.getUpdateId();
String closes = closeRollCall.getCloses();
Optional<RollCall> rollCallOptional = lao.getRollCall(closes);
if (!rollCallOptional.isPresent()) {
Log.w(TAG, "Cannot find roll call to close : " + closes);
throw new InvalidDataException(closeRollCall, "close id", closes);
}
RollCall rollCall = rollCallOptional.get();
rollCall.setEnd(closeRollCall.getClosedAt());
rollCall.setId(updateId);
rollCall.getAttendees().addAll(closeRollCall.getAttendees());
rollCall.setState(EventState.CLOSED);
lao.updateRollCall(closes, rollCall);
lao.updateWitnessMessage(messageId, closeRollCallWitnessMessage(messageId, rollCall));
// Subscribe to the social media channels
try {
PoPToken token = context.getKeyManager().getValidPoPToken(lao, rollCall);
context.getMessageSender().subscribe(channel.subChannel("social").subChannel(token.getPublicKey().getEncoded())).subscribe();
} catch (InvalidPoPTokenException e) {
Log.i(TAG, "Received a close roll-call that you did not attend");
} catch (KeyException e) {
Log.e(TAG, "Could not retrieve your PoP Token to subscribe you to your social media channel", e);
}
}
use of com.github.dedis.popstellar.utility.error.keys.InvalidPoPTokenException 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