use of org.xwiki.csrf.CSRFToken in project xwiki-platform by xwiki.
the class UndeleteActionTest method restoreBatch.
/**
* Launches a RestoreJob with the batchId of the current deleted document.
*/
@Test
public void restoreBatch() throws Exception {
CSRFToken csrfToken = mocker.getInstance(CSRFToken.class);
when(csrfToken.isTokenValid(null)).thenReturn(true);
long id = 13;
String batchId = "abc123";
when(request.getParameter("id")).thenReturn(String.valueOf(id));
XWikiDeletedDocument deletedDocument = mock(XWikiDeletedDocument.class);
when(deletedDocument.getLocale()).thenReturn(Locale.ROOT);
when(deletedDocument.getId()).thenReturn(id);
when(deletedDocument.getBatchId()).thenReturn(batchId);
when(xwiki.getDeletedDocument(anyLong(), any(XWikiContext.class))).thenReturn(deletedDocument);
// Go through the screen showing the option to include the batch and displaying its contents.
when(request.getParameter("showBatch")).thenReturn("true");
// Option to include the entire batch when restoring is enabled.
when(request.getParameter("includeBatch")).thenReturn("true");
// Confirmation button pressed.
when(request.getParameter("confirm")).thenReturn("true");
when(rightsService.hasAccessLevel(any(), any(), any(), any())).thenReturn(true);
assertFalse(undeleteAction.action(context));
verify(refactoringScriptService).createRestoreRequest(batchId);
verify(jobExecutor).execute(RefactoringJobs.RESTORE, jobRequest);
verify(job).join();
}
use of org.xwiki.csrf.CSRFToken in project xwiki-platform by xwiki.
the class UndeleteActionTest method notAllowedToRestoreSinglePage.
/**
* When trying to restore, rights are checked on the current deleted document, regardless if single or batch
* restore.
*/
@Test
public void notAllowedToRestoreSinglePage() throws Exception {
CSRFToken csrfToken = mocker.getInstance(CSRFToken.class);
when(csrfToken.isTokenValid(null)).thenReturn(true);
long id = 13;
when(request.getParameter("id")).thenReturn(String.valueOf(id));
XWikiDeletedDocument deletedDocument = mock(XWikiDeletedDocument.class);
when(deletedDocument.getLocale()).thenReturn(Locale.ROOT);
when(deletedDocument.getId()).thenReturn(id);
when(xwiki.getDeletedDocument(anyLong(), any(XWikiContext.class))).thenReturn(deletedDocument);
when(rightsService.hasAccessLevel(any(), any(), any(), any())).thenReturn(false);
assertTrue(undeleteAction.action(context));
// Render the "accessdenied" template.
assertEquals("accessdenied", undeleteAction.render(context));
// Just make sure we don`t go any further.
verify(refactoringScriptService, never()).createRestoreRequest(Arrays.asList(id));
}
Aggregations