@Test
  public void testServletAsAnonymous() throws Exception {

    HttpClient httpClient = new HttpClient();

    HttpMethod getMethod = null;
    try {
      // ------------ Test anonymous user not allowed ----------------
      getMethod =
          new GetMethod(
              "http://localhost:18080/authentication/token?applicationName=myFavoriteApp&deviceId=dead-beaf-cafe-babe&permission=rw");
      int status = httpClient.executeMethod(getMethod);
      assertEquals(401, status);

      // ------------ Test anonymous user allowed ----------------
      harness.deployContrib(
          "org.nuxeo.ecm.platform.login.token.test",
          "OSGI-INF/test-token-authentication-allow-anonymous-token-contrib.xml");

      status = httpClient.executeMethod(getMethod);
      assertEquals(201, status);
      String token = getMethod.getResponseBodyAsString();
      assertNotNull(token);
      assertNotNull(tokenAuthenticationService.getUserName(token));
      assertEquals(1, tokenAuthenticationService.getTokenBindings("Guest").size());

      harness.undeployContrib(
          "org.nuxeo.ecm.platform.login.token.test",
          "OSGI-INF/test-token-authentication-allow-anonymous-token-contrib.xml");
    } finally {
      getMethod.releaseConnection();
    }
  }
Esempio n. 2
0
  public URL getRepositoryContrib(FeaturesRunner runner) {
    String msg;
    if (isVCS()) {
      msg = "Deploying a VCS repository";
    } else if (isDBS()) {
      msg = "Deploying a DBS repository using " + coreType;
    } else {
      throw new NuxeoException("Unkown test configuration (not vcs/dbs)");
    }
    // System.out used on purpose, don't remove
    System.out.println(getClass().getSimpleName() + ": " + msg);
    log.info(msg);

    String contribPath;
    String bundleName;
    if (isVCS()) {
      bundleName = "org.nuxeo.ecm.core.storage.sql.test";
      contribPath = databaseHelper.getDeploymentContrib();
    } else {
      bundleName = "org.nuxeo.ecm.core.test";
      if (isDBSMem()) {
        contribPath = "OSGI-INF/test-storage-repo-mem-contrib.xml";
      } else if (isDBSMongoDB()) {
        contribPath = "OSGI-INF/test-storage-repo-mongodb-contrib.xml";
      } else {
        throw new NuxeoException("Unkown DBS test configuration (not mem/mongodb)");
      }
    }
    RuntimeHarness harness = runner.getFeature(RuntimeFeature.class).getHarness();
    Bundle bundle = harness.getOSGiAdapter().getRegistry().getBundle(bundleName);
    URL contribURL = bundle.getEntry(contribPath);
    assertNotNull("deployment contrib " + contribPath + " not found", contribURL);
    return contribURL;
  }
Esempio n. 3
0
 public URL getBlobManagerContrib(FeaturesRunner runner) {
   String bundleName = "org.nuxeo.ecm.core.test";
   String contribPath = "OSGI-INF/test-storage-blob-contrib.xml";
   RuntimeHarness harness = runner.getFeature(RuntimeFeature.class).getHarness();
   Bundle bundle = harness.getOSGiAdapter().getRegistry().getBundle(bundleName);
   URL contribURL = bundle.getEntry(contribPath);
   assertNotNull("deployment contrib " + contribPath + " not found", contribURL);
   return contribURL;
 }
Esempio n. 4
0
  @Test
  public void testFileImportersMerge() throws Exception {
    assertNotNull(harness);
    URL url = getClass().getClassLoader().getResource("nxfilemanager-test-override.xml");
    assertNotNull(url);
    harness.deployTestContrib(FileManagerUTConstants.FILEMANAGER_BUNDLE, url);

    FileManagerService fileManagerService = (FileManagerService) service;

    FileImporter plugin = fileManagerService.getPluginByName("pluginWithDocType4merge");
    assertNotNull(plugin);
    assertNotNull(plugin.getDocType());
    assertEquals("Picture", plugin.getDocType());
    assertEquals(2, plugin.getFilters().size());
    List<String> filters = plugin.getFilters();
    assertTrue(filters.contains("image/jpeg"));
    assertTrue(filters.contains("image/png"));

    plugin = fileManagerService.getPluginByName("plug4merge");
    assertNotNull(plugin.getDocType());
    assertEquals("Note", plugin.getDocType());
    assertEquals(3, plugin.getFilters().size());
    filters = plugin.getFilters();
    assertTrue(filters.contains("text/plain"));
    assertTrue(filters.contains("text/rtf"));
    assertTrue(filters.contains("text/xml"));
  }