2016-01-16 09:57:12 -05:00
|
|
|
import junit.framework.TestCase;
|
2016-01-23 12:16:57 -05:00
|
|
|
import meerkat.SimpleRegistry;
|
|
|
|
import meerkat.bulletinboard.SimpleBulletinBoardClient;
|
|
|
|
import meerkat.crypto.concrete.ECElGamalEncryption;
|
|
|
|
import meerkat.crypto.concrete.ECElGamalUtils;
|
|
|
|
import meerkat.protobuf.BulletinBoardAPI.*;
|
|
|
|
import meerkat.protobuf.ConcreteCrypto;
|
|
|
|
import meerkat.protobuf.Voting;
|
|
|
|
import org.factcenter.qilin.primitives.concrete.ECElGamal;
|
|
|
|
import org.factcenter.qilin.primitives.concrete.ECGroup;
|
|
|
|
import util.RegistryTags;
|
|
|
|
import util.SimpleRegistryCallBackHandler;
|
|
|
|
|
|
|
|
import java.math.BigInteger;
|
|
|
|
import java.security.spec.InvalidKeySpecException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Random;
|
2016-01-16 09:57:12 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Vladimir Eliezer Tokarev on 1/16/2016.
|
|
|
|
* Tests the Simple Registry contents
|
|
|
|
*
|
2016-01-23 12:16:57 -05:00
|
|
|
* NOTE: for most of this tests to pass there should run BulletinBoardServer
|
|
|
|
* and the sql server and it should be reachable on
|
|
|
|
* BULLETIN_BOARD_SERVER_ADDRESS location
|
2016-01-16 09:57:12 -05:00
|
|
|
*/
|
|
|
|
public class SimpleRegistryTest extends TestCase{
|
|
|
|
|
2016-01-23 12:16:57 -05:00
|
|
|
private ECElGamalEncryption signatory;
|
|
|
|
private SimpleBulletinBoardClient communicator;
|
|
|
|
private static String BULLETIN_BOARD_SERVER_ADDRESS = "http://localhost:3306";
|
|
|
|
private Random random = new Random(0); // Insecure deterministic random for testing.
|
|
|
|
private SimpleRegistryCallBackHandler handler;
|
|
|
|
|
|
|
|
private void ElGamalSetup(){
|
|
|
|
try {
|
|
|
|
ECGroup group = new ECGroup("secp256k1");
|
|
|
|
BigInteger sk = ECElGamal.generateSecretKey(group, random);
|
|
|
|
ECElGamal.SK key = new ECElGamal.SK(group, sk);
|
|
|
|
ConcreteCrypto.ElGamalPublicKey serializedPk = ECElGamalUtils.serializePk(group, key);
|
|
|
|
signatory = new ECElGamalEncryption();
|
|
|
|
signatory.init(serializedPk);
|
|
|
|
} catch (InvalidKeySpecException e) {
|
|
|
|
assertTrue(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void CommunicatorSetup(){
|
|
|
|
communicator = new SimpleBulletinBoardClient();
|
|
|
|
communicator.init(Voting.BulletinBoardClientParams.newBuilder()
|
|
|
|
.addBulletinBoardAddress(BULLETIN_BOARD_SERVER_ADDRESS)
|
|
|
|
.setMinRedundancy((float) 1.0)
|
|
|
|
.build());
|
|
|
|
}
|
|
|
|
|
|
|
|
private void RegistryAnswersHandlerSetup(){
|
|
|
|
handler = new SimpleRegistryCallBackHandler();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-01-16 09:57:12 -05:00
|
|
|
* Initialize SimpleRegistry object
|
|
|
|
*/
|
|
|
|
public void setUp(){
|
2016-01-23 12:16:57 -05:00
|
|
|
ElGamalSetup();
|
|
|
|
CommunicatorSetup();
|
|
|
|
RegistryAnswersHandlerSetup();
|
|
|
|
}
|
2016-01-16 09:57:12 -05:00
|
|
|
|
2016-01-23 12:16:57 -05:00
|
|
|
/**
|
|
|
|
* Checks if the creation of the registry have been successful
|
|
|
|
*/
|
|
|
|
public void testSimpleRegistryCreation(){
|
|
|
|
try {
|
|
|
|
SimpleRegistry registry = new SimpleRegistry(signatory, communicator);
|
|
|
|
}catch (Exception e){
|
|
|
|
assert false : "While creating the SimpleRegistry exception have been thrown " + e;
|
|
|
|
}
|
2016-01-16 09:57:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-01-23 12:16:57 -05:00
|
|
|
* Test that add voter creates new correct bulletin board message and adds the voter
|
2016-01-16 09:57:12 -05:00
|
|
|
*/
|
|
|
|
public void testAddVoter(){
|
2016-01-23 12:16:57 -05:00
|
|
|
List<String> ids = new ArrayList<>();
|
|
|
|
|
|
|
|
for (int i = 0 ; i < 10 ; i++ ){
|
|
|
|
ids.add("" + (10000000 + random.nextInt(90000000)));
|
|
|
|
}
|
|
|
|
SimpleRegistry registry = new SimpleRegistry(signatory, communicator);
|
2016-01-16 09:58:09 -05:00
|
|
|
|
2016-01-23 12:16:57 -05:00
|
|
|
// check that the callbacks have been called and the this been successful
|
|
|
|
for (String id : ids) {
|
|
|
|
registry.AddVoter(id, "some personal info", handler);
|
|
|
|
assertTrue(handler.ActionSucceed);
|
|
|
|
}
|
|
|
|
|
|
|
|
// check that the callbacks have been called exactly 10 times
|
|
|
|
assertEquals(10, SimpleRegistryCallBackHandler.counter);
|
|
|
|
|
|
|
|
|
|
|
|
// check that the server have the new voters data
|
|
|
|
for (String id : ids){
|
|
|
|
MessageFilterList.Builder filters = MessageFilterList.newBuilder()
|
|
|
|
.addFilter(MessageFilter.newBuilder().setTag(RegistryTags.ID_TAG + " " + id))
|
|
|
|
.addFilter(MessageFilter.newBuilder().setTag(RegistryTags.VOTER_ENTRY_TAG.toString()));
|
|
|
|
|
|
|
|
List<BulletinBoardMessage> messages = communicator.readMessages(filters.build());
|
|
|
|
assertTrue(messages != null);
|
|
|
|
}
|
2016-01-16 09:57:12 -05:00
|
|
|
}
|
|
|
|
|
2016-01-23 12:16:57 -05:00
|
|
|
|
2016-01-16 09:57:12 -05:00
|
|
|
/**
|
|
|
|
* Test that set voted posts creates correct bulletin board message and sets that the user have been voted
|
|
|
|
*/
|
|
|
|
public void testSetVoted(){
|
2016-01-23 12:16:57 -05:00
|
|
|
assertEquals(null, null);
|
2016-01-16 09:57:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that add to group creates correct bulletin board message and adds a user to a group
|
|
|
|
*/
|
|
|
|
public void testAddToGroup(){
|
2016-01-23 12:16:57 -05:00
|
|
|
assertEquals(null, null);
|
2016-01-16 09:57:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that remove from group creates correct bulletin board message and removes the user from a group
|
|
|
|
*/
|
|
|
|
public void testRemoveFromGroup(){
|
2016-01-23 12:16:57 -05:00
|
|
|
assertEquals(null, null);
|
2016-01-16 09:57:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that get groups retrieves the right groups the user are in
|
|
|
|
*/
|
|
|
|
public void testGetGroups(){
|
2016-01-23 12:16:57 -05:00
|
|
|
assertEquals(null, null);
|
2016-01-16 09:57:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that the personal data outputted about the user is right
|
|
|
|
*/
|
|
|
|
public void testGetPersonalIDDetails(){
|
2016-01-23 12:16:57 -05:00
|
|
|
assertEquals(null, null);
|
2016-01-16 09:57:12 -05:00
|
|
|
}
|
|
|
|
}
|