[seam-commits] Seam SVN: r8329 - in trunk: build and 11 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Wed Jun 4 18:53:43 EDT 2008


Author: pete.muir at jboss.org
Date: 2008-06-04 18:53:43 -0400 (Wed, 04 Jun 2008)
New Revision: 8329

Added:
   trunk/examples/mail/src/org/jboss/seam/example/mail/test/sanitization.xhtml
   trunk/src/mail/org/jboss/seam/mail/ui/Header.java
   trunk/src/test/mail/
   trunk/src/test/mail/unit/
   trunk/src/test/mail/unit/org/
   trunk/src/test/mail/unit/org/jboss/
   trunk/src/test/mail/unit/org/jboss/seam/
   trunk/src/test/mail/unit/org/jboss/seam/test/
   trunk/src/test/mail/unit/org/jboss/seam/test/mail/
   trunk/src/test/mail/unit/org/jboss/seam/test/mail/unit/
   trunk/src/test/mail/unit/org/jboss/seam/test/mail/unit/HeaderTest.java
   trunk/src/test/mail/unit/org/jboss/seam/test/mail/unit/testng.xml
Modified:
   trunk/build.xml
   trunk/build/mail.pom.xml
   trunk/examples/mail/src/org/jboss/seam/example/mail/test/MailTest.java
   trunk/src/mail/org/jboss/seam/mail/ui/AddressComponent.java
   trunk/src/mail/org/jboss/seam/mail/ui/UIAttachment.java
   trunk/src/mail/org/jboss/seam/mail/ui/UIBody.java
   trunk/src/mail/org/jboss/seam/mail/ui/UIHeader.java
   trunk/src/mail/org/jboss/seam/mail/ui/UIMessage.java
   trunk/src/mail/org/jboss/seam/mail/ui/UISubject.java
Log:
JBSEAM-3071

Modified: trunk/build/mail.pom.xml
===================================================================
--- trunk/build/mail.pom.xml	2008-06-04 15:55:09 UTC (rev 8328)
+++ trunk/build/mail.pom.xml	2008-06-04 22:53:43 UTC (rev 8329)
@@ -60,6 +60,19 @@
       <artifactId>el-api</artifactId>
       <scope>provided</scope>
     </dependency>
+    
+    <dependency>
+      <groupId>org.testng</groupId>
+      <artifactId>testng</artifactId>
+      <version>5.6</version>
+      <optional>true</optional>
+      <exclusions>
+        <exclusion>
+          <groupId>junit</groupId>
+          <artifactId>junit</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
 
   </dependencies>
 

Modified: trunk/build.xml
===================================================================
--- trunk/build.xml	2008-06-04 15:55:09 UTC (rev 8328)
+++ trunk/build.xml	2008-06-04 22:53:43 UTC (rev 8329)
@@ -24,6 +24,7 @@
 	<property name="classes.remoting.dir" value="${classes.dir}/remotingclasses" />
 	<property name="classes.gen.dir" value="${classes.dir}/genclasses" />
 	<property name="classes.test.dir" value="${classes.dir}/testclasses" />
+	<property name="classes.mail.test.dir" value="${classes.dir}/mailtestclasses" />
 
 	<property name="ui.dir" value="${basedir}/ui" />
 	<property name="seamgen.dir" value="${basedir}/seam-gen" />
@@ -42,6 +43,7 @@
 	<property name="src.remoting.dir" value="src/remoting" />
 	<property name="src.test.dir" value="src/test" />
 	<property name="src.unit.test.dir" value="${src.test.dir}/unit" />
+	<property name="src.mail.unit.test.dir" value="${src.test.dir}/mail/unit" />
 
 	<!-- Library directories -->
 	<property name="eejb.conf.dir" value="${basedir}/bootstrap" />
@@ -643,27 +645,32 @@
 
 	<!-- ########################### TEST TARGETS ###########################-->
 
-	<target name="compiletest" depends="inittestcore,select-compiler,antlr">
-		<compile classesdir="${classes.test.dir}" srcdir="${src.unit.test.dir}" classpath="test.compile.path" />
-	</target>
+	
 
-	<target name="inittestcore" depends="build">
-		<init classesdir="${classes.test.dir}" srcdir="${src.unit.test.dir}" modulename="core" pom="${core.pom}" scope="test" message="" />
-		<copy todir="${classes.test.core.dir}">
-			<fileset dir="${classes.core.dir}" includes="**/*.*" />
-		</copy>
-		<inlineDependencies scope="compile" id="remoting">
-			<dependency groupId="org.jboss.seam" artifactId="jboss-seam-remoting" version="${complete.version}" />
-		</inlineDependencies>
-		<path id="test.compile.path">
-			<path refid="test.core.path" />
-			<path path="${classes.test.core.dir}" />
-			<path refid="compile.remoting.path" />
-		</path>
-	</target>
 
 
-	<target name="unittest" depends="inittestcore,compiletest,getemma" description="Run the Unit tests">
+	<target name="unittest" depends="unittestcore, unittestmail" description="Run the Unit tests" />
+
+	<target name="compiletest" depends="inittestcore,select-compiler,antlr">
+      <compile classesdir="${classes.test.dir}" srcdir="${src.unit.test.dir}" classpath="test.compile.path" />
+   </target>
+	
+  <target name="inittestcore" depends="build">
+      <init classesdir="${classes.test.dir}" srcdir="${src.unit.test.dir}" modulename="core" pom="${core.pom}" scope="test" message="" />
+      <copy todir="${classes.test.core.dir}">
+         <fileset dir="${classes.core.dir}" includes="**/*.*" />
+      </copy>
+      <inlineDependencies scope="compile" id="remoting">
+         <dependency groupId="org.jboss.seam" artifactId="jboss-seam-remoting" version="${complete.version}" />
+      </inlineDependencies>
+      <path id="test.compile.path">
+         <path refid="test.core.path" />
+         <path path="${classes.test.core.dir}" />
+         <path refid="compile.remoting.path" />
+      </path>
+   </target>
+
+	<target name="unittestcore" depends="inittestcore,compiletest,getemma">
 		<taskdef resource="testngtasks" classpathref="test.core.path" />
 		<testng outputdir="${test.dir}">
 			<jvmarg value="-Demma.coverage.out.file=${coverage.ec}" />
@@ -680,6 +687,35 @@
 		<echo>You can increase the logging by editing bootstrap/log4j.xml</echo>
 	</target>
 	
+   <target name="inittestmail" depends="build">
+      <init classesdir="${classes.mail.test.dir}" srcdir="${src.mail.unit.test.dir}" modulename="mail" pom="${mail.pom}" scope="test" message="" />
+      <path id="test.mail.compile.path">
+         <path refid="test.mail.path" />
+         <path path="${classes.mail.test.dir}" />
+      	<path location="${classes.mail.dir}" />
+      </path>
+   </target>
+	
+   <target name="compiletestmail" depends="inittestmail,select-compiler,antlr">
+      <compile classesdir="${classes.mail.test.dir}" srcdir="${src.mail.unit.test.dir}" classpath="test.mail.compile.path" />
+   </target>
+	
+	<target name="unittestmail" depends="inittestmail,compiletestmail,getemma">
+	      <taskdef resource="testngtasks" classpathref="test.mail.path" />
+	      <testng outputdir="${test.dir}">
+	         <jvmarg value="-Demma.coverage.out.file=${coverage.ec}" />
+	         <jvmarg line="-Djava.awt.headless=true" />
+	         <classpath>
+	            <path path="${classes.mail.test.dir}" />
+	         	<path location="${classes.mail.dir}" />
+	            <path refid="runtime.emma.path" />
+	            <path refid="test.mail.path" />
+	         </classpath>
+	         <xmlfileset dir="${classes.mail.test.dir}" includes="**/testng.xml" />
+	      </testng>
+	      <echo>You can increase the logging by editing bootstrap/log4j.xml</echo>
+	   </target>
+	
 	<target name="test" depends="unittest, integrationtest" description="Run Seam Unit Tests and the Seam (core) Integration Tests"/>
 	
 	<target name="integrationtest" description="Run the Seam (core) Inteegration Tests">

Modified: trunk/examples/mail/src/org/jboss/seam/example/mail/test/MailTest.java
===================================================================
--- trunk/examples/mail/src/org/jboss/seam/example/mail/test/MailTest.java	2008-06-04 15:55:09 UTC (rev 8328)
+++ trunk/examples/mail/src/org/jboss/seam/example/mail/test/MailTest.java	2008-06-04 22:53:43 UTC (rev 8329)
@@ -4,6 +4,7 @@
 import static javax.mail.Message.RecipientType.CC;
 
 import java.io.InputStream;
+import java.util.Enumeration;
 
 import javax.faces.FacesException;
 import javax.faces.context.FacesContext;
@@ -91,6 +92,8 @@
        
     }
     
+    
+    
     @Test
     public void testAttachment() throws Exception
     {
@@ -534,6 +537,40 @@
     }
     
     @Test
+    public void testSanitization() throws Exception
+    {
+        
+        new FacesRequest()
+        {
+
+            @Override
+            protected void updateModelValues() throws Exception
+            {
+                
+            }
+            
+            @Override
+            protected void invokeApplication() throws Exception
+            { 
+                Contexts.getEventContext().set("name", "Pete\nMuir");   
+                MimeMessage renderedMessage = getRenderedMailMessage("/org/jboss/seam/example/mail/test/sanitization.xhtml");
+                assert "Try out".equals(renderedMessage.getSubject());
+                InternetAddress to = (InternetAddress) renderedMessage.getAllRecipients()[0];
+                assert to.getAddress().equals("peter at email.tld");
+                assert to.getPersonal().equals("Pete");
+                assert renderedMessage.getFrom().length == 1;
+                assert renderedMessage.getFrom()[0] instanceof InternetAddress;
+                InternetAddress from = (InternetAddress) renderedMessage.getFrom()[0];
+                assert from.getAddress().equals("peter at example.com");
+                assert from.getPersonal().equals("Pete");
+                assert renderedMessage.getHeader("Pete") != null;
+                assert renderedMessage.getHeader("Pete").length == 1;
+                assert "roll".equals(renderedMessage.getHeader("Pete")[0]);
+            }
+        }.run();
+    }
+    
+    @Test
     public void testTemplating() throws Exception
     {
         

Added: trunk/examples/mail/src/org/jboss/seam/example/mail/test/sanitization.xhtml
===================================================================
--- trunk/examples/mail/src/org/jboss/seam/example/mail/test/sanitization.xhtml	                        (rev 0)
+++ trunk/examples/mail/src/org/jboss/seam/example/mail/test/sanitization.xhtml	2008-06-04 22:53:43 UTC (rev 8329)
@@ -0,0 +1,14 @@
+<m:message xmlns="http://www.w3.org/1999/xhtml"
+           xmlns:m="http://jboss.com/products/seam/mail"
+           xmlns:h="http://java.sun.com/jsf/html">
+    
+          <m:from name="#{name}">peter at example.com
+          foo</m:from>
+          <m:to name="#{name}">peter at email.tld
+          bar</m:to>
+          <m:subject>Try out
+          Seam!</m:subject>
+          <m:header name="#{name}">roll
+          over</m:header>
+          <m:body>A mail message to test sanitization</m:body>
+</m:message>
\ No newline at end of file


Property changes on: trunk/examples/mail/src/org/jboss/seam/example/mail/test/sanitization.xhtml
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/src/mail/org/jboss/seam/mail/ui/AddressComponent.java
===================================================================
--- trunk/src/mail/org/jboss/seam/mail/ui/AddressComponent.java	2008-06-04 15:55:09 UTC (rev 8328)
+++ trunk/src/mail/org/jboss/seam/mail/ui/AddressComponent.java	2008-06-04 22:53:43 UTC (rev 8329)
@@ -25,15 +25,16 @@
    protected InternetAddress getInternetAddress(FacesContext facesContext) throws IOException, AddressException 
    {
       InternetAddress address = new InternetAddress();
-      address.setAddress(getAddress() != null ? getAddress() : encode(facesContext));
+      address.setAddress(new Header(getAddress() != null ? getAddress() : encode(facesContext)).getSanitizedValue());
       String charset = findMessage().getCharset();
+      String personal = new Header(getName()).getSanitizedValue();
       if (charset == null)
       {
-         address.setPersonal(getName());
+         address.setPersonal(personal);
       }
       else
       {
-         address.setPersonal(getName(), charset);
+         address.setPersonal(personal, charset);
       }
       address.validate();
       return address;
@@ -70,7 +71,7 @@
     */
    public String getName()
    {
-      if (address == null)
+      if (name == null)
       {
          return getString("name");
       } 

Added: trunk/src/mail/org/jboss/seam/mail/ui/Header.java
===================================================================
--- trunk/src/mail/org/jboss/seam/mail/ui/Header.java	                        (rev 0)
+++ trunk/src/mail/org/jboss/seam/mail/ui/Header.java	2008-06-04 22:53:43 UTC (rev 8329)
@@ -0,0 +1,70 @@
+package org.jboss.seam.mail.ui;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+
+public class Header
+{
+   
+   private final String name;
+   private final String value;
+   
+   private String sanitizedName;
+   private String sanitizedValue;
+   
+   public Header(String name, String value)
+   {
+      this.name = name;
+      this.value = value;
+   }
+   
+   public Header(String value)
+   {
+      this.value = value;
+      this.name = null;
+   }
+   
+   public String getSanitizedName()
+   {
+      if (sanitizedName == null && name != null)
+      {
+         try
+         {
+            sanitizedName = sanitize(name);
+         }
+         catch (IOException e)
+         {
+            throw new IllegalStateException("Error santizing Header name " + name, e);
+         }
+      }
+      return sanitizedName;
+   }
+   
+   public String getSanitizedValue()
+   {
+      if (sanitizedValue == null && value != null)
+      {
+         try
+         {
+            sanitizedValue = sanitize(value);
+         }
+         catch (IOException e)
+         {
+            throw new IllegalStateException("Error santizing Header " + name + " value " + value, e);
+         }
+      }
+      return sanitizedValue;
+   }
+   
+   /**
+    * Remove any line feed/new line characters
+    * @throws IOException 
+    */
+   public static String sanitize(String value) throws IOException
+   {
+      BufferedReader  reader = new BufferedReader(new StringReader(value));
+      return reader.readLine();
+   }
+
+}


Property changes on: trunk/src/mail/org/jboss/seam/mail/ui/Header.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/src/mail/org/jboss/seam/mail/ui/UIAttachment.java
===================================================================
--- trunk/src/mail/org/jboss/seam/mail/ui/UIAttachment.java	2008-06-04 15:55:09 UTC (rev 8328)
+++ trunk/src/mail/org/jboss/seam/mail/ui/UIAttachment.java	2008-06-04 22:53:43 UTC (rev 8329)
@@ -163,10 +163,10 @@
             MimeBodyPart attachment = new MimeBodyPart();
             // Need to manually set the contentid
             String contentId = RandomStringUtils.randomAlphabetic(20).toLowerCase();
-            attachment.setContentID("<" + contentId + ">");
+            attachment.setContentID(new Header("<" + contentId + ">").getSanitizedValue());
             attachment.setDataHandler(new DataHandler(ds));
-            attachment.setFileName(getName(ds.getName()));
-            attachment.setDisposition(getDisposition());
+            attachment.setFileName(new Header(getName(ds.getName())).getSanitizedValue());
+            attachment.setDisposition(new Header(getDisposition()).getSanitizedValue());
             findMessage().getAttachments().add(attachment);
             if (getStatus() != null)
             {

Modified: trunk/src/mail/org/jboss/seam/mail/ui/UIBody.java
===================================================================
--- trunk/src/mail/org/jboss/seam/mail/ui/UIBody.java	2008-06-04 15:55:09 UTC (rev 8328)
+++ trunk/src/mail/org/jboss/seam/mail/ui/UIBody.java	2008-06-04 22:53:43 UTC (rev 8329)
@@ -100,13 +100,13 @@
             throws MessagingException
    {
       MimeBodyPart bodyPart = new MimeBodyPart();
-      bodyPart.setDisposition("inline");
+      bodyPart.setDisposition(new Header("inline").getSanitizedValue());
       String charset = findMessage().getCharset();
       if ( charset != null) 
       {
          //bodyPart.setContent(body, "text/plain; charset="
          //      + charset + "; format=flowed");
-         bodyPart.setText(body, charset);
+         bodyPart.setText(body, new Header(charset).getSanitizedValue());
       } 
       else 
       {
@@ -119,16 +119,16 @@
             throws MessagingException
    {
       MimeBodyPart bodyPart = new MimeBodyPart();
-      bodyPart.setDisposition("inline");
+      bodyPart.setDisposition(new Header("inline").getSanitizedValue());
       String charset = findMessage().getCharset();
       if ( charset != null) 
       {
-         bodyPart.setContent(body, "text/html; charset="
-                  + charset);
+         bodyPart.setContent(body, new Header("text/html; charset="
+                  + charset).getSanitizedValue());
       } 
       else 
       {
-         bodyPart.setContent(body, "text/html");
+         bodyPart.setContent(body, new Header("text/html").getSanitizedValue());
       }
       
       return bodyPart;

Modified: trunk/src/mail/org/jboss/seam/mail/ui/UIHeader.java
===================================================================
--- trunk/src/mail/org/jboss/seam/mail/ui/UIHeader.java	2008-06-04 15:55:09 UTC (rev 8328)
+++ trunk/src/mail/org/jboss/seam/mail/ui/UIHeader.java	2008-06-04 22:53:43 UTC (rev 8329)
@@ -19,11 +19,13 @@
       {
          if (getValue() != null) 
          {
-            findMimeMessage().addHeader(getName(), getValue());
+            Header header = new Header(getName(), getValue());
+            findMimeMessage().addHeader(header.getSanitizedName(), header.getSanitizedValue());
          }
          else 
          {
-            findMimeMessage().addHeader(getName(), encode(facesContext));
+            Header header = new Header(getName(), encode(facesContext));
+            findMimeMessage().addHeader(header.getSanitizedName(), header.getSanitizedValue());
          }
       }
       catch (MessagingException e)

Modified: trunk/src/mail/org/jboss/seam/mail/ui/UIMessage.java
===================================================================
--- trunk/src/mail/org/jboss/seam/mail/ui/UIMessage.java	2008-06-04 15:55:09 UTC (rev 8328)
+++ trunk/src/mail/org/jboss/seam/mail/ui/UIMessage.java	2008-06-04 22:53:43 UTC (rev 8329)
@@ -133,7 +133,8 @@
             }
             if (getPrecedence() != null)
             {
-               getMimeMessage().addHeader("Precedence", getPrecedence());
+               Header header = new Header("Precedence", getPrecedence());
+               getMimeMessage().addHeader(header.getSanitizedName(), header.getSanitizedValue());
             }
          }
          catch (MessagingException e)
@@ -156,8 +157,9 @@
          if (isRequestReadReceipt() && getMimeMessage().getFrom() != null
                   && getMimeMessage().getFrom().length == 1)
          {
-            getMimeMessage().addHeader("Disposition-Notification-To",
-                     getMimeMessage().getFrom()[0].toString());
+            Header header = new Header("Disposition-Notification-To",
+                  getMimeMessage().getFrom()[0].toString());
+            getMimeMessage().addHeader(header.getSanitizedName(), header.getSanitizedValue());
          }
          // Do the send manually, Transport.send gets the wrong transport
          getMimeMessage().saveChanges();

Modified: trunk/src/mail/org/jboss/seam/mail/ui/UISubject.java
===================================================================
--- trunk/src/mail/org/jboss/seam/mail/ui/UISubject.java	2008-06-04 15:55:09 UTC (rev 8328)
+++ trunk/src/mail/org/jboss/seam/mail/ui/UISubject.java	2008-06-04 22:53:43 UTC (rev 8329)
@@ -22,11 +22,11 @@
          String charset = findMessage().getCharset();
          if (charset == null)
          {
-            findMimeMessage().setSubject(subject);
+            findMimeMessage().setSubject(new Header(subject).getSanitizedValue());
          }
          else
          {
-            findMimeMessage().setSubject(subject, charset);
+            findMimeMessage().setSubject(new Header(subject).getSanitizedValue(), charset);
          }
       }
       catch (MessagingException e)

Added: trunk/src/test/mail/unit/org/jboss/seam/test/mail/unit/HeaderTest.java
===================================================================
--- trunk/src/test/mail/unit/org/jboss/seam/test/mail/unit/HeaderTest.java	                        (rev 0)
+++ trunk/src/test/mail/unit/org/jboss/seam/test/mail/unit/HeaderTest.java	2008-06-04 22:53:43 UTC (rev 8329)
@@ -0,0 +1,64 @@
+package org.jboss.seam.test.mail.unit;
+
+import org.jboss.seam.mail.ui.Header;
+import org.testng.annotations.Test;
+
+public class HeaderTest
+{
+   @Test
+   public void testHeader()
+   {
+      String name = "foo";
+      String value = "bar";
+      
+      Header header = new Header(name, value);
+      
+      assert header.getSanitizedName().equals(name);
+      assert header.getSanitizedValue().equals(value);
+   }
+   
+   @Test
+   public void testHeaderWithLineFeed()
+   {
+      String name = "foo\nnewline";
+      String value = "bar\nnewline";
+      
+      Header header = new Header(name, value);
+      
+      assert !header.getSanitizedName().equals(name);
+      assert !header.getSanitizedValue().equals(value);
+      
+      assert "foo".equals(header.getSanitizedName());
+      assert "bar".equals(header.getSanitizedValue());
+   }
+   
+   @Test
+   public void testHeaderWithCarrigeReturnLineBreak()
+   {
+      String name = "foo\r\nnewline";
+      String value = "bar\r\nnewline";
+      
+      Header header = new Header(name, value);
+      
+      assert !header.getSanitizedName().equals(name);
+      assert !header.getSanitizedValue().equals(value);
+      
+      assert "foo".equals(header.getSanitizedName());
+      assert "bar".equals(header.getSanitizedValue());
+   }
+   
+   @Test
+   public void testHeaderWithCarriageReturn()
+   {
+      String name = "foo\rnewline";
+      String value = "bar\rnewline";
+      
+      Header header = new Header(name, value);
+      
+      assert !header.getSanitizedName().equals(name);
+      assert !header.getSanitizedValue().equals(value);
+      
+      assert "foo".equals(header.getSanitizedName());
+      assert "bar".equals(header.getSanitizedValue());
+   }
+}


Property changes on: trunk/src/test/mail/unit/org/jboss/seam/test/mail/unit/HeaderTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/src/test/mail/unit/org/jboss/seam/test/mail/unit/testng.xml
===================================================================
--- trunk/src/test/mail/unit/org/jboss/seam/test/mail/unit/testng.xml	                        (rev 0)
+++ trunk/src/test/mail/unit/org/jboss/seam/test/mail/unit/testng.xml	2008-06-04 22:53:43 UTC (rev 8329)
@@ -0,0 +1,9 @@
+<!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
+
+<suite name="Seam Mail Unit Testsuite" verbose="2" parallel="false">
+   <test name="Seam Unit Tests: Mail">
+     <classes>
+       <class name="org.jboss.seam.test.mail.unit.HeaderTest"/>
+     </classes>
+   </test>
+</suite>


Property changes on: trunk/src/test/mail/unit/org/jboss/seam/test/mail/unit/testng.xml
___________________________________________________________________
Name: svn:mime-type
   + text/plain




More information about the seam-commits mailing list