Search in sources :

Example 51 with GuidEntry

use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.

the class GuidImport method parse.

@Override
public void parse(String commandText) throws Exception {
    try {
        StringTokenizer st = new StringTokenizer(commandText.trim());
        if (st.countTokens() != 1) {
            wrongArguments();
            return;
        }
        String filename = st.nextToken();
        File f = new File(filename);
        GuidEntry guidEntry;
        try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(f))) {
            guidEntry = new GuidEntry(ois);
            ois.close();
        }
        KeyPairUtils.saveKeyPair(module.getGnsInstance(), guidEntry.getEntityName(), guidEntry.getGuid(), new KeyPair(guidEntry.getPublicKey(), guidEntry.getPrivateKey()));
        console.printString("Keys for " + guidEntry.getEntityName() + " read from " + filename + " and saved in local preferences.");
        console.printNewline();
    } catch (IOException | EncryptionException e) {
        console.printString("Failed to load keys ( " + e + ")\n");
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) KeyPair(java.security.KeyPair) EncryptionException(edu.umass.cs.gnscommon.exceptions.client.EncryptionException) IOException(java.io.IOException) File(java.io.File) GuidEntry(edu.umass.cs.gnsclient.client.util.GuidEntry) FileInputStream(java.io.FileInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 52 with GuidEntry

use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.

the class AccountVerify method parse.

@Override
public void parse(String commandText) throws Exception {
    try {
        GNSClientCommands client = module.getGnsClient();
        StringTokenizer st = new StringTokenizer(commandText.trim());
        if (st.countTokens() != 2) {
            wrongArguments();
            return;
        }
        String alias = st.nextToken();
        GuidEntry guid = KeyPairUtils.getGuidEntry(module.getGnsInstance(), alias);
        if (guid == null) {
            printString("Unable to retrieve GUID for alias " + alias + "\n");
            return;
        }
        String code = st.nextToken();
        try {
            if (client.accountGuidVerify(guid, code).startsWith(GNSProtocol.OK_RESPONSE.toString())) {
                printString("Account verified.\n");
                module.setAccountVerified(true);
                return;
            }
        // this happens if it was already verified, but we didn't notice
        } catch (VerificationException e) {
            module.setAccountVerified(true);
            printString("Account already verified" + "\n");
            return;
        } catch (Exception e) {
            printString("Account not verified: " + e + "\n");
        }
    } catch (Exception e) {
        console.printString("Failed to access GNS ( " + e + ")\n");
    }
    module.setAccountVerified(false);
}
Also used : StringTokenizer(java.util.StringTokenizer) GNSClientCommands(edu.umass.cs.gnsclient.client.GNSClientCommands) VerificationException(edu.umass.cs.gnscommon.exceptions.client.VerificationException) GuidEntry(edu.umass.cs.gnsclient.client.util.GuidEntry) VerificationException(edu.umass.cs.gnscommon.exceptions.client.VerificationException)

Example 53 with GuidEntry

use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.

the class ServerIntegrationTest method test_190_Substitute.

/**
   * Tests different DB substitute methods.
   */
@Test
public void test_190_Substitute() {
    //CHECKED FOR VALIDITY
    String testSubstituteGuid = "testSubstituteGUID" + RandomString.randomString(12);
    String field = "people";
    GuidEntry testEntry = null;
    try {
        // Utils.clearTestGuids(client);
        // System.out.println("cleared old GUIDs");
        testEntry = clientCommands.guidCreate(masterGuid, testSubstituteGuid);
    } catch (Exception e) {
        failWithStackTrace("Exception during init: ", e);
    }
    try {
        clientCommands.fieldAppendOrCreateList(testEntry.getGuid(), field, new JSONArray(Arrays.asList("Frank", "Joe", "Sally", "Rita")), testEntry);
    } catch (IOException | ClientException e) {
        failWithStackTrace("Exception during create: ", e);
    }
    try {
        HashSet<String> expected = new HashSet<>(Arrays.asList("Frank", "Joe", "Sally", "Rita"));
        HashSet<String> actual = JSONUtils.JSONArrayToHashSet(clientCommands.fieldReadArray(testEntry.getGuid(), field, testEntry));
        Assert.assertEquals(expected, actual);
    } catch (Exception e) {
        failWithStackTrace("Exception when we were not expecting it: ", e);
    }
    try {
        clientCommands.fieldSubstitute(testEntry.getGuid(), field, "Christy", "Sally", testEntry);
    } catch (Exception e) {
        failWithStackTrace("Exception during substitute: ", e);
    }
    try {
        HashSet<String> expected = new HashSet<>(Arrays.asList("Frank", "Joe", "Christy", "Rita"));
        HashSet<String> actual = JSONUtils.JSONArrayToHashSet(clientCommands.fieldReadArray(testEntry.getGuid(), field, testEntry));
        Assert.assertEquals(expected, actual);
    } catch (Exception e) {
        failWithStackTrace("Exception when we were not expecting it: ", e);
    }
}
Also used : JSONArray(org.json.JSONArray) RandomString(edu.umass.cs.gnscommon.utils.RandomString) IOException(java.io.IOException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) BasicGuidEntry(edu.umass.cs.gnsclient.client.util.BasicGuidEntry) GuidEntry(edu.umass.cs.gnsclient.client.util.GuidEntry) EncryptionException(edu.umass.cs.gnscommon.exceptions.client.EncryptionException) FieldNotFoundException(edu.umass.cs.gnscommon.exceptions.client.FieldNotFoundException) JSONException(org.json.JSONException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) HashSet(java.util.HashSet) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest) Test(org.junit.Test)

Example 54 with GuidEntry

use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.

the class CreateGuidTest method test_01_CreateEntity.

/**
   *
   */
@Test
public void test_01_CreateEntity() {
    String alias = "testGUID" + RandomString.randomString(12);
    GuidEntry guidEntry = null;
    try {
        guidEntry = clientCommands.guidCreate(masterGuid, alias);
    } catch (ClientException | IOException e) {
        Utils.failWithStackTrace("Exception while creating guid: " + e);
    }
    Assert.assertNotNull(guidEntry);
    Assert.assertEquals(alias, guidEntry.getEntityName());
    try {
        clientCommands.guidRemove(masterGuid, guidEntry.getGuid());
    } catch (ClientException | IOException e) {
        Utils.failWithStackTrace("Exception while creating guid: " + e);
    }
}
Also used : RandomString(edu.umass.cs.gnscommon.utils.RandomString) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) IOException(java.io.IOException) GuidEntry(edu.umass.cs.gnsclient.client.util.GuidEntry) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest) Test(org.junit.Test)

Example 55 with GuidEntry

use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.

the class CreateUpdateRemoveRepeatTest method test_001_CreateAndUpdate.

/**
   * @throws Exception
   */
@Test
@Repeat(times = REPEAT)
public void test_001_CreateAndUpdate() throws Exception {
    // CHECKED FOR VALIDITY
    String alias = "testGUID" + RandomString.randomString(12);
    String createdGUID = client.execute(GNSCommand.guidCreate(masterGuid, alias)).getResultString();
    GuidEntry createdGUIDEntry = GuidUtils.getGUIDKeys(alias);
    Assert.assertEquals(alias, createdGUIDEntry.entityName);
    Assert.assertEquals(createdGUID, GuidUtils.getGUIDKeys(alias).guid);
    String key = "key1", value = "value1";
    client.execute(GNSCommand.update(createdGUID, new JSONObject().put(key, value), createdGUIDEntry));
    Assert.assertEquals(value, client.execute(GNSCommand.fieldRead(createdGUIDEntry, key)).getResultMap().get(key));
    client.execute(GNSCommand.guidRemove(masterGuid, createdGUID));
}
Also used : JSONObject(org.json.JSONObject) RandomString(edu.umass.cs.gnscommon.utils.RandomString) GuidEntry(edu.umass.cs.gnsclient.client.util.GuidEntry) Test(org.junit.Test) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest) Repeat(edu.umass.cs.utils.Repeat)

Aggregations

GuidEntry (edu.umass.cs.gnsclient.client.util.GuidEntry)134 ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)87 IOException (java.io.IOException)85 Test (org.junit.Test)69 DefaultGNSTest (edu.umass.cs.gnsserver.utils.DefaultGNSTest)61 RandomString (edu.umass.cs.gnscommon.utils.RandomString)54 BasicGuidEntry (edu.umass.cs.gnsclient.client.util.BasicGuidEntry)46 JSONException (org.json.JSONException)45 JSONArray (org.json.JSONArray)36 GNSClientCommands (edu.umass.cs.gnsclient.client.GNSClientCommands)28 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)18 EncryptionException (edu.umass.cs.gnscommon.exceptions.client.EncryptionException)15 DuplicateNameException (edu.umass.cs.gnscommon.exceptions.client.DuplicateNameException)14 StringTokenizer (java.util.StringTokenizer)13 JSONObject (org.json.JSONObject)12 FieldNotFoundException (edu.umass.cs.gnscommon.exceptions.client.FieldNotFoundException)11 FileNotFoundException (java.io.FileNotFoundException)11 HashSet (java.util.HashSet)10 FileInputStream (java.io.FileInputStream)8 Repeat (edu.umass.cs.utils.Repeat)7