Exemplo n.º 1
0
  @Test
  public void testBug49922() throws Exception {

    // Set up a container
    Tomcat tomcat = getTomcatInstance();

    File root = new File("test/webapp-3.0");
    tomcat.addWebapp("", root.getAbsolutePath());

    tomcat.start();
    ByteChunk result = new ByteChunk();

    // Check filter and servlet aren't called
    int rc = getUrl("http://localhost:" + getPort() + "/bug49922/foo", result, null);
    assertEquals(HttpServletResponse.SC_NOT_FOUND, rc);
    assertTrue(result.getLength() > 0);

    // Check extension mapping works
    result = getUrl("http://localhost:" + getPort() + "/foo.do");
    assertEquals("FilterServlet", result.toString());

    // Check path mapping works
    result = getUrl("http://localhost:" + getPort() + "/bug49922/servlet");
    assertEquals("FilterServlet", result.toString());

    // Check servlet name mapping works
    result = getUrl("http://localhost:" + getPort() + "/foo.od");
    assertEquals("FilterServlet", result.toString());

    // Check filter is only called once
    result = getUrl("http://localhost:" + getPort() + "/bug49922/servlet/foo.do");
    assertEquals("FilterServlet", result.toString());
    result = getUrl("http://localhost:" + getPort() + "/bug49922/servlet/foo.od");
    assertEquals("FilterServlet", result.toString());

    // Check dispatcher mapping
    result = getUrl("http://localhost:" + getPort() + "/bug49922/target");
    assertEquals("Target", result.toString());
    result = getUrl("http://localhost:" + getPort() + "/bug49922/forward");
    assertEquals("FilterTarget", result.toString());
    result = getUrl("http://localhost:" + getPort() + "/bug49922/include");
    assertEquals("IncludeFilterTarget", result.toString());
  }
Exemplo n.º 2
0
  @Test
  public void testBug50015() throws Exception {
    // Set up a container
    Tomcat tomcat = getTomcatInstance();

    // Must have a real docBase - just use temp
    File docBase = new File(System.getProperty("java.io.tmpdir"));
    Context ctx = tomcat.addContext("", docBase.getAbsolutePath());

    // Setup realm
    MapRealm realm = new MapRealm();
    realm.addUser("tomcat", "tomcat");
    realm.addUserRole("tomcat", "tomcat");
    ctx.setRealm(realm);

    // Configure app for BASIC auth
    LoginConfig lc = new LoginConfig();
    lc.setAuthMethod("BASIC");
    ctx.setLoginConfig(lc);
    ctx.getPipeline().addValve(new BasicAuthenticator());

    // Add ServletContainerInitializer
    ServletContainerInitializer sci = new Bug50015SCI();
    ctx.addServletContainerInitializer(sci, null);

    // Start the context
    tomcat.start();

    // Request the first servlet
    ByteChunk bc = new ByteChunk();
    int rc = getUrl("http://localhost:" + getPort() + "/bug50015", bc, null);

    // Check for a 401
    assertNotSame("OK", bc.toString());
    assertEquals(401, rc);
  }