Search in sources :

Example 6 with ConfigurationSource

use of org.xwiki.configuration.ConfigurationSource in project xwiki-platform by xwiki.

the class VelocityContextInitializerTest method registerComponents.

@Override
protected void registerComponents() throws Exception {
    super.registerComponents();
    registerMockComponent(ScriptService.class, "officeimporter", "importer");
    registerMockComponent(ScriptService.class, "officemanager", "manager");
    final ConfigurationSource configurationSource = registerMockComponent(ConfigurationSource.class);
    getMockery().checking(new Expectations() {

        {
            oneOf(configurationSource).getProperty("velocity.tools", Properties.class);
            will(returnValue(new Properties()));
        }
    });
}
Also used : Expectations(org.jmock.Expectations) ConfigurationSource(org.xwiki.configuration.ConfigurationSource) Properties(java.util.Properties)

Example 7 with ConfigurationSource

use of org.xwiki.configuration.ConfigurationSource in project xwiki-platform by xwiki.

the class ActivityStreamImpl method addHiddenEventsFilter.

/**
 * This method will add a where clause to filter events fired from hidden documents. The clause will not be added to
 * the query if the user has specified that he wish to see hidden documents in his profile. If the clause is added
 * this method will also add a 'where' to the query if it is missing.
 *
 * @param query The query to add the filter to
 */
private void addHiddenEventsFilter(StringBuffer query) {
    ConfigurationSource source = Utils.getComponent(ConfigurationSource.class, "user");
    Integer preference = source.getProperty("displayHiddenDocuments", Integer.class);
    if (preference == null || preference != 1) {
        if (!query.toString().contains(" where ")) {
            query.append(" where ");
        }
        query.append(" (act.hidden <> true or act.hidden is null) and ");
    }
}
Also used : ConfigurationSource(org.xwiki.configuration.ConfigurationSource)

Example 8 with ConfigurationSource

use of org.xwiki.configuration.ConfigurationSource in project xwiki-platform by xwiki.

the class SecureGroovyCompilationCustomizerTest method executeWithSecureCustomizerWhenProgrammingRights.

@Test
public void executeWithSecureCustomizerWhenProgrammingRights() throws Exception {
    final ConfigurationSource source = registerMockComponent(ConfigurationSource.class);
    final ContextualAuthorizationManager cam = registerMockComponent(ContextualAuthorizationManager.class);
    getMockery().checking(new Expectations() {

        {
            oneOf(source).getProperty("groovy.compilationCustomizers", Collections.emptyList());
            will(returnValue(Arrays.asList("secure")));
            oneOf(cam).hasAccess(Right.PROGRAM);
            will(returnValue(true));
        }
    });
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngineFactory groovyScriptEngineFactory = getComponentManager().getInstance(ScriptEngineFactory.class, "groovy");
    manager.registerEngineName("groovy", groovyScriptEngineFactory);
    final ScriptEngine engine = manager.getEngineByName("groovy");
    // Verify that the Secure AST Customizer is not active by running a Groovy script that raise an exception
    // when the Secure AST Customizer is active
    engine.eval("synchronized(this) { }");
}
Also used : ContextualAuthorizationManager(org.xwiki.security.authorization.ContextualAuthorizationManager) Expectations(org.jmock.Expectations) ConfigurationSource(org.xwiki.configuration.ConfigurationSource) ScriptEngineFactory(javax.script.ScriptEngineFactory) ScriptEngineManager(javax.script.ScriptEngineManager) ScriptEngine(javax.script.ScriptEngine) Test(org.junit.Test)

Example 9 with ConfigurationSource

use of org.xwiki.configuration.ConfigurationSource in project xwiki-platform by xwiki.

the class SecureGroovyCompilationCustomizerTest method setUpWhenNoProgrammingRights.

private void setUpWhenNoProgrammingRights() throws Exception {
    final ConfigurationSource source = registerMockComponent(ConfigurationSource.class);
    final ContextualAuthorizationManager cam = registerMockComponent(ContextualAuthorizationManager.class);
    getMockery().checking(new Expectations() {

        {
            oneOf(source).getProperty("groovy.compilationCustomizers", Collections.emptyList());
            will(returnValue(Arrays.asList("secure")));
            oneOf(cam).hasAccess(Right.PROGRAM);
            will(returnValue(false));
        }
    });
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngineFactory groovyScriptEngineFactory = getComponentManager().getInstance(ScriptEngineFactory.class, "groovy");
    manager.registerEngineName("groovy", groovyScriptEngineFactory);
    this.engine = manager.getEngineByName("groovy");
}
Also used : ContextualAuthorizationManager(org.xwiki.security.authorization.ContextualAuthorizationManager) Expectations(org.jmock.Expectations) ConfigurationSource(org.xwiki.configuration.ConfigurationSource) ScriptEngineFactory(javax.script.ScriptEngineFactory) ScriptEngineManager(javax.script.ScriptEngineManager)

Example 10 with ConfigurationSource

use of org.xwiki.configuration.ConfigurationSource in project xwiki-platform by xwiki.

the class DefaultMailStorageConfigurationTest method discardSuccessStatusesFalseWhenDefinedInMailConfig.

@Test
public void discardSuccessStatusesFalseWhenDefinedInMailConfig() throws Exception {
    ConfigurationSource mailConfigSource = this.mocker.getInstance(ConfigurationSource.class, "mailsend");
    when(mailConfigSource.getProperty("discardSuccessStatuses")).thenReturn(0);
    assertEquals(false, this.mocker.getComponentUnderTest().discardSuccessStatuses());
}
Also used : ConfigurationSource(org.xwiki.configuration.ConfigurationSource) Test(org.junit.Test)

Aggregations

ConfigurationSource (org.xwiki.configuration.ConfigurationSource)42 Test (org.junit.Test)29 Properties (java.util.Properties)7 XWikiContext (com.xpn.xwiki.XWikiContext)3 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)3 XWikiCfgConfigurationSource (com.xpn.xwiki.internal.XWikiCfgConfigurationSource)3 ArrayList (java.util.ArrayList)3 Expectations (org.jmock.Expectations)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 Parser (org.xwiki.rendering.parser.Parser)3 Syntax (org.xwiki.rendering.syntax.Syntax)3 SyntaxType (org.xwiki.rendering.syntax.SyntaxType)3 ContextualAuthorizationManager (org.xwiki.security.authorization.ContextualAuthorizationManager)3 CoreConfiguration (com.xpn.xwiki.CoreConfiguration)2 File (java.io.File)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2