use of com.github.dedis.popstellar.model.objects.Lao in project popstellar by dedis.
the class ChirpHandler method handleDeleteChirp.
/**
* process a DeleteChirp message.
*
* @param context the HandlerContext of the message
* @param deleteChirp the data of the message that was received
*/
public static void handleDeleteChirp(HandlerContext context, DeleteChirp deleteChirp) throws DataHandlingException {
LAORepository laoRepository = context.getLaoRepository();
Channel channel = context.getChannel();
Lao lao = laoRepository.getLaoByChannel(channel);
Optional<Chirp> chirpOptional = lao.getChirp(deleteChirp.getChirpId());
Chirp chirp;
if (!chirpOptional.isPresent()) {
throw new InvalidMessageIdException(deleteChirp, deleteChirp.getChirpId());
}
chirp = chirpOptional.get();
if (chirp.getIsDeleted()) {
Log.d(TAG, "The chirp is already deleted");
} else {
chirp.setIsDeleted(true);
chirp.setText("");
}
}
use of com.github.dedis.popstellar.model.objects.Lao in project popstellar by dedis.
the class ConsensusHandlerTest method setup.
@Before
public void setup() throws GeneralSecurityException, DataHandlingException, IOException {
lenient().when(keyManager.getMainKeyPair()).thenReturn(ORGANIZER_KEY);
lenient().when(keyManager.getMainPublicKey()).thenReturn(ORGANIZER);
when(messageSender.subscribe(any())).then(args -> Completable.complete());
laoRepository = new LAORepository();
messageHandler = new MessageHandler(DataRegistryModule.provideDataRegistry(), keyManager);
lao = new Lao(LAO_ID);
laoRepository.getLaoById().put(LAO_ID, new LAOState(lao));
MessageGeneral createLaoMessage = getMsg(ORGANIZER_KEY, CREATE_LAO);
messageHandler.handleMessage(laoRepository, messageSender, lao.getChannel(), createLaoMessage);
electMsg = getMsg(NODE_2_KEY, elect);
messageId = electMsg.getMessageId();
}
use of com.github.dedis.popstellar.model.objects.Lao in project popstellar by dedis.
the class LaoHandlerTest method setup.
@Before
public void setup() throws GeneralSecurityException, IOException {
lenient().when(keyManager.getMainKeyPair()).thenReturn(SENDER_KEY);
lenient().when(keyManager.getMainPublicKey()).thenReturn(SENDER);
when(messageSender.subscribe(any())).then(args -> Completable.complete());
laoRepository = new LAORepository();
messageHandler = new MessageHandler(DataRegistryModule.provideDataRegistry(), keyManager);
// Create one LAO and add it to the LAORepository
lao = new Lao(CREATE_LAO.getName(), CREATE_LAO.getOrganizer(), CREATE_LAO.getCreation());
lao.setLastModified(lao.getCreation());
laoRepository.getLaoById().put(lao.getId(), new LAOState(lao));
laoRepository.setAllLaoSubject();
// Add the CreateLao message to the LAORepository
createLaoMessage = new MessageGeneral(SENDER_KEY, CREATE_LAO, GSON);
laoRepository.getMessageById().put(createLaoMessage.getMessageId(), createLaoMessage);
}
use of com.github.dedis.popstellar.model.objects.Lao in project popstellar by dedis.
the class RollCallHandlerTest method setup.
@Before
public void setup() throws GeneralSecurityException, IOException, KeyException {
lenient().when(keyManager.getMainKeyPair()).thenReturn(SENDER_KEY);
lenient().when(keyManager.getMainPublicKey()).thenReturn(SENDER);
lenient().when(keyManager.getValidPoPToken(any(), any())).thenReturn(POP_TOKEN);
when(messageSender.subscribe(any())).then(args -> Completable.complete());
laoRepository = new LAORepository();
messageHandler = new MessageHandler(DataRegistryModule.provideDataRegistry(), keyManager);
// Create one LAO
Lao lao = new Lao(CREATE_LAO.getName(), CREATE_LAO.getOrganizer(), CREATE_LAO.getCreation());
lao.setLastModified(lao.getCreation());
// Create one Roll Call and add it to the LAO
rollCall = new RollCall(lao.getId(), Instant.now().getEpochSecond(), "roll call 1");
rollCall.setLocation("EPFL");
lao.setRollCalls(new HashMap<String, RollCall>() {
{
put(rollCall.getId(), rollCall);
}
});
// Add the LAO to the LAORepository
laoRepository.getLaoById().put(lao.getId(), new LAOState(lao));
laoRepository.setAllLaoSubject();
// Add the CreateLao message to the LAORepository
MessageGeneral createLaoMessage = new MessageGeneral(SENDER_KEY, CREATE_LAO, GSON);
laoRepository.getMessageById().put(createLaoMessage.getMessageId(), createLaoMessage);
}
use of com.github.dedis.popstellar.model.objects.Lao 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());
}
Aggregations