use of org.springframework.mock.web.MockHttpServletResponse in project cas by apereo.
the class AbstractServiceValidateControllerTests method getModelAndViewUponServiceValidationWithSecurePgtUrl.
/*
Helper methods.
*/
protected ModelAndView getModelAndViewUponServiceValidationWithSecurePgtUrl() throws Exception {
final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(getAuthenticationSystemSupport(), SERVICE);
final TicketGrantingTicket tId = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
final ServiceTicket sId = getCentralAuthenticationService().grantServiceTicket(tId.getId(), SERVICE, ctx);
final MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, SERVICE.getId());
request.addParameter(CasProtocolConstants.PARAMETER_TICKET, sId.getId());
request.addParameter(CasProtocolConstants.PARAMETER_PROXY_GRANTING_TICKET_URL, GITHUB_URL);
return this.serviceValidateController.handleRequestInternal(request, new MockHttpServletResponse());
}
use of org.springframework.mock.web.MockHttpServletResponse in project alfresco-remote-api by Alfresco.
the class LockMethodTest method testMNT_11990.
@Test
public void testMNT_11990() throws Exception {
MockHttpServletRequest lockRequest = new MockHttpServletRequest();
lockRequest.addHeader(WebDAV.HEADER_TIMEOUT, WebDAV.SECOND + 3600);
lockRequest.addHeader(WebDAV.HEADER_IF, "(<" + WebDAV.makeLockToken(fileNodeRef, userName) + ">)");
lockRequest.setRequestURI("/" + TEST_FILE_NAME);
lockMethod.setDetails(lockRequest, new MockHttpServletResponse(), davHelper, folderNodeRef);
lockMethod.parseRequestHeaders();
lockMethod.parseRequestBody();
RetryingTransactionCallback<Void> lockExecuteImplCallBack = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
try {
lockMethod.executeImpl();
fail("Lock should not be refreshed for non-locked file.");
} catch (WebDAVServerException e) {
assertEquals(e.getHttpStatusCode(), HttpServletResponse.SC_BAD_REQUEST);
}
return null;
}
};
// try to refresh lock for non-locked node
this.transactionService.getRetryingTransactionHelper().doInTransaction(lockExecuteImplCallBack);
}
use of org.springframework.mock.web.MockHttpServletResponse in project alfresco-remote-api by Alfresco.
the class LockMethodTest method testMNT_12425.
@Test
public void testMNT_12425() throws Exception {
MockHttpServletRequest lockRequest = new MockHttpServletRequest();
MockHttpServletResponse lockResponse = new MockHttpServletResponse();
// refresh lock set to 1 hour
lockRequest.addHeader(WebDAV.HEADER_TIMEOUT, WebDAV.SECOND + 3600);
lockRequest.addHeader(WebDAV.HEADER_IF, "(<" + WebDAV.makeLockToken(fileNodeRef, userName) + ">)");
// specify path to non-existing file
lockRequest.setRequestURI("/" + TEST_NEW_FOLDER_NAME + "/" + TEST_NEW_FILE_NAME);
lockMethod.setDetails(lockRequest, lockResponse, davHelper, folderNodeRef);
lockMethod.parseRequestHeaders();
RetryingTransactionCallback<Void> lockExecuteImplCallBack = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
try {
lockMethod.executeImpl();
fail("Refresh lock for non-exisitent resource should fail.");
} catch (WebDAVServerException e) {
assertEquals(HttpServletResponse.SC_FORBIDDEN, e.getHttpStatusCode());
}
return null;
}
};
// try to lock non-existent file
this.transactionService.getRetryingTransactionHelper().doInTransaction(lockExecuteImplCallBack);
}
use of org.springframework.mock.web.MockHttpServletResponse in project alfresco-remote-api by Alfresco.
the class UnlockMethodTest method unlockWorkingCopy.
/**
* Test MNT-9680: Working copies are open in read-only mode when using Webdav online edit
*
* @throws Exception
*/
@Test
public void unlockWorkingCopy() throws Exception {
setUpPreconditionForCheckedOutTest();
try {
String workingCopyName = nodeService.getProperty(fileWorkingCopyNodeRef, ContentModel.PROP_NAME).toString();
String lockToken = fileWorkingCopyNodeRef.getId() + WebDAV.LOCK_TOKEN_SEPERATOR + this.userName;
String lockHeaderValue = "<" + WebDAV.OPAQUE_LOCK_TOKEN + lockToken + ">";
final WebDAVHelper davHelper = (WebDAVHelper) appContext.getBean("webDAVHelper");
request.addHeader(WebDAV.HEADER_LOCK_TOKEN, lockHeaderValue);
request.setRequestURI("/" + workingCopyName);
String content = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + "<d:lockinfo xmlns:d=\"DAV:\">" + "<d:lockscope><d:exclusive/></d:lockscope>" + "</d:lockinfo>";
request.setContent(content.getBytes("UTF-8"));
lockMethod.setDetails(request, new MockHttpServletResponse(), davHelper, folderNodeRef);
lockMethod.parseRequestHeaders();
lockMethod.parseRequestBody();
RetryingTransactionCallback<Void> lockExecuteImplCallBack = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
lockMethod.executeImpl();
return null;
}
};
this.transactionService.getRetryingTransactionHelper().doInTransaction(lockExecuteImplCallBack);
unlockMethod.setDetails(request, new MockHttpServletResponse(), davHelper, folderNodeRef);
unlockMethod.parseRequestHeaders();
RetryingTransactionCallback<Void> unlockExecuteImplCallBack = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
unlockMethod.executeImpl();
return null;
}
};
this.transactionService.getRetryingTransactionHelper().doInTransaction(unlockExecuteImplCallBack);
assertNull("lockType property should be deleted on unlock", nodeService.getProperty(fileWorkingCopyNodeRef, ContentModel.PROP_LOCK_TYPE));
assertNull("lockOwner property should be deleted on unlock", nodeService.getProperty(fileWorkingCopyNodeRef, ContentModel.PROP_LOCK_OWNER));
} finally {
// clear context for current user
this.authenticationComponent.clearCurrentSecurityContext();
// delete test store as system user
this.authenticationComponent.setSystemUserAsCurrentUser();
RetryingTransactionCallback<Void> deleteStoreCallback = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
if (nodeService.exists(storeRef)) {
nodeService.deleteStore(storeRef);
}
return null;
}
};
this.transactionService.getRetryingTransactionHelper().doInTransaction(deleteStoreCallback);
}
}
use of org.springframework.mock.web.MockHttpServletResponse in project alfresco-remote-api by Alfresco.
the class UnlockMethodTest method unlockCheckedOutNode.
/**
* Test that it is impossible to unlock a checked out node
*
* @throws Exception
*/
@Test
public void unlockCheckedOutNode() throws Exception {
setUpPreconditionForCheckedOutTest();
try {
String lockToken = fileNodeRef.getId() + WebDAV.LOCK_TOKEN_SEPERATOR + this.userName;
String lockHeaderValue = "<" + WebDAV.OPAQUE_LOCK_TOKEN + lockToken + ">";
request.addHeader(WebDAV.HEADER_LOCK_TOKEN, lockHeaderValue);
request.setRequestURI("/" + TEST_FILE_NAME);
WebDAVHelper davHelper = (WebDAVHelper) appContext.getBean("webDAVHelper");
unlockMethod.setDetails(request, new MockHttpServletResponse(), davHelper, folderNodeRef);
unlockMethod.parseRequestHeaders();
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
unlockMethod.executeImpl();
return null;
}
});
fail("Exception should have been thrown, but wasn't.");
} catch (AlfrescoRuntimeException e) {
if (e.getCause() instanceof WebDAVServerException) {
WebDAVServerException ee = (WebDAVServerException) e.getCause();
assertEquals(HttpServletResponse.SC_PRECONDITION_FAILED, ee.getHttpStatusCode());
} else {
fail("Incorrect exception thrown.");
}
} catch (WebDAVServerException e) {
assertEquals(HttpServletResponse.SC_PRECONDITION_FAILED, e.getHttpStatusCode());
} finally {
// clear context for current user
this.authenticationComponent.clearCurrentSecurityContext();
// delete test store as system user
this.authenticationComponent.setSystemUserAsCurrentUser();
RetryingTransactionCallback<Void> deleteStoreCallback = new RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
if (nodeService.exists(storeRef)) {
nodeService.deleteStore(storeRef);
}
return null;
}
};
this.transactionService.getRetryingTransactionHelper().doInTransaction(deleteStoreCallback);
}
}
Aggregations