maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bentm...@apache.org
Subject svn commit: r922090 - in /maven/core-integration-testing/trunk/core-it-suite/src/test: java/org/apache/maven/it/MavenITmng4448FollowHttpRedirectTest.java resources/mng-4448/keystore resources/mng-4448/settings-template.xml
Date Fri, 12 Mar 2010 00:51:02 GMT
Author: bentmann
Date: Fri Mar 12 00:51:02 2010
New Revision: 922090

URL: http://svn.apache.org/viewvc?rev=922090&view=rev
Log:
[MNG-4428] Permament move (error 301) not handled properly by Maven

o Strengthened IT

Added:
    maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4448/keystore
  (with props)
Modified:
    maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4448FollowHttpRedirectTest.java
    maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4448/settings-template.xml

Modified: maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4448FollowHttpRedirectTest.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4448FollowHttpRedirectTest.java?rev=922090&r1=922089&r2=922090&view=diff
==============================================================================
--- maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4448FollowHttpRedirectTest.java
(original)
+++ maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4448FollowHttpRedirectTest.java
Fri Mar 12 00:51:02 2010
@@ -28,14 +28,15 @@ import java.io.PrintWriter;
 import java.util.List;
 import java.util.Properties;
 
-import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.mortbay.jetty.Connector;
 import org.mortbay.jetty.Handler;
 import org.mortbay.jetty.Request;
 import org.mortbay.jetty.Server;
 import org.mortbay.jetty.handler.AbstractHandler;
+import org.mortbay.jetty.security.SslSocketConnector;
 
 /**
  * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4448">MNG-4448</a>.
@@ -53,69 +54,79 @@ public class MavenITmng4448FollowHttpRed
     }
 
     /**
-     * Verify that HTTP redirects are getting followed.
+     * Verify that redirects from HTTP to HTTP are getting followed.
      */
-    public void testit()
+    public void testitHttpToHttp()
         throws Exception
     {
-        File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4448"
);
+        testit( true, true );
+    }
 
-        Verifier verifier = new Verifier( testDir.getAbsolutePath() );
+    /**
+     * Verify that redirects from HTTPS to HTTPS are getting followed.
+     */
+    public void testitHttpsToHttps()
+        throws Exception
+    {
+        testit( false, false );
+    }
 
-        Handler repoHandler = new AbstractHandler()
-        {
-            public void handle( String target, HttpServletRequest request, HttpServletResponse
response, int dispatch )
-                throws IOException, ServletException
-            {
-                System.out.println( "Handling " + request.getMethod() + " " + request.getRequestURL()
);
+    /**
+     * Verify that redirects from HTTP to HTTPS are getting followed.
+     */
+    public void testitHttpToHttps()
+        throws Exception
+    {
+        requiresMavenVersion( "2.2.0" );
 
-                PrintWriter writer = response.getWriter();
+        testit( true, false );
+    }
 
-                response.setStatus( HttpServletResponse.SC_OK );
+    /**
+     * Verify that redirects from HTTPS to HTTP are getting followed.
+     */
+    public void testitHttpsToHttp()
+        throws Exception
+    {
+        requiresMavenVersion( "2.2.0" );
 
-                if ( request.getRequestURI().startsWith( "/repo/" ) )
-                {
-                    response.setStatus( HttpServletResponse.SC_MOVED_PERMANENTLY );
-                    response.setHeader( "Location", "/redirected/" + request.getRequestURI().substring(
6 ) );
-                }
-                else if ( request.getRequestURI().endsWith( ".pom" ) )
-                {
-                    writer.println( "<project>" );
-                    writer.println( "  <modelVersion>4.0.0</modelVersion>" );
-                    writer.println( "  <groupId>org.apache.maven.its.mng4448</groupId>"
);
-                    writer.println( "  <artifactId>dep</artifactId>" );
-                    writer.println( "  <version>0.1</version>" );
-                    writer.println( "</project>" );
-                }
-                else if ( request.getRequestURI().endsWith( ".jar" ) )
-                {
-                    writer.println( "empty" );
-                }
-                else if ( request.getRequestURI().endsWith( ".md5" ) || request.getRequestURI().endsWith(
".sha1" ) )
-                {
-                    response.setStatus( HttpServletResponse.SC_NOT_FOUND );
-                }
+        testit( false, true );
+    }
 
-                ( (Request) request ).setHandled( true );
-            }
-        };
+    private void testit( boolean fromHttp, boolean toHttp )
+        throws Exception
+    {
+        File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4448"
);
+
+        Verifier verifier = new Verifier( testDir.getAbsolutePath() );
+
+        // keytool -genkey -alias localhost -keypass key-passwd -keystore keystore -storepass
store-passwd \
+        //   -validity 4096 -dname "cn=localhost, ou=None, L=Seattle, ST=Washington, o=ExampleOrg,
c=US" -keyalg RSA
+        String storePath = new File( testDir, "keystore" ).getAbsolutePath();
+        String storePwd = "store-passwd";
+        String keyPwd = "key-passwd";
 
         Server server = new Server( 0 );
-        server.setHandler( repoHandler );
+        server.addConnector( newHttpsConnector( storePath, storePwd, keyPwd ) );
+        Connector from = server.getConnectors()[ fromHttp ? 0 : 1 ];
+        Connector to = server.getConnectors()[ toHttp ? 0 : 1 ];
+        server.setHandler( new RedirectHandler( toHttp ? "http" : "https", to ) );
         server.start();
 
         try
         {
-            int port = server.getConnectors()[0].getLocalPort();
-
             verifier.setAutoclean( false );
             verifier.deleteArtifacts( "org.apache.maven.its.mng4448" );
             verifier.deleteDirectory( "target" );
             Properties filterProps = verifier.newDefaultFilterProperties();
-            filterProps.setProperty( "@port@", Integer.toString( port ) );
+            filterProps.setProperty( "@protocol@", fromHttp ? "http" : "https" );
+            filterProps.setProperty( "@port@", Integer.toString( from.getLocalPort() ) );
             verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps
);
-            verifier.getCliOptions().add( "--settings" );
+            verifier.getCliOptions().add( "-X --settings" );
             verifier.getCliOptions().add( "settings.xml" );
+            verifier.setSystemProperty( "javax.net.ssl.trustStore", storePath );
+            verifier.setSystemProperty( "javax.net.ssl.trustStorePassword", storePwd );
+            verifier.setLogFileName( "log-" + getName().substring( 6 ) + ".txt" );
             verifier.executeGoal( "validate" );
             verifier.verifyErrorFreeLog();
             verifier.resetStreams();
@@ -129,4 +140,74 @@ public class MavenITmng4448FollowHttpRed
         assertTrue( cp.toString(), cp.contains( "dep-0.1.jar" ) );
     }
 
+    private Connector newHttpsConnector( String keystore, String storepwd, String keypwd
)
+    {
+        SslSocketConnector connector = new SslSocketConnector();
+        connector.setPort( 0 );
+        connector.setKeystore( keystore );
+        connector.setPassword( storepwd );
+        connector.setKeyPassword( keypwd );
+        return connector;
+    }
+
+    static class RedirectHandler extends AbstractHandler
+    {
+
+        private final String protocol;
+
+        private final Connector connector;
+
+        public RedirectHandler( String protocol, Connector connector )
+        {
+            this.protocol = protocol;
+            this.connector = connector;
+        }
+
+        public void handle( String target, HttpServletRequest request, HttpServletResponse
response, int dispatch )
+            throws IOException
+        {
+            System.out.println( "Handling " + request.getMethod() + " " + request.getRequestURL()
);
+
+            PrintWriter writer = response.getWriter();
+
+            String uri = request.getRequestURI();
+            if ( uri.startsWith( "/repo/" ) )
+            {
+                String location = protocol + "://localhost:" + connector.getLocalPort() +
"/redirected/"
+                    + uri.substring( 6 );
+                if ( uri.endsWith( ".pom" ) )
+                {
+                    response.setStatus( HttpServletResponse.SC_MOVED_TEMPORARILY );
+                }
+                else
+                {
+                    response.setStatus( HttpServletResponse.SC_MOVED_PERMANENTLY );
+                }
+                response.setHeader( "Location", location );
+            }
+            else if ( uri.endsWith( ".pom" ) )
+            {
+                writer.println( "<project>" );
+                writer.println( "  <modelVersion>4.0.0</modelVersion>" );
+                writer.println( "  <groupId>org.apache.maven.its.mng4448</groupId>"
);
+                writer.println( "  <artifactId>dep</artifactId>" );
+                writer.println( "  <version>0.1</version>" );
+                writer.println( "</project>" );
+                response.setStatus( HttpServletResponse.SC_OK );
+            }
+            else if ( uri.endsWith( ".jar" ) )
+            {
+                writer.println( "empty" );
+                response.setStatus( HttpServletResponse.SC_OK );
+            }
+            else
+            {
+                response.setStatus( HttpServletResponse.SC_NOT_FOUND );
+            }
+
+            ( (Request) request ).setHandled( true );
+        }
+
+    }
+
 }

Added: maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4448/keystore
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4448/keystore?rev=922090&view=auto
==============================================================================
Binary file - no diff available.

Propchange: maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4448/keystore
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4448/settings-template.xml
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4448/settings-template.xml?rev=922090&r1=922089&r2=922090&view=diff
==============================================================================
--- maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4448/settings-template.xml
(original)
+++ maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4448/settings-template.xml
Fri Mar 12 00:51:02 2010
@@ -26,7 +26,7 @@ under the License.
       <repositories>
         <repository>
           <id>maven-core-it</id>
-          <url>http://localhost:@port@/repo/</url>
+          <url>@protocol@://localhost:@port@/repo/</url>
           <releases>
             <checksumPolicy>ignore</checksumPolicy>
           </releases>



Mime
View raw message