Search in sources :

Example 6 with LegacyTestWiki

use of org.xwiki.security.authorization.testwikibuilding.LegacyTestWiki in project xwiki-platform by xwiki.

the class XWikiRightServiceTest method testUserFromAnotherWiki2.

@Test
public void testUserFromAnotherWiki2() throws Exception {
    LegacyTestWiki testWiki = newTestWiki("userFromAnotherWiki2.xml", true);
    XWikiContext ctx = testWiki.getXWikiContext();
    ctx.setWikiId("wiki");
    assertAccessLevelTrue("User from another wiki does not have right on a local wiki when tested from user wiki", "view", "wiki:XWiki.user", "wiki2:Space.Page", ctx);
    assertAccessLevelTrue("User from another wiki does not have right on a local wiki when tested from user wiki", "view", "XWiki.user", "wiki2:Space.Page", ctx);
    ctx.setWikiId("wiki2");
    assertAccessLevelTrue("User from another wiki does not have right on a local wiki when tested from local wiki", "view", "wiki:XWiki.user", "wiki2:Space.Page", ctx);
    assertAccessLevelTrue("User from another wiki does not have right on a local wiki when tested from local wiki", "view", "wiki:XWiki.user", "Space.Page", ctx);
}
Also used : LegacyTestWiki(org.xwiki.security.authorization.testwikibuilding.LegacyTestWiki) XWikiContext(com.xpn.xwiki.XWikiContext) Test(org.junit.Test)

Example 7 with LegacyTestWiki

use of org.xwiki.security.authorization.testwikibuilding.LegacyTestWiki in project xwiki-platform by xwiki.

the class XWikiRightServiceTest method testProgrammingRightsWhenCustomSecureDocIsSet.

@Test
public void testProgrammingRightsWhenCustomSecureDocIsSet() throws Exception {
    LegacyTestWiki testWiki = newTestWiki("programmingRights.xml", true);
    XWikiContext ctx = testWiki.getXWikiContext();
    ctx.setWikiId("wiki");
    setContext(ctx);
    XWikiDocument sdoc = new XWikiDocument(new DocumentReference("wiki", "space", "page"));
    sdoc.setContentAuthorReference(new DocumentReference(ctx.getMainXWiki(), "XWiki", "superadmin"));
    testWiki.setSdoc(sdoc);
    // XWiki.Programmer should have PR, as per the global rights.
    sdoc.setContentAuthorReference(new DocumentReference(ctx.getMainXWiki(), "XWiki", "programmer"));
    Assert.assertTrue(getLegacyImpl().hasProgrammingRights(ctx));
    Assert.assertTrue(getCachingImpl().hasProgrammingRights(ctx));
    // Guests should not have PR
    sdoc.setContentAuthorReference(null);
    Assert.assertFalse(getLegacyImpl().hasProgrammingRights(ctx));
    Assert.assertFalse(getCachingImpl().hasProgrammingRights(ctx));
    // superadmin should always have PR
    sdoc.setContentAuthorReference(new DocumentReference(ctx.getMainXWiki(), "XWiki", "superadmin"));
    Assert.assertTrue(getLegacyImpl().hasProgrammingRights(ctx));
    Assert.assertTrue(getCachingImpl().hasProgrammingRights(ctx));
}
Also used : LegacyTestWiki(org.xwiki.security.authorization.testwikibuilding.LegacyTestWiki) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiContext(com.xpn.xwiki.XWikiContext) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 8 with LegacyTestWiki

use of org.xwiki.security.authorization.testwikibuilding.LegacyTestWiki in project xwiki-platform by xwiki.

the class XWikiRightServiceTest method testUserFromAnotherWiki1.

@Test
public void testUserFromAnotherWiki1() throws Exception {
    LegacyTestWiki testWiki = newTestWiki("userFromAnotherWiki1.xml", true);
    XWikiContext ctx = testWiki.getXWikiContext();
    ctx.setWikiId("wiki");
    assertAccessLevelTrue("User from another wiki has right on a local wiki", "view", "wiki:XWiki.user", "wiki2:Space.Page", ctx);
    assertAccessLevelTrue("User from another wiki has right on a local wiki", "view", "XWiki.user", "wiki2:Space.Page", ctx);
}
Also used : LegacyTestWiki(org.xwiki.security.authorization.testwikibuilding.LegacyTestWiki) XWikiContext(com.xpn.xwiki.XWikiContext) Test(org.junit.Test)

Example 9 with LegacyTestWiki

use of org.xwiki.security.authorization.testwikibuilding.LegacyTestWiki in project xwiki-platform by xwiki.

the class XWikiRightServiceTest method testWikiOwnerFromAnotherWiki.

@Test
public void testWikiOwnerFromAnotherWiki() throws Exception {
    LegacyTestWiki testWiki = newTestWiki("userFromAnotherWiki2.xml", true);
    XWikiContext ctx = testWiki.getXWikiContext();
    ctx.setWikiId("wiki");
    assertAccessLevelTrue("Wiki owner from another wiki does not have right on a local wiki when tested from user wiki", "view", "wiki:XWiki.user", "wiki2:Space.Page", ctx);
    assertAccessLevelTrue("Wiki owner from another wiki does not have right on a local wiki when tested from user wiki", "view", "XWiki.user", "wiki2:Space.Page", ctx);
    ctx.setWikiId("wiki2");
    assertAccessLevelTrue("Wiki owner from another wiki does not have right on a local wiki when tested from local wiki", "view", "wiki:XWiki.user", "wiki2:Space.Page", ctx);
    assertAccessLevelTrue("Wiki owner from another wiki does not have right on a local wiki when tested from local wiki", "view", "wiki:XWiki.user", "Space.Page", ctx);
}
Also used : LegacyTestWiki(org.xwiki.security.authorization.testwikibuilding.LegacyTestWiki) XWikiContext(com.xpn.xwiki.XWikiContext) Test(org.junit.Test)

Example 10 with LegacyTestWiki

use of org.xwiki.security.authorization.testwikibuilding.LegacyTestWiki in project xwiki-platform by xwiki.

the class XWikiRightServiceTest method testProgrammingRightsWhenNoContextDocumentIsSet.

/**
 * Test that programming rights are checked on the context user when no context document is set.
 *
 * @throws com.xpn.xwiki.XWikiException on error
 */
@Test
public void testProgrammingRightsWhenNoContextDocumentIsSet() throws Exception {
    LegacyTestWiki testWiki = newTestWiki("programmingRights.xml", true);
    XWikiContext ctx = testWiki.getXWikiContext();
    ctx.setWikiId("wiki");
    setContext(ctx);
    testWiki.setSdoc((String) null);
    // XWiki.Programmer should have PR, as per the global rights.
    testWiki.setUser("XWiki.programmer");
    Assert.assertTrue(getLegacyImpl().hasProgrammingRights(ctx));
    Assert.assertTrue(getCachingImpl().hasProgrammingRights(ctx));
    // Guests should not have PR
    testWiki.setUser(XWikiConstants.GUEST_USER_FULLNAME);
    Assert.assertFalse(getLegacyImpl().hasProgrammingRights(ctx));
    Assert.assertFalse(getCachingImpl().hasProgrammingRights(ctx));
    // superadmin should always have PR
    testWiki.setUser(XWikiConstants.XWIKI_SPACE + '.' + AuthorizationManager.SUPERADMIN_USER);
    Assert.assertTrue(getLegacyImpl().hasProgrammingRights(ctx));
    Assert.assertTrue(getCachingImpl().hasProgrammingRights(ctx));
}
Also used : LegacyTestWiki(org.xwiki.security.authorization.testwikibuilding.LegacyTestWiki) XWikiContext(com.xpn.xwiki.XWikiContext) Test(org.junit.Test)

Aggregations

LegacyTestWiki (org.xwiki.security.authorization.testwikibuilding.LegacyTestWiki)19 XWikiContext (com.xpn.xwiki.XWikiContext)18 Test (org.junit.Test)18 DocumentReference (org.xwiki.model.reference.DocumentReference)9 EntityReference (org.xwiki.model.reference.EntityReference)3 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1