use of org.springframework.extensions.webscripts.TestWebScriptServer.Response in project alfresco-remote-api by Alfresco.
the class AuditWebScriptTest method testGetIsAuditEnabledGlobally.
public void testGetIsAuditEnabledGlobally() throws Exception {
boolean wasEnabled = auditService.isAuditEnabled();
Map<String, AuditApplication> checkApps = auditService.getAuditApplications();
String url = "/api/audit/control";
TestWebScriptServer.GetRequest req = new TestWebScriptServer.GetRequest(url);
Response response = sendRequest(req, Status.STATUS_OK, admin);
JSONObject json = new JSONObject(response.getContentAsString());
boolean enabled = json.getBoolean(AbstractAuditWebScript.JSON_KEY_ENABLED);
assertEquals("Mismatched global audit enabled", wasEnabled, enabled);
JSONArray apps = json.getJSONArray(AbstractAuditWebScript.JSON_KEY_APPLICATIONS);
assertEquals("Incorrect number of applications reported", checkApps.size(), apps.length());
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.Response in project alfresco-remote-api by Alfresco.
the class AuditWebScriptTest method testGetIsAuditEnabledRepo.
public void testGetIsAuditEnabledRepo() throws Exception {
boolean wasEnabled = auditService.isAuditEnabled(APP_REPOTEST_NAME, null);
String url = "/api/audit/control/" + APP_REPOTEST_NAME + APP_REPOTEST_PATH;
TestWebScriptServer.GetRequest req = new TestWebScriptServer.GetRequest(url);
if (wasEnabled) {
Response response = sendRequest(req, Status.STATUS_OK, admin);
JSONObject json = new JSONObject(response.getContentAsString());
JSONArray apps = json.getJSONArray(AbstractAuditWebScript.JSON_KEY_APPLICATIONS);
assertEquals("Incorrect number of applications reported", 1, apps.length());
JSONObject app = apps.getJSONObject(0);
String appName = app.getString(AbstractAuditWebScript.JSON_KEY_NAME);
String appPath = app.getString(AbstractAuditWebScript.JSON_KEY_PATH);
boolean appEnabled = app.getBoolean(AbstractAuditWebScript.JSON_KEY_ENABLED);
assertEquals("Mismatched application audit enabled", wasEnabled, appEnabled);
assertEquals("Mismatched application audit name", APP_REPOTEST_NAME, appName);
assertEquals("Mismatched application audit path", APP_REPOTEST_PATH, appPath);
}
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.Response in project alfresco-remote-api by Alfresco.
the class AuditWebScriptTest method testQueryAuditRepo.
@SuppressWarnings("unused")
public void testQueryAuditRepo() throws Exception {
long now = System.currentTimeMillis();
long future = Long.MAX_VALUE;
auditService.setAuditEnabled(true);
auditService.enableAudit(APP_REPOTEST_NAME, APP_REPOTEST_PATH);
loginWithFailure(getName());
// Query for audit entries that could not have happened
String url = "/api/audit/query/" + APP_REPOTEST_NAME + "?fromTime=" + now + "&verbose=true";
JSONArray jsonEntries = null;
TestWebScriptServer.GetRequest req = null;
Response response = null;
JSONObject json = null;
Long entryCount = null;
// 1 second sleep to ensure that the audit is processed
for (int i = 0; i < 60; i++) {
req = new TestWebScriptServer.GetRequest(url);
response = sendRequest(req, Status.STATUS_OK, admin);
json = new JSONObject(response.getContentAsString());
entryCount = json.getLong(AbstractAuditWebScript.JSON_KEY_ENTRY_COUNT);
jsonEntries = json.getJSONArray(AbstractAuditWebScript.JSON_KEY_ENTRIES);
if (jsonEntries.length() > 0) {
break;
}
Thread.sleep(1000);
}
assertTrue("Expected at least one entry", jsonEntries.length() > 0);
assertEquals("Entry count and physical count don't match", new Long(jsonEntries.length()), entryCount);
JSONObject jsonEntry = jsonEntries.getJSONObject(0);
Long entryId = jsonEntry.getLong(AbstractAuditWebScript.JSON_KEY_ENTRY_ID);
assertNotNull("No entry ID", entryId);
String entryTimeStr = jsonEntry.getString(AbstractAuditWebScript.JSON_KEY_ENTRY_TIME);
assertNotNull("No entry time String", entryTimeStr);
// Check conversion
Date entryTime = ISO8601DateFormat.parse((String) entryTimeStr);
JSONObject jsonValues = jsonEntry.getJSONObject(AbstractAuditWebScript.JSON_KEY_ENTRY_VALUES);
String entryUsername = jsonValues.getString("/repositorytest/login/error/user");
assertEquals("Didn't find the login-failure-user", getName(), entryUsername);
// Query using well-known ID
// Search is inclusive on the 'from' side
Long fromEntryId = entryId;
// Search is exclusive on the 'to' side
Long toEntryId = entryId.longValue() + 1L;
url = "/api/audit/query/" + APP_REPOTEST_NAME + "?fromId=" + fromEntryId + "&toId=" + toEntryId;
req = new TestWebScriptServer.GetRequest(url);
response = sendRequest(req, Status.STATUS_OK, admin);
json = new JSONObject(response.getContentAsString());
jsonEntries = json.getJSONArray(AbstractAuditWebScript.JSON_KEY_ENTRIES);
assertEquals("Incorrect number of search results", 1, jsonEntries.length());
// Query using a non-existent entry path
url = "/api/audit/query/" + APP_REPOTEST_NAME + "/repositorytest/login/error/userXXX" + "?verbose=true";
req = new TestWebScriptServer.GetRequest(url);
response = sendRequest(req, Status.STATUS_OK, admin);
json = new JSONObject(response.getContentAsString());
jsonEntries = json.getJSONArray(AbstractAuditWebScript.JSON_KEY_ENTRIES);
assertTrue("Should not have found anything", jsonEntries.length() == 0);
// Query using a good entry path
url = "/api/audit/query/" + APP_REPOTEST_NAME + "/repositorytest/login/error/user" + "?verbose=true";
req = new TestWebScriptServer.GetRequest(url);
response = sendRequest(req, Status.STATUS_OK, admin);
json = new JSONObject(response.getContentAsString());
jsonEntries = json.getJSONArray(AbstractAuditWebScript.JSON_KEY_ENTRIES);
assertTrue("Should have found entries", jsonEntries.length() > 0);
// Now login with failure using a GUID and ensure that we can find it
String missingUser = new Long(System.currentTimeMillis()).toString();
// Query for event that has not happened
url = "/api/audit/query/" + APP_REPOTEST_NAME + "/repositorytest/login/error/user" + "?value=" + missingUser;
req = new TestWebScriptServer.GetRequest(url);
response = sendRequest(req, Status.STATUS_OK, admin);
json = new JSONObject(response.getContentAsString());
jsonEntries = json.getJSONArray(AbstractAuditWebScript.JSON_KEY_ENTRIES);
assertEquals("Incorrect number of search results", 0, jsonEntries.length());
loginWithFailure(missingUser);
// Query for event that has happened once
url = "/api/audit/query/" + APP_REPOTEST_NAME + "/repositorytest/login/error/user" + "?value=" + missingUser;
// 1 second sleep to ensure that the audit is processed
for (int i = 0; i < 60; i++) {
req = new TestWebScriptServer.GetRequest(url);
response = sendRequest(req, Status.STATUS_OK, admin);
json = new JSONObject(response.getContentAsString());
jsonEntries = json.getJSONArray(AbstractAuditWebScript.JSON_KEY_ENTRIES);
if (jsonEntries.length() == 1) {
break;
}
Thread.sleep(1000);
}
assertEquals("Incorrect number of search results", 1, jsonEntries.length());
// Query for event, but casting the value to the incorrect type
url = "/api/audit/query/" + APP_REPOTEST_NAME + "/repositorytest/login/error/user" + "?value=" + missingUser + "&valueType=java.lang.Long";
req = new TestWebScriptServer.GetRequest(url);
response = sendRequest(req, Status.STATUS_OK, admin);
json = new JSONObject(response.getContentAsString());
jsonEntries = json.getJSONArray(AbstractAuditWebScript.JSON_KEY_ENTRIES);
assertEquals("Incorrect number of search results", 0, jsonEntries.length());
// Test what happens when the target data needs encoding
now = System.currentTimeMillis();
String oddUser = "%$£\\\"\'";
loginWithFailure(oddUser);
// Query for the event limiting to one by count and descending (i.e. get last)
url = "/api/audit/query/" + APP_REPOTEST_NAME + "?forward=false&limit=1&verbose=true&fromTime=" + now;
// 1 second sleep to ensure that the audit is processed
for (int i = 0; i < 60; i++) {
req = new TestWebScriptServer.GetRequest(url);
response = sendRequest(req, Status.STATUS_OK, admin);
json = new JSONObject(response.getContentAsString());
jsonEntries = json.getJSONArray(AbstractAuditWebScript.JSON_KEY_ENTRIES);
if (jsonEntries.length() == 1) {
break;
}
Thread.sleep(1000);
}
assertEquals("Incorrect number of search results", 1, jsonEntries.length());
jsonEntry = jsonEntries.getJSONObject(0);
entryId = jsonEntry.getLong(AbstractAuditWebScript.JSON_KEY_ENTRY_ID);
assertNotNull("No entry ID", entryId);
jsonValues = jsonEntry.getJSONObject(AbstractAuditWebScript.JSON_KEY_ENTRY_VALUES);
entryUsername = jsonValues.getString("/repositorytest/login/error/user");
assertEquals("Didn't find the login-failure-user", oddUser, entryUsername);
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.Response in project alfresco-remote-api by Alfresco.
the class SubscriptionServiceRestApiTest method setSubscriptionListPrivate.
protected void setSubscriptionListPrivate(String user, boolean setPrivate) throws Exception {
JSONObject privateObject = new JSONObject();
privateObject.put("private", setPrivate);
String url = getUrl(URL_PRIVATE, user);
Response response = sendRequest(new PutRequest(url, privateObject.toString(), "application/json"), Status.STATUS_OK);
JSONObject resultObject = new JSONObject(response.getContentAsString());
assertTrue(resultObject.has("private"));
assertEquals(setPrivate, resultObject.getBoolean("private"));
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.Response in project alfresco-remote-api by Alfresco.
the class SubscriptionServiceRestApiTest method getFollowers.
protected List<String> getFollowers(String user) throws Exception {
String url = getUrl(URL_FOLLOWERS, user);
Response response = sendRequest(new GetRequest(url), Status.STATUS_OK);
JSONObject resultObject = new JSONObject(response.getContentAsString());
assertTrue(resultObject.has("people"));
List<String> result = new ArrayList<String>();
JSONArray people = resultObject.getJSONArray("people");
for (int i = 0; i < people.length(); i++) {
JSONObject person = people.getJSONObject(i);
assertTrue(person.has("userName"));
assertTrue(person.has("firstName"));
assertTrue(person.has("lastName"));
result.add(person.getString("userName"));
}
return result;
}
Aggregations