Search in sources :

Example 21 with WikiReference

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;
}
Also used : AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) WikiReference(org.xwiki.model.reference.WikiReference) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException)

Example 22 with WikiReference

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());
}
Also used : MemberCandidacy(org.xwiki.wiki.user.MemberCandidacy) WikiReference(org.xwiki.model.reference.WikiReference) Test(org.junit.Test)

Example 23 with WikiReference

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());
}
Also used : MemberCandidacy(org.xwiki.wiki.user.MemberCandidacy) WikiReference(org.xwiki.model.reference.WikiReference) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException) Test(org.junit.Test)

Example 24 with WikiReference

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;
}
Also used : AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) WikiReference(org.xwiki.model.reference.WikiReference) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException)

Example 25 with WikiReference

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);
}
Also used : WikiReference(org.xwiki.model.reference.WikiReference) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) Test(org.junit.Test)

Aggregations

WikiReference (org.xwiki.model.reference.WikiReference)220 DocumentReference (org.xwiki.model.reference.DocumentReference)127 Test (org.junit.Test)106 SpaceReference (org.xwiki.model.reference.SpaceReference)58 XWikiContext (com.xpn.xwiki.XWikiContext)33 XWikiException (com.xpn.xwiki.XWikiException)24 EntityReference (org.xwiki.model.reference.EntityReference)24 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)23 ArrayList (java.util.ArrayList)19 AccessDeniedException (org.xwiki.security.authorization.AccessDeniedException)18 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)15 WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)11 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)10 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)10 XWiki (com.xpn.xwiki.XWiki)9 BaseObject (com.xpn.xwiki.objects.BaseObject)9 ComponentManager (org.xwiki.component.manager.ComponentManager)9 Expectations (org.jmock.Expectations)8 Before (org.junit.Before)8 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)8