Search in sources :

Example 21 with ClientException

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

the class GroupAddTest method test_221_GroupSecondCreate.

/**
   *
   */
@Test
public void test_221_GroupSecondCreate() {
    String another = "anotherGroupEntry" + RandomString.randomString(12);
    try {
        try {
            clientCommands.lookupGuid(another);
            Utils.failWithStackTrace(another + " entity should not exist");
        } catch (ClientException e) {
        }
        anotherGroupEntry = clientCommands.guidCreate(masterGuid, another);
    } catch (Exception e) {
        Utils.failWithStackTrace("Exception while creating guids: ", 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 22 with ClientException

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

the class SelectTest method test_098_EvilOperators.

/**
   * Check an empty query
   */
@Test
public void test_098_EvilOperators() {
    try {
        String query = "nr_valuesMap.secret:{$regex : ^i_like_cookies}";
        JSONArray result = client.execute(GNSCommand.selectQuery(query)).getResultJSONArray();
        //JSONArray result = clientCommands.selectQuery(query);
        for (int i = 0; i < result.length(); i++) {
            Assert.assertTrue(StringUtil.isValidGuidString(result.get(i).toString()));
        }
        Utils.failWithStackTrace("Should have throw an exception");
    } catch (IOException | JSONException e) {
        Utils.failWithStackTrace("Exception executing evil query " + e);
    } catch (ClientException e) {
    // Expected
    }
}
Also used : JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) RandomString(edu.umass.cs.gnscommon.utils.RandomString) IOException(java.io.IOException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) Test(org.junit.Test) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest)

Example 23 with ClientException

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

the class SelectTest method test_059_QuerySelectwithProjectionSomeFieldsNotAccessible.

/**
   * Check a query select with a projection
   */
@Test
public void test_059_QuerySelectwithProjectionSomeFieldsNotAccessible() {
    String fieldName = "testQueryProjectionSomeFieldsNotAccessible";
    try {
        for (int cnt = 0; cnt < 5; cnt++) {
            String queryTestName = "queryTest-" + RandomString.randomString(12);
            client.execute(GNSCommand.createGUID(masterGuid, queryTestName));
            GuidEntry testEntry = GuidUtils.getGUIDKeys(queryTestName);
            // Remove default all fields / all guids ACL;
            client.execute(GNSCommand.aclRemove(AclAccessType.READ_WHITELIST, testEntry, GNSProtocol.ENTIRE_RECORD.toString(), GNSProtocol.ALL_GUIDS.toString()));
            // Also remove masterGuid access to entire record
            client.execute(GNSCommand.aclRemove(AclAccessType.READ_WHITELIST, testEntry, GNSProtocol.ENTIRE_RECORD.toString(), masterGuid.getGuid()));
            // save them so we can delete them later
            CREATED_GUIDS.add(testEntry);
            JSONObject json = new JSONObject();
            json.put(fieldName, Arrays.asList(25));
            json.put("field1", "value1");
            json.put("inaccessableField", "someValue");
            client.execute(GNSCommand.update(testEntry.getGuid(), json, testEntry));
            // Add masterguid access to fieldName so that the query will work
            client.execute(GNSCommand.aclAdd(AclAccessType.READ_WHITELIST, testEntry, fieldName, masterGuid.getGuid()));
            // Add masterguid access to field1
            client.execute(GNSCommand.aclAdd(AclAccessType.READ_WHITELIST, testEntry, "field1", masterGuid.getGuid()));
            // Set up the ACL so the masterGuid can't read this field
            client.execute(GNSCommand.fieldCreateAcl(AclAccessType.READ_WHITELIST, testEntry, "inaccessableField", testEntry.getGuid()));
        }
        waitSettle(WAIT_SETTLE);
    } catch (ClientException | IOException | JSONException e) {
        Utils.failWithStackTrace("Exception while trying to create the guids: " + e);
    }
    try {
        String query = "~" + fieldName + " : ($gt: 0)";
        //JSONArray result = client.execute(GNSCommand.selectRecords(masterGuid, query, null)).getResultJSONArray();
        JSONArray result = waitForQueryResults(query);
        for (int i = 0; i < result.length(); i++) {
            System.out.println(result.get(i).toString());
        }
        // best we can do should be at least 5, but possibly more objects in results
        Assert.assertThat(result.length(), Matchers.greaterThanOrEqualTo(5));
        // Make sure that one of them has the field we want and
        Assert.assertTrue(result.getJSONObject(0).has("field1"));
        // doesn't have the field we can't see
        Assert.assertFalse(result.getJSONObject(0).has("inaccessableField"));
    } catch (JSONException e) {
        //} catch (ClientException | IOException | JSONException e) {
        Utils.failWithStackTrace("Exception executing selectRecords: " + e);
    }
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) 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) Test(org.junit.Test) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest)

Example 24 with ClientException

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

the class SelectTest method test_092_EmptyQueryBrackets.

/**
   * Check an empty query
   */
@Test
public void test_092_EmptyQueryBrackets() {
    try {
        String query = "[]";
        JSONArray result = client.execute(GNSCommand.selectQuery(query)).getResultJSONArray();
        for (int i = 0; i < result.length(); i++) {
            Assert.assertTrue(StringUtil.isValidGuidString(result.get(i).toString()));
        }
    } catch (IOException | JSONException | ClientException e) {
        Utils.failWithStackTrace("Exception executing empty query " + e);
    }
}
Also used : JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) RandomString(edu.umass.cs.gnscommon.utils.RandomString) IOException(java.io.IOException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) Test(org.junit.Test) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest)

Example 25 with ClientException

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

the class SelectTest method test_058_QuerySelectwithProjectionAll.

/**
   * Check a query select with a projection of all fields
   */
@Test
public void test_058_QuerySelectwithProjectionAll() {
    String fieldName = "testQueryProjectionAll";
    try {
        for (int cnt = 0; cnt < 5; cnt++) {
            String queryTestName = "queryTest-" + RandomString.randomString(12);
            client.execute(GNSCommand.createGUID(masterGuid, queryTestName));
            GuidEntry testEntry = GuidUtils.getGUIDKeys(queryTestName);
            // Remove default all fields / all guids ACL;
            client.execute(GNSCommand.aclRemove(AclAccessType.READ_WHITELIST, testEntry, GNSProtocol.ENTIRE_RECORD.toString(), GNSProtocol.ALL_GUIDS.toString()));
            // save them so we can delete them later
            CREATED_GUIDS.add(testEntry);
            JSONObject json = new JSONObject();
            json.put(fieldName, Arrays.asList(25));
            json.put("field1", "value1");
            JSONObject subJson = new JSONObject();
            subJson.put("subfield", "subvalue1");
            json.put("nested", subJson);
            client.execute(GNSCommand.update(testEntry.getGuid(), json, testEntry));
        }
        waitSettle(WAIT_SETTLE);
    } catch (ClientException | IOException | JSONException e) {
        Utils.failWithStackTrace("Exception while trying to create the guids: " + e);
    }
    try {
        String query = "~" + fieldName + " : ($gt: 0)";
        JSONArray result = waitForQueryResults(query);
        //JSONArray result = client.execute(GNSCommand.selectRecords(masterGuid, query, null)).getResultJSONArray();
        for (int i = 0; i < result.length(); i++) {
            System.out.println(result.get(i).toString());
        }
        // best we can do should be at least 5, but possibly more objects in results
        Assert.assertThat(result.length(), Matchers.greaterThanOrEqualTo(5));
    } catch (JSONException e) {
        //} catch (ClientException | IOException | JSONException e) {
        Utils.failWithStackTrace("Exception executing selectRecords: " + e);
    }
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) 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) 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