Search in sources :

Example 51 with ClientException

use of edu.umass.cs.gnscommon.exceptions.client.ClientException in project GNS by MobilityFirst.

the class UnsignedReadTest method test_259_UnsignedReadFailRead.

/**
   * Attempt a read that should fail because ENTIRE_RECORD was removed.
   */
@Test
public void test_259_UnsignedReadFailRead() {
    try {
        try {
            String result = clientCommands.fieldRead(unsignedReadTestGuid.getGuid(), unreadAbleReadFieldName, null);
            Utils.failWithStackTrace("Result of read of westy's " + unreadAbleReadFieldName + " in " + unsignedReadTestGuid.entityName + " as world readable was " + result + " which is wrong because it should have been rejected in UnsignedRead.");
        } catch (ClientException e) {
        }
    } catch (Exception e) {
        Utils.failWithStackTrace("Exception while testing for denied unsigned access in UnsignedRead: ", e);
    }
}
Also used : RandomString(edu.umass.cs.gnscommon.utils.RandomString) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) IOException(java.io.IOException) JSONException(org.json.JSONException) Test(org.junit.Test) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest)

Example 52 with ClientException

use of edu.umass.cs.gnscommon.exceptions.client.ClientException in project GNS by MobilityFirst.

the class MultiFieldLookupTest method test_01_JSONUpdate.

/**
   *
   */
@Test
public void test_01_JSONUpdate() {
    try {
        westyEntry = clientCommands.guidCreate(masterGuid, "westy" + RandomString.randomString(12));
        System.out.println("Created: " + westyEntry);
    } catch (ClientException | IOException e) {
        Utils.failWithStackTrace("Exception when we were not expecting it: " + e);
    }
    try {
        JSONObject json = new JSONObject();
        json.put("name", "frank");
        json.put("occupation", "busboy");
        json.put("location", "work");
        json.put("friends", new ArrayList<>(Arrays.asList("Joe", "Sam", "Billy")));
        JSONObject subJson = new JSONObject();
        subJson.put("einy", "floop");
        subJson.put("meiny", "bloop");
        json.put("gibberish", subJson);
        clientCommands.update(westyEntry, json);
    } catch (JSONException | IOException | ClientException e) {
        Utils.failWithStackTrace("Exception while updating JSON: " + e);
    }
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) IOException(java.io.IOException) Test(org.junit.Test) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest)

Example 53 with ClientException

use of edu.umass.cs.gnscommon.exceptions.client.ClientException in project GNS by MobilityFirst.

the class RemoveGuidTest method test_10_RemoveGuidUsingAccount.

/**
   *
   */
@Test
public void test_10_RemoveGuidUsingAccount() {
    String guidName = "testGUID" + RandomString.randomString(12);
    GuidEntry guid = null;
    try {
        guid = clientCommands.guidCreate(masterGuid, guidName);
    } catch (ClientException | IOException e) {
        Utils.failWithStackTrace("Exception while creating testGuid: " + e);
    }
    if (guid != null) {
        System.out.println("testGuid is " + guid.toString());
        try {
            clientCommands.guidRemove(masterGuid, guid.getGuid());
        } catch (ClientException | IOException e) {
            Utils.failWithStackTrace("Exception while removing testGuid (" + guid.toString() + "): " + e);
        }
        try {
            clientCommands.lookupGuidRecord(guid.getGuid());
            Utils.failWithStackTrace("Lookup testGuid should have throw an exception.");
        } catch (ClientException e) {
        } catch (IOException e) {
            Utils.failWithStackTrace("Exception while doing Lookup testGuid: " + 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 54 with ClientException

use of edu.umass.cs.gnscommon.exceptions.client.ClientException in project GNS by MobilityFirst.

the class UnsignedReadTest method test_263_UnsignedReadFailMissingField.

/**
   *
   */
@Test
public void test_263_UnsignedReadFailMissingField() {
    String missingFieldName = "missingField" + RandomString.randomString(12);
    try {
        try {
            String result = clientCommands.fieldRead(unsignedReadTestGuid.getGuid(), missingFieldName, null);
            Utils.failWithStackTrace("Result of read of test guid's nonexistant field " + missingFieldName + " in " + unsignedReadTestGuid.entityName + " as world readable was " + result + " which is wrong because it should have failed.");
        } catch (ClientException e) {
        // The normal result
        }
    } catch (Exception e) {
        Utils.failWithStackTrace("Exception while testing for denied unsigned access in UnsignedRead: ", e);
    }
}
Also used : RandomString(edu.umass.cs.gnscommon.utils.RandomString) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) IOException(java.io.IOException) JSONException(org.json.JSONException) Test(org.junit.Test) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest)

Example 55 with ClientException

use of edu.umass.cs.gnscommon.exceptions.client.ClientException in project GNS by MobilityFirst.

the class UnsignedReadTest method test_251_UnsignedReadDefaultAccountGuidRead.

/**
   * Tests for the default ACL list working with unsigned read.
   * Attempts to read the field.
   */
@Test
public void test_251_UnsignedReadDefaultAccountGuidRead() {
    try {
        String response = clientCommands.fieldRead(unsignedReadAccountGuid.getGuid(), "aRandomFieldForUnsignedRead", null);
        Assert.assertEquals("aRandomValue", response);
    } catch (ClientException | IOException e) {
        Utils.failWithStackTrace("Exception writing field UnsignedReadDefaultMasterWrite: ", e);
    }
}
Also used : RandomString(edu.umass.cs.gnscommon.utils.RandomString) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) IOException(java.io.IOException) Test(org.junit.Test) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest)

Aggregations

ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)239 IOException (java.io.IOException)215 Test (org.junit.Test)134 JSONException (org.json.JSONException)126 DefaultGNSTest (edu.umass.cs.gnsserver.utils.DefaultGNSTest)125 RandomString (edu.umass.cs.gnscommon.utils.RandomString)113 JSONArray (org.json.JSONArray)74 GuidEntry (edu.umass.cs.gnsclient.client.util.GuidEntry)71 JSONObject (org.json.JSONObject)59 GNSClientCommands (edu.umass.cs.gnsclient.client.GNSClientCommands)40 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)37 StringTokenizer (java.util.StringTokenizer)30 EncryptionException (edu.umass.cs.gnscommon.exceptions.client.EncryptionException)23 BasicGuidEntry (edu.umass.cs.gnsclient.client.util.BasicGuidEntry)20 FieldNotFoundException (edu.umass.cs.gnscommon.exceptions.client.FieldNotFoundException)19 FileNotFoundException (java.io.FileNotFoundException)18 InternalRequestException (edu.umass.cs.gnscommon.exceptions.server.InternalRequestException)15 ResponseCode (edu.umass.cs.gnscommon.ResponseCode)13 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)13 InvalidKeyException (java.security.InvalidKeyException)12