use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.
the class WikiUserManagerScriptServiceTest method currentUserHasNotAdminRight.
/**
* Mocks the components to simulate that the current user is not an admin.
*
* @return the exception expected when the current user has the not the admin right
*/
private Exception currentUserHasNotAdminRight() throws AccessDeniedException {
WikiReference wiki = new WikiReference("subwiki");
Exception exception = new AccessDeniedException(Right.ADMIN, userDocRef, wiki);
doThrow(exception).when(authorizationManager).checkAccess(eq(Right.ADMIN), eq(userDocRef), eq(wiki));
return exception;
}
use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.
the class WikiUserManagerScriptServiceTest method getCandidacyAsAdmin.
@Test
public void getCandidacyAsAdmin() throws Exception {
// Mocks
MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.OtherUser", MemberCandidacy.CandidateType.REQUEST);
candidacy.setId(12);
candidacy.setAdminPrivateComment("private message");
when(wikiUserManager.getCandidacy("subwiki", candidacy.getId())).thenReturn(candidacy);
when(authorizationManager.hasAccess(eq(Right.ADMIN), eq(userDocRef), eq(new WikiReference("subwiki")))).thenReturn(true);
// Test
MemberCandidacy result = mocker.getComponentUnderTest().getCandidacy("subwiki", 12);
// Asserts
assertEquals(candidacy, result);
assertEquals("private message", result.getAdminPrivateComment());
}
use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.
the class WikiUserManagerScriptServiceTest method getCandidacyWhenNoRight.
@Test
public void getCandidacyWhenNoRight() throws Exception {
// Mocks
// The current user is not the candidate
MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.OtherUser", MemberCandidacy.CandidateType.REQUEST);
candidacy.setId(12);
when(wikiUserManager.getCandidacy("subwiki", candidacy.getId())).thenReturn(candidacy);
// The current user does not have ADMIN right
when(authorizationManager.hasAccess(eq(Right.ADMIN), eq(userDocRef), eq(new WikiReference("subwiki")))).thenReturn(false);
// Test
MemberCandidacy result = mocker.getComponentUnderTest().getCandidacy("subwiki", 12);
// Asserts
assertNull(result);
Exception exception = mocker.getComponentUnderTest().getLastError();
assertTrue(exception instanceof WikiUserManagerScriptServiceException);
assertEquals("You are not allowed to see this candidacy.", exception.getMessage());
}
use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.
the class WikiManagerScriptServiceTest method currentUserHasNotCreateWikiRight.
/**
* @return the exception expected when the current user has the not the 'create wiki' right
*/
private Exception currentUserHasNotCreateWikiRight() throws AccessDeniedException {
WikiReference wiki = new WikiReference("mainWiki");
Exception exception = new AccessDeniedException(Right.CREATE_WIKI, currentUserRef, wiki);
doThrow(exception).when(authorizationManager).checkAccess(eq(Right.CREATE_WIKI), eq(currentUserRef), eq(wiki));
return exception;
}
use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.
the class WikiManagerScriptServiceTest method saveDescriptorWhenDescriptorDidNotExist.
@Test
public void saveDescriptorWhenDescriptorDidNotExist() throws Exception {
WikiDescriptor descriptor = new WikiDescriptor("wikiId", "wikiAlias");
boolean result = mocker.getComponentUnderTest().saveDescriptor(descriptor);
assertFalse(result);
// Verify the rights have been checked
verify(authorizationManager).hasAccess(eq(Right.ADMIN), eq(currentUserRef), eq(new WikiReference("mainWiki")));
// The descriptor has not been saved
verify(wikiDescriptorManager, never()).saveDescriptor(descriptor);
}
Aggregations