Return-Path: Mailing-List: contact tomcat-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list tomcat-dev@jakarta.apache.org Received: (qmail 25830 invoked by uid 500); 22 Feb 2001 01:07:31 -0000 Delivered-To: apmail-jakarta-tomcat-4.0-cvs@apache.org Received: (qmail 25825 invoked by uid 1059); 22 Feb 2001 01:07:29 -0000 Date: 22 Feb 2001 01:07:29 -0000 Message-ID: <20010222010729.25824.qmail@apache.org> From: craigmcc@apache.org To: jakarta-tomcat-4.0-cvs@apache.org Subject: cvs commit: jakarta-tomcat-4.0/tester/web/WEB-INF web.xml craigmcc 01/02/21 17:07:29 Modified: tester/src/bin tester.xml tester/web/WEB-INF web.xml Added: tester/src/tester/org/apache/tester Jndi01.java Jndi02.java Log: Add the first two of a series of unit tests for the JNDI naming context that is provided to web applications by Tomcat 4.0. The initial tests exercize the ability to retrieve environment entries created by elements in the web application deployment descriptor. NOTE: One of the requirements on the provided context is that applications should not be able to modify it. The context returned by Tomcat 4.0 currently fails to enforce this, so the calls to the Jndi01 tests are currently commented out. Revision Changes Path 1.16 +26 -1 jakarta-tomcat-4.0/tester/src/bin/tester.xml Index: tester.xml =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/tester/src/bin/tester.xml,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- tester.xml 2001/02/21 21:39:50 1.15 +++ tester.xml 2001/02/22 01:07:23 1.16 @@ -12,7 +12,7 @@ - + @@ -120,6 +120,31 @@ request="${context.path}/WrappedErrorPage03" debug="${debug}" outContent="ErrorPage04 PASSED"/> + + + + + + + + + + + + + 1.1 jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Jndi01.java Index: Jndi01.java =================================================================== /* ========================================================================= * * * * The Apache Software License, Version 1.1 * * * * Copyright (c) 1999, 2000, 2001 The Apache Software Foundation. * * All rights reserved. * * * * ========================================================================= * * * * Redistribution and use in source and binary forms, with or without modi- * * fication, are permitted provided that the following conditions are met: * * * * 1. Redistributions of source code must retain the above copyright notice * * notice, this list of conditions and the following disclaimer. * * * * 2. Redistributions in binary form must reproduce the above copyright * * notice, this list of conditions and the following disclaimer in the * * documentation and/or other materials provided with the distribution. * * * * 3. The end-user documentation included with the redistribution, if any, * * must include the following acknowlegement: * * * * "This product includes software developed by the Apache Software * * Foundation ." * * * * Alternately, this acknowlegement may appear in the software itself, if * * and wherever such third-party acknowlegements normally appear. * * * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * * Foundation" must not be used to endorse or promote products derived * * from this software without prior written permission. For written * * permission, please contact . * * * * 5. Products derived from this software may not be called "Apache" nor may * * "Apache" appear in their names without prior written permission of the * * Apache Software Foundation. * * * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES * * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * * THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY * * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * * POSSIBILITY OF SUCH DAMAGE. * * * * ========================================================================= * * * * This software consists of voluntary contributions made by many indivi- * * duals on behalf of the Apache Software Foundation. For more information * * on the Apache Software Foundation, please see . * * * * ========================================================================= */ package org.apache.tester; import java.io.*; import javax.naming.Binding; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingEnumeration; import javax.naming.NamingException; import javax.servlet.*; import javax.servlet.http.*; /** * Negative test for ensuring that the naming context provided by the servlet * container is immutable. No attempt to add, modify, or delete any binding * should succeed. * * @author Craig R. McClanahan * @version $Revision: 1.1 $ $Date: 2001/02/22 01:07:26 $ */ public class Jndi01 extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // Prepare to render our output response.setContentType("text/plain"); PrintWriter writer = response.getWriter(); StringBuffer sb = new StringBuffer(); boolean ok = true; Object value = null; // Look up the initial context provided by our servlet container Context initContext = null; try { initContext = new InitialContext(); } catch (NamingException e) { log("Create initContext", e); sb.append(" Cannot create initContext."); ok = false; } // Look up the environment context provided to our web application Context envContext = null; try { if (ok) { value = initContext.lookup("java:comp/env"); envContext = (Context) value; if (envContext == null) { sb.append(" Missing envContext."); ok = false; } } } catch (ClassCastException e) { sb.append(" envContext class is "); sb.append(value.getClass().getName()); sb.append("."); ok = false; } catch (NamingException e) { log("Create envContext", e); sb.append(" Cannot create envContext."); ok = false; } // Attempt to add a new binding to our environment context try { if (ok) { envContext.bind("newEntry", "New Value"); sb.append(" Allowed bind()."); value = envContext.lookup("newEntry"); if (value != null) sb.append(" Allowed lookup() of added entry."); } } catch (Throwable e) { log("Add binding", e); } // Attempt to change the value of an existing binding try { if (ok) { envContext.rebind("stringEntry", "Changed Value"); sb.append(" Allowed rebind()."); value = envContext.lookup("stringEntry"); if ((value != null) && (value instanceof String) && "Changed Value".equals((String) value)) sb.append(" Allowed lookup() of changed entry."); } } catch (Throwable e) { log("Change binding", e); } // Attempt to delete an existing binding try { if (ok) { envContext.unbind("byteEntry"); sb.append(" Allowed unbind()."); value = envContext.lookup("byteEntry"); if (value == null) sb.append(" Allowed unbind of deleted entry."); } } catch (Throwable e) { log("Delete binding", e); } // Report our ultimate success or failure if (sb.length() < 1) writer.println("Jndi01 PASSED"); else { writer.print("Jndi01 FAILED -"); writer.println(sb); } // Add wrapper messages as required while (true) { String message = StaticLogger.read(); if (message == null) break; writer.println(message); } StaticLogger.reset(); } } 1.1 jakarta-tomcat-4.0/tester/src/tester/org/apache/tester/Jndi02.java Index: Jndi02.java =================================================================== /* ========================================================================= * * * * The Apache Software License, Version 1.1 * * * * Copyright (c) 1999, 2000, 2001 The Apache Software Foundation. * * All rights reserved. * * * * ========================================================================= * * * * Redistribution and use in source and binary forms, with or without modi- * * fication, are permitted provided that the following conditions are met: * * * * 1. Redistributions of source code must retain the above copyright notice * * notice, this list of conditions and the following disclaimer. * * * * 2. Redistributions in binary form must reproduce the above copyright * * notice, this list of conditions and the following disclaimer in the * * documentation and/or other materials provided with the distribution. * * * * 3. The end-user documentation included with the redistribution, if any, * * must include the following acknowlegement: * * * * "This product includes software developed by the Apache Software * * Foundation ." * * * * Alternately, this acknowlegement may appear in the software itself, if * * and wherever such third-party acknowlegements normally appear. * * * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * * Foundation" must not be used to endorse or promote products derived * * from this software without prior written permission. For written * * permission, please contact . * * * * 5. Products derived from this software may not be called "Apache" nor may * * "Apache" appear in their names without prior written permission of the * * Apache Software Foundation. * * * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES * * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * * THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY * * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * * POSSIBILITY OF SUCH DAMAGE. * * * * ========================================================================= * * * * This software consists of voluntary contributions made by many indivi- * * duals on behalf of the Apache Software Foundation. For more information * * on the Apache Software Foundation, please see . * * * * ========================================================================= */ package org.apache.tester; import java.io.*; import javax.naming.Binding; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingEnumeration; import javax.naming.NamingException; import javax.servlet.*; import javax.servlet.http.*; /** * Positive test for looking up environment entries from the naming context * provided by the servlet container. The looked-up values are initialized * via <env-entry> elements in the web application * deployment descriptor. * * @author Craig R. McClanahan * @version $Revision: 1.1 $ $Date: 2001/02/22 01:07:26 $ */ public class Jndi02 extends HttpServlet { // Names of the known elements String names[] = { "booleanEntry", "byteEntry", "doubleEntry", "floatEntry", "integerEntry", "longEntry", "stringEntry" }; public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // Prepare to render our output response.setContentType("text/plain"); PrintWriter writer = response.getWriter(); StringBuffer sb = new StringBuffer(); boolean ok = true; Object value = null; // Look up the initial context provided by our servlet container Context initContext = null; try { initContext = new InitialContext(); } catch (NamingException e) { log("Create initContext", e); sb.append(" Cannot create initContext."); ok = false; } // Look up the environment context provided to our web application Context envContext = null; try { if (ok) { value = initContext.lookup("java:comp/env"); envContext = (Context) value; if (envContext == null) { sb.append(" Missing envContext."); ok = false; } } } catch (ClassCastException e) { sb.append(" envContext class is "); sb.append(value.getClass().getName()); sb.append("."); ok = false; } catch (NamingException e) { log("Create envContext", e); sb.append(" Cannot create envContext."); ok = false; } // Validate the booleanEntry environment entry try { if (ok) { value = envContext.lookup("booleanEntry"); Boolean booleanValue = (Boolean) value; if (!(booleanValue.booleanValue() == true)) { sb.append(" booleanValue is "); sb.append(booleanValue); sb.append("."); } } } catch (ClassCastException e) { sb.append(" booleanValue class is "); sb.append(value.getClass().getName()); sb.append("."); } catch (NullPointerException e) { sb.append(" booleanValue is missing."); } catch (NamingException e) { log("Get booleanValue", e); sb.append(" Cannot get booleanValue."); } // Validate the byteEntry environment entry try { if (ok) { value = envContext.lookup("byteEntry"); Byte byteValue = (Byte) value; if (!(byteValue.byteValue() == 123)) { sb.append(" byteValue is "); sb.append(byteValue); sb.append("."); } } } catch (ClassCastException e) { sb.append(" byteValue class is "); sb.append(value.getClass().getName()); sb.append("."); } catch (NullPointerException e) { sb.append(" byteValue is missing."); } catch (NamingException e) { log("Get byteValue", e); sb.append(" Cannot get byteValue."); } // Validate the doubleEntry environment entry try { if (ok) { value = envContext.lookup("doubleEntry"); Double doubleValue = (Double) value; if (!(doubleValue.doubleValue() == 123.45)) { sb.append(" doubleValue is "); sb.append(doubleValue); sb.append("."); } } } catch (ClassCastException e) { sb.append(" doubleValue class is "); sb.append(value.getClass().getName()); sb.append("."); } catch (NullPointerException e) { sb.append(" doubleValue is missing."); } catch (NamingException e) { log("Get doubleValue", e); sb.append(" Cannot get doubleValue."); } // Validate the floatEntry environment entry try { if (ok) { value = envContext.lookup("floatEntry"); Float floatValue = (Float) value; float difference = floatValue.floatValue() - ((float) 54.32); if ((difference < ((float) -0.01)) || (difference > ((float) 0.01))) { sb.append(" floatValue is "); sb.append(floatValue); sb.append("."); } } } catch (ClassCastException e) { sb.append(" floatValue class is "); sb.append(value.getClass().getName()); sb.append("."); } catch (NullPointerException e) { sb.append(" floatValue is missing."); } catch (NamingException e) { log("Get floatValue", e); sb.append(" Cannot get floatValue."); } // Validate the integerEntry environment entry try { if (ok) { value = envContext.lookup("integerEntry"); Integer integerValue = (Integer) value; if (!(integerValue.intValue() == 12345)) { sb.append(" integerValue is "); sb.append(integerValue); sb.append("."); } } } catch (ClassCastException e) { sb.append(" integerValue class is "); sb.append(value.getClass().getName()); sb.append("."); } catch (NullPointerException e) { sb.append(" integerValue is missing."); } catch (NamingException e) { log("Get integerValue", e); sb.append(" Cannot get integerValue."); } // Validate the longEntry environment entry try { if (ok) { value = envContext.lookup("longEntry"); Long longValue = (Long) value; if (!(longValue.longValue() == 54321)) { sb.append(" longValue is "); sb.append(longValue); sb.append("."); } } } catch (ClassCastException e) { sb.append(" longValue class is "); sb.append(value.getClass().getName()); sb.append("."); } catch (NullPointerException e) { sb.append(" longValue is missing."); } catch (NamingException e) { log("Get longValue", e); sb.append(" Cannot get longValue."); } // Validate the stringEntry environment entry try { if (ok) { value = envContext.lookup("stringEntry"); String stringValue = (String) value; if (!"String Value".equals(stringValue)) { sb.append(" stringValue is "); sb.append(stringValue); sb.append("."); } } } catch (ClassCastException e) { sb.append(" stringValue class is "); sb.append(value.getClass().getName()); sb.append("."); } catch (NullPointerException e) { sb.append(" stringValue is missing."); } catch (NamingException e) { log("Get stringValue", e); sb.append(" Cannot get stringValue."); } // Validate that we can enumerate the contents of our environment try { if (ok) { int counts[] = new int[names.length]; for (int i = 0; i < names.length; i++) counts[i] = 0; NamingEnumeration enum = initContext.listBindings("java:comp/env"); while (enum.hasMore()) { Binding binding = (Binding) enum.next(); String name = binding.getName(); boolean found = false; for (int i = 0; i < names.length; i++) { if (name.equals(names[i])) { counts[i]++; found = true; break; } } if (!found) StaticLogger.write("Found binding for '" + name + "'"); } for (int i = 0; i < names.length; i++) { if (counts[i] < 1) { sb.append(" Missing binding for "); sb.append(names[i]); sb.append("."); } else if (counts[i] > 1) { sb.append(" Found "); sb.append(counts[i]); sb.append(" bindings for "); sb.append(names[i]); sb.append("."); } } } } catch (NamingException e) { log("Enumerate envContext", e); sb.append(" Cannot enumerate envContext"); } // Report our ultimate success or failure if (sb.length() < 1) writer.println("Jndi02 PASSED"); else { writer.print("Jndi02 FAILED -"); writer.println(sb); } // Add wrapper messages as required while (true) { String message = StaticLogger.read(); if (message == null) break; writer.println(message); } StaticLogger.reset(); } } 1.12 +85 -0 jakarta-tomcat-4.0/tester/web/WEB-INF/web.xml Index: web.xml =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/tester/web/WEB-INF/web.xml,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- web.xml 2001/02/21 21:39:51 1.11 +++ web.xml 2001/02/22 01:07:27 1.12 @@ -111,6 +111,16 @@ + HttpFilter + /WrappedJndi01 + + + + HttpFilter + /WrappedJndi02 + + + GenericFilter /WrappedReset01 @@ -249,6 +259,16 @@ + Jndi01 + org.apache.tester.Jndi01 + + + + Jndi02 + org.apache.tester.Jndi02 + + + Reset01 org.apache.tester.Reset01 @@ -467,6 +487,26 @@ + Jndi01 + /Jndi01 + + + + Jndi01 + /WrappedJndi01 + + + + Jndi02 + /Jndi02 + + + + Jndi02 + /WrappedJndi02 + + + Reset01 /Reset01 @@ -596,6 +636,51 @@ BASIC Authentication Servlet + + + + + + booleanEntry + true + java.lang.Boolean + + + + byteEntry + 123 + java.lang.Byte + + + + doubleEntry + 123.45 + java.lang.Double + + + + floatEntry + 54.32 + java.lang.Float + + + + integerEntry + 12345 + java.lang.Integer + + + + longEntry + 54321 + java.lang.Long + + + + stringEntry + String Value + java.lang.String +