Search in sources :

Example 36 with MacroTransformationContext

use of org.xwiki.rendering.transformation.MacroTransformationContext in project xwiki-platform by xwiki.

the class NestedScriptMacroValidatorTest method testNoNestedScript.

@Test
public void testNoNestedScript() throws Exception {
    MacroTransformationContext context = buildContext("script", "script");
    CancelableEvent event = new ScriptEvaluatingEvent();
    this.validator.onEvent(event, context, null);
    Assert.assertTrue(event.isCanceled());
}
Also used : ScriptEvaluatingEvent(org.xwiki.script.event.ScriptEvaluatingEvent) MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) CancelableEvent(org.xwiki.observation.event.CancelableEvent) Test(org.junit.Test)

Example 37 with MacroTransformationContext

use of org.xwiki.rendering.transformation.MacroTransformationContext in project xwiki-platform by xwiki.

the class NestedScriptMacroValidatorTest method testNestedScriptMacroEnabledInterceptsNestedChain.

@Test
public void testNestedScriptMacroEnabledInterceptsNestedChain() throws Exception {
    MacroTransformationContext context = buildContext("script", "nestedscriptmacroenabled", "script");
    CancelableEvent event = new ScriptEvaluatingEvent();
    this.validator.onEvent(event, context, null);
    Assert.assertFalse(event.isCanceled());
}
Also used : ScriptEvaluatingEvent(org.xwiki.script.event.ScriptEvaluatingEvent) MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) CancelableEvent(org.xwiki.observation.event.CancelableEvent) Test(org.junit.Test)

Example 38 with MacroTransformationContext

use of org.xwiki.rendering.transformation.MacroTransformationContext in project xwiki-platform by xwiki.

the class NestedScriptMacroValidatorTest method testIncludeInterceptsNestedChain.

@Test
public void testIncludeInterceptsNestedChain() throws Exception {
    MacroTransformationContext context = buildContext("script", "include", "script");
    CancelableEvent event = new ScriptEvaluatingEvent();
    this.validator.onEvent(event, context, null);
    Assert.assertFalse(event.isCanceled());
}
Also used : ScriptEvaluatingEvent(org.xwiki.script.event.ScriptEvaluatingEvent) MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) CancelableEvent(org.xwiki.observation.event.CancelableEvent) Test(org.junit.Test)

Example 39 with MacroTransformationContext

use of org.xwiki.rendering.transformation.MacroTransformationContext in project xwiki-platform by xwiki.

the class VelocityMacroSecurityTest method testRestrictedByContext.

@Test(expected = MacroExecutionException.class)
public void testRestrictedByContext() throws Exception {
    VelocityMacroParameters params = new VelocityMacroParameters();
    MacroTransformationContext context = new MacroTransformationContext();
    context.setSyntax(Syntax.XWIKI_2_0);
    context.setCurrentMacroBlock(new MacroBlock("velocity", Collections.<String, String>emptyMap(), false));
    context.setId("page1");
    // Restrict the transformation context.
    context.getTransformationContext().setRestricted(true);
    when(authorizationManager.hasAccess(Right.SCRIPT)).thenReturn(true);
    mocker.getComponentUnderTest().execute(params, "#macro(testMacrosAreLocal)mymacro#end", context);
}
Also used : MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) MacroBlock(org.xwiki.rendering.block.MacroBlock) Test(org.junit.Test)

Example 40 with MacroTransformationContext

use of org.xwiki.rendering.transformation.MacroTransformationContext in project xwiki-platform by xwiki.

the class VelocityMacroSecurityTest method testRestrictedByRights.

@Test(expected = MacroExecutionException.class)
public void testRestrictedByRights() throws Exception {
    VelocityMacroParameters params = new VelocityMacroParameters();
    MacroTransformationContext context = new MacroTransformationContext();
    context.setSyntax(Syntax.XWIKI_2_0);
    context.setCurrentMacroBlock(new MacroBlock("velocity", Collections.<String, String>emptyMap(), false));
    context.setId("page1");
    context.getTransformationContext().setRestricted(false);
    // Restrict the SCRIPT right.
    when(authorizationManager.hasAccess(Right.SCRIPT)).thenReturn(false);
    mocker.getComponentUnderTest().execute(params, "#macro(testMacrosAreLocal)mymacro#end", context);
    verify(authorizationManager.hasAccess(Right.SCRIPT));
}
Also used : MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) MacroBlock(org.xwiki.rendering.block.MacroBlock) Test(org.junit.Test)

Aggregations

MacroTransformationContext (org.xwiki.rendering.transformation.MacroTransformationContext)41 Test (org.junit.Test)30 MacroBlock (org.xwiki.rendering.block.MacroBlock)17 DocumentReference (org.xwiki.model.reference.DocumentReference)15 Block (org.xwiki.rendering.block.Block)13 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)10 XDOM (org.xwiki.rendering.block.XDOM)10 MacroExecutionException (org.xwiki.rendering.macro.MacroExecutionException)10 Expectations (org.jmock.Expectations)9 HashMap (java.util.HashMap)6 MacroMarkerBlock (org.xwiki.rendering.block.MacroMarkerBlock)6 MetaDataBlock (org.xwiki.rendering.block.MetaDataBlock)6 MetaData (org.xwiki.rendering.listener.MetaData)6 CacheMacroParameters (org.xwiki.rendering.macro.cache.CacheMacroParameters)6 IncludeMacroParameters (org.xwiki.rendering.macro.include.IncludeMacroParameters)6 ContextMacroParameters (org.xwiki.rendering.macro.context.ContextMacroParameters)5 Transformation (org.xwiki.rendering.transformation.Transformation)5 TransformationContext (org.xwiki.rendering.transformation.TransformationContext)5 StringWriter (java.io.StringWriter)4 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)4