コード例 #1
0
 private static boolean isAuthorized(String mimeType) {
   ConfigurationSource configuration =
       Utils.getComponent(ConfigurationSource.class, "xwikiproperties");
   if (configuration.containsKey(BLACKLIST_PROPERTY)
       && !configuration.containsKey(WHITELIST_PROPERTY)) {
     List<String> blackList =
         (configuration.getProperty(BLACKLIST_PROPERTY, Collections.<String>emptyList()));
     return !blackList.contains(mimeType);
   } else {
     List<String> whiteList = configuration.getProperty(WHITELIST_PROPERTY, MIMETYPE_WHITELIST);
     return whiteList.contains(mimeType);
   }
 }
コード例 #2
0
  @Test
  public void deleteAllDocumentsAndWithoutSendingToTrash() throws Exception {
    XWiki xwiki = new XWiki();

    XWikiDocument document = mock(XWikiDocument.class);
    DocumentReference reference = new DocumentReference("wiki", "space", "page");
    when(document.getDocumentReference()).thenReturn(reference);

    // Make sure we have a trash for the test.
    XWikiRecycleBinStoreInterface recycleBinStoreInterface =
        mock(XWikiRecycleBinStoreInterface.class);
    xwiki.setRecycleBinStore(recycleBinStoreInterface);
    when(xwikiCfgConfigurationSource.getProperty("xwiki.recyclebin", "1")).thenReturn("1");

    // Configure the mocked Store to later verify if it's called
    XWikiStoreInterface storeInterface = mock(XWikiStoreInterface.class);
    xwiki.setStore(storeInterface);
    XWikiContext xwikiContext = mock(XWikiContext.class);

    xwiki.deleteAllDocuments(document, false, xwikiContext);

    // Verify that saveToRecycleBin is never called since otherwise it would mean the doc has been
    // saved in the
    // trash
    verify(recycleBinStoreInterface, never())
        .saveToRecycleBin(
            any(XWikiDocument.class),
            any(String.class),
            any(Date.class),
            any(XWikiContext.class),
            any(Boolean.class));

    // Verify that deleteXWikiDoc() is called
    verify(storeInterface).deleteXWikiDoc(document, xwikiContext);
  }
コード例 #3
0
 protected XWikiUser getUser() {
   XWikiUser user = getContext().getXWikiUser();
   String defaultUserName =
       xwikiPropConfigSource.getProperty("celements.mandatory.defaultGlobalUserName");
   if (StringUtils.isNotBlank(defaultUserName)) {
     user = new XWikiUser(defaultUserName, true);
   }
   return user;
 }
コード例 #4
0
  @Test
  public void testProvideData() throws Exception {
    server.register(
        "/*",
        new HttpRequestHandler() {
          @Override
          public void handle(HttpRequest request, HttpResponse response, HttpContext context)
              throws IOException {
            response.setEntity(new StringEntity("{\"ip\":\"192.168.1.1\"}"));
          }
        });

    ConfigurationSource configuration = this.mocker.getInstance(ConfigurationSource.class);
    when(configuration.getProperty(IPPingDataProvider.IP_FETCH_URL_PROPERTY))
        .thenReturn(serverURL + "/get/Stats/Id");

    Map<String, Object> actual = this.mocker.getComponentUnderTest().provideData();
    JSONAssert.assertEquals("{\"ip\":\"192.168.1.1\"}", new JSONObject(actual), false);
  }
コード例 #5
0
 XWikiDocument getFileBaseDoc() throws FileBaseLoadException {
   String fileBaseDocFN = configuration.getProperty(FILEBASE_CONFIG_FIELD);
   if (!Strings.isNullOrEmpty(fileBaseDocFN) && !"-".equals(fileBaseDocFN)) {
     try {
       DocumentReference fileBaseDocRef = webUtils.resolveDocumentReference(fileBaseDocFN);
       return modelAccess.getOrCreateDocument(fileBaseDocRef);
     } catch (DocumentLoadException exp) {
       _LOGGER.error("Failed to load FileBaseDocument.", exp);
       throw new FileBaseLoadException(fileBaseDocFN, exp);
     }
   } else {
     throw new FileBaseLoadException(fileBaseDocFN);
   }
 }
コード例 #6
0
 @Override
 public boolean isParentChildMechanismEnabled() {
   return "parentchild".equals(configurationSource.getProperty("core.hierarchyMode", "reference"));
 }
コード例 #7
0
  @Test
  public void getSpacePreference() throws Exception {
    this.mocker.registerMockComponent(ConfigurationSource.class, "wiki");
    ConfigurationSource spaceConfiguration =
        this.mocker.registerMockComponent(ConfigurationSource.class, "space");

    when(this.xwikiCfgConfigurationSource.getProperty(anyString(), anyString()))
        .then(
            new Answer<String>() {
              @Override
              public String answer(InvocationOnMock invocation) throws Throwable {
                return invocation.getArgumentAt(1, String.class);
              }
            });

    WikiReference wikiReference = new WikiReference("wiki");
    SpaceReference space1Reference = new SpaceReference("space1", wikiReference);
    SpaceReference space2Reference = new SpaceReference("space2", space1Reference);

    // Without preferences and current doc

    assertEquals("", this.xwiki.getSpacePreference("pref", this.context));
    assertEquals(
        "defaultvalue", this.xwiki.getSpacePreference("pref", "defaultvalue", this.context));
    assertEquals("", this.xwiki.getSpacePreference("pref", space2Reference, this.context));
    assertEquals(
        "defaultvalue",
        this.xwiki.getSpacePreference("pref", space2Reference, "defaultvalue", this.context));

    // Without preferences but with current doc

    this.context.setDoc(new XWikiDocument(new DocumentReference("document", space2Reference)));

    assertEquals("", this.xwiki.getSpacePreference("pref", this.context));
    assertEquals(
        "defaultvalue", this.xwiki.getSpacePreference("pref", "defaultvalue", this.context));
    assertEquals("", this.xwiki.getSpacePreference("pref", space2Reference, this.context));
    assertEquals(
        "defaultvalue",
        this.xwiki.getSpacePreference("pref", space2Reference, "defaultvalue", this.context));

    // With preferences

    final Map<String, Map<String, String>> spacesPreferences = new HashMap<>();
    Map<String, String> space1Preferences = new HashMap<>();
    space1Preferences.put("pref", "prefvalue1");
    space1Preferences.put("pref1", "pref1value1");
    Map<String, String> space2Preferences = new HashMap<>();
    space2Preferences.put("pref", "prefvalue2");
    space2Preferences.put("pref2", "pref2value2");
    spacesPreferences.put(space1Reference.getName(), space1Preferences);
    spacesPreferences.put(space2Reference.getName(), space2Preferences);

    when(spaceConfiguration.getProperty(anyString(), same(String.class)))
        .then(
            new Answer<String>() {
              @Override
              public String answer(InvocationOnMock invocation) throws Throwable {
                if (context.getDoc() != null) {
                  Map<String, String> spacePreferences =
                      spacesPreferences.get(
                          context.getDoc().getDocumentReference().getParent().getName());
                  if (spacePreferences != null) {
                    return spacePreferences.get(invocation.getArgumentAt(0, String.class));
                  }
                }

                return null;
              }
            });

    this.context.setDoc(new XWikiDocument(new DocumentReference("document", space1Reference)));
    assertEquals("prefvalue1", this.xwiki.getSpacePreference("pref", this.context));
    assertEquals("prefvalue1", this.xwiki.getSpacePreference("pref", "defaultvalue", this.context));
    assertEquals("pref1value1", this.xwiki.getSpacePreference("pref1", this.context));
    assertEquals("", this.xwiki.getSpacePreference("pref2", this.context));

    this.context.setDoc(new XWikiDocument(new DocumentReference("document", space2Reference)));
    assertEquals("prefvalue2", this.xwiki.getSpacePreference("pref", this.context));
    assertEquals("prefvalue2", this.xwiki.getSpacePreference("pref", "defaultvalue", this.context));
    assertEquals("pref1value1", this.xwiki.getSpacePreference("pref1", this.context));
    assertEquals("pref2value2", this.xwiki.getSpacePreference("pref2", this.context));

    assertEquals("", this.xwiki.getSpacePreference("nopref", space1Reference, this.context));
    assertEquals(
        "defaultvalue",
        this.xwiki.getSpacePreference("nopref", space1Reference, "defaultvalue", this.context));
    assertEquals(
        "prefvalue1", this.xwiki.getSpacePreference("pref", space1Reference, this.context));
    assertEquals(
        "prefvalue1",
        this.xwiki.getSpacePreference("pref", space1Reference, "defaultvalue", this.context));
    assertEquals(
        "pref1value1", this.xwiki.getSpacePreference("pref1", space1Reference, this.context));
    assertEquals("", this.xwiki.getSpacePreference("pref2", space1Reference, this.context));

    assertEquals("", this.xwiki.getSpacePreference("nopref", space2Reference, this.context));
    assertEquals(
        "defaultvalue",
        this.xwiki.getSpacePreference("nopref", space2Reference, "defaultvalue", this.context));
    assertEquals(
        "prefvalue2", this.xwiki.getSpacePreference("pref", space2Reference, this.context));
    assertEquals(
        "prefvalue2",
        this.xwiki.getSpacePreference("pref", space2Reference, "defaultvalue", this.context));
    assertEquals(
        "pref1value1", this.xwiki.getSpacePreference("pref1", space2Reference, this.context));
    assertEquals(
        "pref2value2", this.xwiki.getSpacePreference("pref2", space2Reference, this.context));
  }