use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.
the class AccountCreate method parse.
@Override
public void parse(String commandText) throws Exception {
StringTokenizer st = new StringTokenizer(commandText.trim());
if ((st.countTokens() != 2)) {
wrongArguments();
return;
}
String aliasName = st.nextToken();
String password = st.nextToken();
try {
GNSClientCommands gnsClient = module.getGnsClient();
try {
gnsClient.lookupGuid(aliasName);
if (!module.isSilent()) {
printString("Alias " + aliasName + " already exists.\n");
}
return;
} catch (Exception expected) {
// The alias does not exists, that's good, let's create it
}
GuidEntry myGuid = KeyPairUtils.getGuidEntry(module.getGnsInstance(), aliasName);
if (myGuid != null) {
try {
PublicKey pk = gnsClient.publicKeyLookupFromGuid(myGuid.getGuid());
if (myGuid.getPublicKey().equals(pk)) {
// We already have the key but the alias is missing in the GNS,
// re-add the alias
printString("Alias info found locally but missing in GNS, re-adding alias to the GNS\n");
gnsClient.guidCreate(myGuid, aliasName);
} else {
printString("Old certificates found locally and not matching key in GNS, deleting local keys\n");
KeyPairUtils.removeKeyPair(module.getGnsInstance(), aliasName);
}
} catch (InvalidGuidException e) {
KeyPairUtils.removeKeyPair(module.getGnsInstance(), aliasName);
}
}
myGuid = gnsClient.accountGuidCreate(aliasName, password);
if (!module.isSilent()) {
printString("Created an account with GUID " + myGuid.getGuid() + ".\n");
}
if (module.getCurrentGuid() == null) {
module.setCurrentGuidAndCheckForVerified(myGuid);
if (KeyPairUtils.getDefaultGuidEntry(module.getGnsInstance()) == null) {
KeyPairUtils.setDefaultGuidEntry(module.getGnsInstance(), aliasName);
module.printString(aliasName + " saved as default GUID \n");
}
module.setPromptString(ConsoleModule.CONSOLE_PROMPT + aliasName + ">");
}
} catch (Exception e) {
e.printStackTrace();
printString("Failed to create new guid ( " + e + ")\n");
}
}
use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.
the class ServerIntegrationTest method test_400_SetFieldNull.
/**
* Tests fieldSetNull.
*
* @throws Exception
*/
@Test
public void test_400_SetFieldNull() throws Exception {
//CHECKED FOR VALIDITY
String field = "fieldToSetToNull";
GuidEntry westyEntry = clientCommands.guidCreate(masterGuid, "westy400" + RandomString.randomString(12));
System.out.print("Created: " + westyEntry);
try {
clientCommands.fieldCreateOneElementList(westyEntry.getGuid(), field, "work", westyEntry);
} catch (IOException | ClientException e) {
failWithStackTrace("Exception while creating the field: ", e);
}
try {
// read my own field
Assert.assertEquals("work", clientCommands.fieldReadArrayFirstElement(westyEntry.getGuid(), field, westyEntry));
} catch (Exception e) {
failWithStackTrace("Exception while reading the field " + field + ": ", e);
}
try {
clientCommands.fieldSetNull(westyEntry.getGuid(), field, westyEntry);
} catch (IOException | ClientException e) {
failWithStackTrace("Exception while setting field to null field: ", e);
}
try {
Assert.assertEquals(null, clientCommands.fieldReadArrayFirstElement(westyEntry.getGuid(), field, westyEntry));
} catch (Exception e) {
failWithStackTrace("Exception while reading the field " + field + ": ", e);
}
}
use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.
the class ServerIntegrationTest method test_320_GeoSpatialSelect.
/**
* Tests that selectNear and selectWithin work.
*/
@Test
public void test_320_GeoSpatialSelect() {
/* The SELECT tests will need extra long timeouts and some waitSettle commands
* between writes and the SELECTs since the SELECTs are not force-coordinatable
* and implementing force-coordination would be very complicated, and may not
* worth the trouble since it would only be used for testing purposes.
*
* DONE: Add in waitSettle() between client.setLocation and the select call
* for this test and any other similar ones.
*/
try {
for (int cnt = 0; cnt < 5; cnt++) {
GuidEntry testEntry = clientCommands.guidCreate(masterGuid, "geoTest-" + RandomString.randomString(12));
// save them so we can delete them later
CREATED_GUIDS.add(testEntry);
clientCommands.setLocation(testEntry, 0.0, 0.0);
//See comment under the method header.
waitSettle(SELECT_WAIT);
// arun: added this but unclear why we should need this at all
JSONArray location = clientCommands.getLocation(testEntry.getGuid(), testEntry);
assert (location.getDouble(0) == 0.0 && location.getDouble(1) == 0.0);
}
} catch (ClientException | IOException | JSONException e) {
failWithStackTrace("Exception while writing fields for GeoSpatialSelect: ", e);
}
// select near
try {
JSONArray loc = new JSONArray();
loc.put(1.0);
loc.put(1.0);
JSONArray result = clientCommands.selectNear(GNSProtocol.LOCATION_FIELD_NAME.toString(), loc, 2000000.0);
// best we can do should be at least 5, but possibly more objects in
// results
Assert.assertThat(result.length(), Matchers.greaterThanOrEqualTo(5));
} catch (JSONException | ClientException | IOException e) {
failWithStackTrace("Exception executing selectNear: ", e);
}
// select within
try {
JSONArray rect = new JSONArray();
JSONArray upperLeft = new JSONArray();
upperLeft.put(1.0);
upperLeft.put(1.0);
JSONArray lowerRight = new JSONArray();
lowerRight.put(-1.0);
lowerRight.put(-1.0);
rect.put(upperLeft);
rect.put(lowerRight);
JSONArray result = clientCommands.selectWithin(GNSProtocol.LOCATION_FIELD_NAME.toString(), rect);
// best we can do should be at least 5, but possibly more objects in
// results
Assert.assertThat(result.length(), Matchers.greaterThanOrEqualTo(5));
} catch (JSONException | ClientException | IOException e) {
failWithStackTrace("Exception executing selectWithin: ", e);
}
try {
for (GuidEntry guid : CREATED_GUIDS) {
clientCommands.guidRemove(masterGuid, guid.getGuid());
}
CREATED_GUIDS.clear();
} catch (ClientException | IOException e) {
failWithStackTrace("Exception during cleanup: " + e);
}
}
use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.
the class ServerIntegrationTest method test_210_GroupTests.
/**
* A set of tests for checking Group functionality.
*
* @throws Exception
*/
@Test
public void test_210_GroupTests() throws Exception {
GuidEntry westyEntry = GuidUtils.lookupOrCreateGuid(clientCommands, masterGuid, "westy210" + RandomString.randomString(6));
GuidEntry samEntry = GuidUtils.lookupOrCreateGuid(clientCommands, masterGuid, "sam210" + RandomString.randomString(6));
List<GuidEntry> entries = test_210_GroupCreate();
GuidEntry guidToDeleteEntry = entries.get(0);
GuidEntry mygroupEntry = entries.get(1);
test_211_GroupAdd(westyEntry, samEntry, mygroupEntry, guidToDeleteEntry);
test_212_GroupRemoveGuid(guidToDeleteEntry, mygroupEntry);
GuidEntry groupAccessUserEntry = test_220_GroupAndACLCreateGuids(mygroupEntry);
test_221_GroupAndACLTestBadAccess(groupAccessUserEntry, westyEntry);
test_222_GroupAndACLTestGoodAccess(groupAccessUserEntry, westyEntry);
test_223_GroupAndACLTestRemoveGuid(westyEntry, mygroupEntry);
test_224_GroupAndACLTestRemoveGuidCheck(westyEntry, mygroupEntry);
}
use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.
the class ServerIntegrationTest method test_551_QueryRemovePreviousTestFields.
/**
* Remove any old fields from previous tests for group tests.
*
* @param groupTestFieldName
*/
public void test_551_QueryRemovePreviousTestFields(String groupTestFieldName) {
// find all the guids that have our field and remove it from them
try {
String query = "~" + groupTestFieldName + " : {$exists: true}";
JSONArray result = clientCommands.selectQuery(query);
for (int i = 0; i < result.length(); i++) {
BasicGuidEntry guidInfo = new BasicGuidEntry(clientCommands.lookupGuidRecord(result.getString(i)));
GuidEntry guidEntry = GuidUtils.lookupGuidEntryFromDatabase(clientCommands, guidInfo.getEntityName());
System.out.println("Removing from " + guidEntry.getEntityName());
clientCommands.fieldRemove(guidEntry, groupTestFieldName);
}
} catch (Exception e) {
failWithStackTrace("Trying to remove previous test's fields: ", e);
}
}
Aggregations