You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by og...@apache.org on 2009/04/23 00:57:04 UTC
svn commit: r767705 [18/31] - in /maven/mercury/trunk/mercury-core: ./ src/
src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/maven/ src/main/java/org/apache/maven/mercury/
src/main/java/org/apache/maven/mer...
Added: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/AuthenticatingJettyDeployerTest.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/AuthenticatingJettyDeployerTest.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/AuthenticatingJettyDeployerTest.java (added)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/AuthenticatingJettyDeployerTest.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,60 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.mercury.spi.http.client;
+
+import java.net.URL;
+import java.util.HashSet;
+
+import org.apache.maven.mercury.crypto.api.StreamVerifierFactory;
+import org.apache.maven.mercury.spi.http.client.deploy.DefaultDeployer;
+import org.apache.maven.mercury.spi.http.server.AuthenticatingPutServer;
+import org.apache.maven.mercury.transport.api.Credentials;
+
+public class AuthenticatingJettyDeployerTest extends JettyDeployerTest
+{
+
+ public AuthenticatingJettyDeployerTest () throws Exception
+ {
+ super();
+ }
+
+ protected void setUp() throws Exception
+ {
+ setUpFiles();
+ _deployer = new DefaultDeployer();
+ _putServer = new AuthenticatingPutServer();
+ _putServer.start();
+ _port = String.valueOf(_putServer.getPort());
+ setUpServerType();
+ }
+
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ }
+
+ protected void setUpServerType () throws Exception
+ {
+ HashSet<org.apache.maven.mercury.transport.api.Server> remoteServerTypes = new HashSet<org.apache.maven.mercury.transport.api.Server>();
+ remoteServerType = new org.apache.maven.mercury.transport.api.Server( "test", new URL(_HOST_FRAGMENT+_port), false, false, new Credentials("foo", "bar"));
+ factories = new HashSet<StreamVerifierFactory>();
+ remoteServerTypes.add(remoteServerType);
+ _deployer.setServers(remoteServerTypes);
+ }
+}
Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/AuthenticatingJettyDeployerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/AuthenticatingJettyDeployerTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/AuthenticatingJettyRetrieverTest.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/AuthenticatingJettyRetrieverTest.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/AuthenticatingJettyRetrieverTest.java (added)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/AuthenticatingJettyRetrieverTest.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,56 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.mercury.spi.http.client;
+
+import java.net.URL;
+import java.util.HashSet;
+
+import org.apache.maven.mercury.crypto.api.StreamVerifierFactory;
+import org.apache.maven.mercury.spi.http.client.retrieve.DefaultRetriever;
+import org.apache.maven.mercury.spi.http.server.AuthenticatingTestServer;
+import org.apache.maven.mercury.transport.api.Credentials;
+import org.apache.maven.mercury.transport.api.Server;
+
+public class AuthenticatingJettyRetrieverTest extends JettyRetrieverTest
+{
+ public void setUp ()
+ throws Exception
+ {
+ server = new AuthenticatingTestServer();
+ server.start();
+ _port=String.valueOf(server.getPort());
+
+ HashSet<Server> remoteServerTypes = new HashSet<Server>();
+ remoteServerType = new Server( "test", new URL(__HOST_FRAGMENT+_port), false, false,
+ new Credentials(((AuthenticatingTestServer)server).getUsername(), ((AuthenticatingTestServer)server).getPassword()));
+ factories = new HashSet<StreamVerifierFactory>();
+
+ remoteServerTypes.add(remoteServerType);
+
+ retriever = new DefaultRetriever();
+ retriever.setServers(remoteServerTypes);
+ }
+
+
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ }
+
+}
Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/AuthenticatingJettyRetrieverTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/AuthenticatingJettyRetrieverTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/JettyDeployerTest.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/JettyDeployerTest.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/JettyDeployerTest.java (added)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/JettyDeployerTest.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,564 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.maven.mercury.spi.http.client;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import java.io.OutputStream;
+import java.net.URL;
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.maven.mercury.crypto.api.StreamVerifierAttributes;
+import org.apache.maven.mercury.crypto.api.StreamVerifierFactory;
+import org.apache.maven.mercury.crypto.pgp.PgpStreamVerifierFactory;
+import org.apache.maven.mercury.crypto.sha.SHA1VerifierFactory;
+import org.apache.maven.mercury.spi.http.client.deploy.DefaultDeployer;
+import org.apache.maven.mercury.spi.http.client.deploy.DeployRequest;
+import org.apache.maven.mercury.spi.http.client.deploy.DeployResponse;
+import org.apache.maven.mercury.spi.http.server.SimplePutServer;
+import org.apache.maven.mercury.spi.http.validate.Validator;
+import org.apache.maven.mercury.transport.api.Binding;
+import org.mortbay.util.IO;
+
+public class JettyDeployerTest extends TestCase
+{
+ public String _HOST_FRAGMENT = "http://localhost:";
+ public static final String __PATH_FRAGMENT = "/maven2/repo/";
+
+ private static final String keyId = "0EDB5D91141BC4F2";
+
+ private static final String secretKeyFile = "/pgp/secring.gpg";
+ private static final String secretKeyPass = "testKey82";
+
+ protected DefaultDeployer _deployer;
+ protected SimplePutServer _putServer;
+ protected String _port;
+ File _baseDir;
+ File _file0;
+ File _file1;
+ File _file2;
+ File _file3;
+ File _file4;
+ File _file5;
+ File _file6;
+
+ org.apache.maven.mercury.transport.api.Server remoteServerType;
+ HashSet<StreamVerifierFactory> factories;
+
+ protected class DeployRequestImpl implements DeployRequest
+ {
+ private Set<Binding> _bindings = new HashSet<Binding>();
+ private boolean _failFast;
+
+ public Set<Validator> getValidators()
+ {
+ return null;
+ }
+ public void setBindings(Set<Binding> bindings)
+ {
+ _bindings=bindings;
+ }
+ public Set<Binding> getBindings()
+ {
+ return _bindings;
+ }
+
+ public boolean isFailFast()
+ {
+ return _failFast;
+ }
+
+ public void setFailFast (boolean f)
+ {
+ _failFast=f;
+ }
+ };
+
+ public JettyDeployerTest () throws Exception
+ {
+
+ }
+
+ public void setUpFiles () throws Exception
+ {
+ //copy the test files from the classpath to disk
+ _baseDir = File.createTempFile("deployerTestFiles",null);
+ _baseDir.delete();
+ _baseDir.mkdir();
+ _baseDir.deleteOnExit();
+ URL list = JettyDeployerTest.class.getResource("/testRepo/");
+ LineNumberReader in = new LineNumberReader(new InputStreamReader(list.openStream()));
+ String file=null;
+ while ((file=in.readLine())!=null)
+ {
+ if (!file.startsWith("file"))
+ continue;
+ OutputStream out=new FileOutputStream(new File(_baseDir,file));
+ IO.copy(JettyDeployerTest.class.getResource("/testRepo/"+file).openStream(),out);
+ out.close();
+ }
+ }
+
+ protected void setUp() throws Exception
+ {
+ setUpFiles();
+ _deployer = new DefaultDeployer();
+ _putServer = new SimplePutServer();
+ _putServer.start();
+ _port = String.valueOf(_putServer.getPort());
+ setUpServerType();
+ super.setUp();
+ }
+
+
+ public void destroy (File f)
+ {
+ if (f == null)
+ return;
+ if (f.isDirectory())
+ {
+ File[] files = f.listFiles();
+ for (int i=0;files!=null && i<files.length; i++)
+ {
+ destroy (files[i]);
+ }
+ }
+ f.delete();
+ }
+
+ protected void setUpServerType () throws Exception
+ {
+ HashSet<org.apache.maven.mercury.transport.api.Server> remoteServerTypes = new HashSet<org.apache.maven.mercury.transport.api.Server>();
+ remoteServerType = new org.apache.maven.mercury.transport.api.Server( "test", new URL(_HOST_FRAGMENT+_port));
+ factories = new HashSet<StreamVerifierFactory>();
+ remoteServerTypes.add(remoteServerType);
+ _deployer.setServers(remoteServerTypes);
+ }
+
+ protected void tearDown() throws Exception
+ {
+ _putServer.stop();
+ _putServer.destroy();
+ destroy(_baseDir);
+ System.err.println("Destroyed "+_baseDir.getAbsolutePath());
+ super.tearDown();
+ }
+
+ public void testUploadOKWithChecksums () throws Exception
+ {
+ HashSet<Binding> bindings = new HashSet<Binding>();
+ DeployRequestImpl request = new DeployRequestImpl();
+ factories.add( new SHA1VerifierFactory(false, true) ); //!lenient, sufficient
+ factories.add(
+ new PgpStreamVerifierFactory(
+ new StreamVerifierAttributes( PgpStreamVerifierFactory.DEFAULT_EXTENSION, false, true )
+ , getClass().getResourceAsStream( secretKeyFile )
+ , keyId, secretKeyPass
+ )
+ );
+ remoteServerType.setWriterStreamVerifierFactories(factories);
+
+ System.err.println("Basedir = "+_baseDir.getAbsolutePath());
+
+ _file0 = new File(_baseDir, "file0.txt");
+ _file1 = new File(_baseDir, "file1.txt");
+ _file2 = new File(_baseDir, "file2.txt");
+ _file3 = new File(_baseDir, "file3.jar");
+ _file4 = new File(_baseDir, "file4.so");
+ _file5 = new File(_baseDir, "file5.jpg");
+ _file6 = new File(_baseDir, "file6.gif");
+ Binding binding0 = new Binding(new URL(_HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file0.txt"), _file0);
+ Binding binding3 = new Binding(new URL(_HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file3.jar"), _file3);
+ Binding binding4 = new Binding(new URL(_HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file4.so"), _file4);
+ Binding binding5 = new Binding(new URL(_HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file5.jpg"), _file5);
+ Binding binding6 = new Binding(new URL(_HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file6.gif"), _file6);
+
+ bindings.add(binding0);
+ bindings.add(binding3);
+ bindings.add(binding4);
+ bindings.add(binding5);
+ bindings.add(binding6);
+
+ request.setBindings(bindings);
+
+ DeployResponse response = _deployer.deploy(request);
+
+ for (HttpClientException t:response.getExceptions())
+ t.printStackTrace();
+
+ assertEquals(0, response.getExceptions().size());
+ File f0 = new File(_putServer.getPutDir(), "file0.txt");
+ File f0cs = new File (_putServer.getPutDir(), "file0.txt.sha1");
+ assertTrue (f0.exists());
+ assertTrue (f0cs.exists());
+
+ File f3 = new File(_putServer.getPutDir(), "file3.jar");
+ File f3cs = new File (_putServer.getPutDir(), "file3.jar.sha1");
+ assertTrue(f3.exists());
+ assertTrue(f3cs.exists());
+
+ File f4 = new File(_putServer.getPutDir(), "file4.so");
+ File f4cs = new File (_putServer.getPutDir(), "file4.so.sha1");
+ assertTrue (f4.exists());
+ assertTrue (f4cs.exists());
+
+ File f5 = new File(_putServer.getPutDir(), "file5.jpg");
+ File f5cs = new File (_putServer.getPutDir(), "file5.jpg.sha1");
+ assertTrue (f5.exists());
+ assertTrue (f5cs.exists());
+
+ File f6 = new File(_putServer.getPutDir(), "file6.gif");
+ File f6cs = new File (_putServer.getPutDir(), "file6.gif.asc");
+ assertTrue (f6.exists());
+ assertTrue (f6cs.exists());
+
+ }
+
+ public void testUploadOKWithExemptChecksums () throws Exception
+ {
+ HashSet<Binding> bindings = new HashSet<Binding>();
+ DeployRequestImpl request = new DeployRequestImpl();
+ factories.add( new SHA1VerifierFactory(false, true) ); //!lenient, sufficient
+ factories.add(
+ new PgpStreamVerifierFactory(
+ new StreamVerifierAttributes( PgpStreamVerifierFactory.DEFAULT_EXTENSION, false, true )
+ , getClass().getResourceAsStream( secretKeyFile )
+ , keyId, secretKeyPass
+ )
+ );
+ remoteServerType.setWriterStreamVerifierFactories(factories);
+
+ System.err.println("Basedir = "+_baseDir.getAbsolutePath());
+
+ _file0 = new File(_baseDir, "file0.txt");
+ _file1 = new File(_baseDir, "file1.txt");
+ _file2 = new File(_baseDir, "file2.txt");
+ _file3 = new File(_baseDir, "file3.jar");
+ _file4 = new File(_baseDir, "file4.so");
+ _file5 = new File(_baseDir, "file5.jpg");
+ _file6 = new File(_baseDir, "file6.gif");
+ Binding binding0 = new Binding(new URL(_HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file0.txt"), _file0);
+ Binding binding3 = new Binding(new URL(_HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file3.jar"), _file3);
+ Binding binding4 = new Binding(new URL(_HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file4.so"), _file4);
+ Binding binding5 = new Binding(new URL(_HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file5.jpg"), _file5);
+ Binding binding6 = new Binding(new URL(_HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file6.gif"), _file6, true ); // exempt
+
+ bindings.add(binding0);
+ bindings.add(binding3);
+ bindings.add(binding4);
+ bindings.add(binding5);
+ bindings.add(binding6);
+
+ request.setBindings(bindings);
+
+ DeployResponse response = _deployer.deploy(request);
+
+ for (HttpClientException t:response.getExceptions())
+ t.printStackTrace();
+
+ assertEquals(0, response.getExceptions().size());
+ File f0 = new File(_putServer.getPutDir(), "file0.txt");
+ File f0cs = new File (_putServer.getPutDir(), "file0.txt.sha1");
+ assertTrue (f0.exists());
+ assertTrue (f0cs.exists());
+
+ File f3 = new File(_putServer.getPutDir(), "file3.jar");
+ File f3cs = new File (_putServer.getPutDir(), "file3.jar.sha1");
+ assertTrue(f3.exists());
+ assertTrue(f3cs.exists());
+
+ File f4 = new File(_putServer.getPutDir(), "file4.so");
+ File f4cs = new File (_putServer.getPutDir(), "file4.so.sha1");
+ assertTrue (f4.exists());
+ assertTrue (f4cs.exists());
+
+ File f5 = new File(_putServer.getPutDir(), "file5.jpg");
+ File f5cs = new File (_putServer.getPutDir(), "file5.jpg.sha1");
+ assertTrue (f5.exists());
+ assertTrue (f5cs.exists());
+
+ File f6 = new File(_putServer.getPutDir(), "file6.gif");
+ File f6cs = new File (_putServer.getPutDir(), "file6.gif.asc");
+ assertTrue (f6.exists());
+ assertFalse (f6cs.exists());
+
+ }
+ /* This test duplicates the one above unless we allow for checksum files to
+ * be pre-existing
+
+ public void testUploadOKMissingChecksum () throws Exception
+ {
+ HashSet<Binding> bindings = new HashSet<Binding>();
+ DeployRequestImpl request = new DeployRequestImpl();
+
+ _file0 = new File(_baseDir, "file0.txt");
+ _file1 = new File(_baseDir, "file1.txt");
+ _file2 = new File(_baseDir, "file2.txt");
+ _file3 = new File(_baseDir, "file3.jar");
+ _file4 = new File(_baseDir, "file4.so");
+ _file5 = new File(_baseDir, "file5.jpg");
+
+ _binding0.setRemoteResource(_HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file0.txt");
+ _binding0.setLocalFile(_file0);
+ bindings.add(_binding0);
+
+ //TODO Test Lenient
+ _binding1.setRemoteResource(_HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file1.txt"); //has no sha file
+ _binding1.setLocalFile(_file1);
+ //_binding1.setLenientChecksum(true);
+ bindings.add(_binding1);
+
+ _binding3.setRemoteResource(_HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file3.jar");
+ _binding3.setLocalFile(_file3);
+ bindings.add(_binding3);
+
+ _binding4.setRemoteResource(_HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file4.so");
+ _binding4.setLocalFile(_file4);
+ bindings.add(_binding4);
+
+ _binding5.setRemoteResource(_HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file5.jpg");
+ _binding5.setLocalFile(_file5);
+ bindings.add(_binding5);
+
+ request.setBindings(bindings);
+
+ DeployResponse response = _deployer.deploy(request);
+
+ //for (MercuryException t:response.getExceptions())
+ // t.printStackTrace();
+
+ assertEquals(10, _putServer.getPutDir().list().length);
+ assertEquals(0, response.getExceptions().size());
+ File f0 = new File(_putServer.getPutDir(), "file0.txt");
+ File f0cs = new File (_putServer.getPutDir(), "file0.txt.sha1");
+ assertTrue (f0.exists());
+ assertTrue (f0cs.exists());
+
+ File f1 = new File(_putServer.getPutDir(), "file1.txt");
+ File f1cs = new File(_putServer.getPutDir(), "file1.txt.sha1");
+ assertTrue(f1.exists());
+ assertTrue(f1cs.exists());
+
+ File f3 = new File(_putServer.getPutDir(), "file3.jar");
+ File f3cs = new File (_putServer.getPutDir(), "file3.jar.sha1");
+ assertTrue(f3.exists());
+ assertTrue(f3cs.exists());
+
+ File f4 = new File(_putServer.getPutDir(), "file4.so");
+ File f4cs = new File (_putServer.getPutDir(), "file4.so.sha1");
+ assertTrue (f4.exists());
+ assertTrue (f4cs.exists());
+
+ File f5 = new File(_putServer.getPutDir(), "file5.jpg");
+ File f5cs = new File (_putServer.getPutDir(), "file5.jpg.sha1");
+ assertTrue (f5.exists());
+ assertTrue (f5cs.exists());
+ }
+ */
+
+
+ public void testUploadFail () throws Exception
+ {
+ factories.add(new SHA1VerifierFactory(false, true)); //!lenient, sufficient
+ remoteServerType.setWriterStreamVerifierFactories(factories);
+ HashSet<Binding> bindings = new HashSet<Binding>();
+ DeployRequestImpl request = new DeployRequestImpl();
+
+ _file0 = new File(_baseDir, "file0.txt");
+ _file1 = new File(_baseDir, "file1.txt");
+ _file2 = new File(_baseDir, "file2.txt");
+ _file3 = new File(_baseDir, "file3.jar");
+ _file4 = new File(_baseDir, "file4.so");
+ _file5 = new File(_baseDir, "file5.jpg");
+ File file6 = new File(_baseDir, "file6.txt");//doesn't exist
+ File file7 = new File(_baseDir, "file7.txt");//doesn't exist
+
+ Binding binding0 = new Binding(new URL(_HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file0.txt"), _file0);
+ bindings.add(binding0);
+
+ Binding binding3 = new Binding(new URL(_HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file3.jar"), _file3);
+ bindings.add(binding3);
+
+ Binding binding4 = new Binding(new URL(_HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file4.so"), _file4);
+ bindings.add(binding4);
+
+ Binding binding5 = new Binding(new URL(_HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file5.jpg"), _file5);
+ bindings.add(binding5);
+
+ Binding binding6 = new Binding(new URL(_HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file6.txt"), file6);
+ bindings.add(binding6);
+
+ Binding binding7 = new Binding(new URL(_HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file7.txt"), file7);
+ bindings.add(binding7);
+
+ request.setBindings(bindings);
+ DeployResponse response = _deployer.deploy(request);
+
+// for (HttpClientException t:response.getExceptions())
+// t.printStackTrace();
+
+ //as the serverside is not running the mercury enhancements to the put filter, then
+ //all the files except for the 2 which don't exists should have been uploaded
+ assertEquals(2, response.getExceptions().size());
+ File f0 = new File(_putServer.getPutDir(), "file0.txt");
+ File f0cs = new File (_putServer.getPutDir(), "file0.txt.sha1");
+ assertTrue (f0.exists());
+ assertTrue (f0cs.exists());
+
+ File f3 = new File(_putServer.getPutDir(), "file3.jar");
+ File f3cs = new File (_putServer.getPutDir(), "file3.jar.sha1");
+ assertTrue(f3.exists());
+ assertTrue(f3cs.exists());
+
+ File f4 = new File(_putServer.getPutDir(), "file4.so");
+ File f4cs = new File (_putServer.getPutDir(), "file4.so.sha1");
+ assertTrue (f4.exists());
+ assertTrue (f4cs.exists());
+
+ File f5 = new File(_putServer.getPutDir(), "file5.jpg");
+ File f5cs = new File (_putServer.getPutDir(), "file5.jpg.sha1");
+ assertTrue (f5.exists());
+ assertTrue (f5cs.exists());
+
+ File f6 = new File(_putServer.getPutDir(), "file6.txt");
+ File f6cs = new File (_putServer.getPutDir(), "file6.txt.sha1");
+ assertFalse (f6.exists());
+ assertFalse (f6cs.exists());
+
+ File f7 = new File(_putServer.getPutDir(), "file7.txt");
+ File f7cs = new File (_putServer.getPutDir(), "file7.txt.sha1");
+ assertFalse (f7.exists());
+ assertFalse (f7cs.exists());
+ }
+
+ public void testUploadFailFast () throws Exception
+ {
+ factories.add(new SHA1VerifierFactory(false, true)); //!lenient, sufficient
+ remoteServerType.setWriterStreamVerifierFactories(factories);
+ HashSet<Binding> bindings = new HashSet<Binding>();
+ DeployRequestImpl request = new DeployRequestImpl();
+
+ _file0 = new File(_baseDir, "file0.txt");
+ _file1 = new File(_baseDir, "file1.txt");
+ _file2 = new File(_baseDir, "file2.txt");
+ _file3 = new File(_baseDir, "file3.jar");
+ _file4 = new File(_baseDir, "file4.so");
+ _file5 = new File(_baseDir, "file5.jpg");
+ File file6 = new File(_baseDir, "file6.txt");//doesn't exist
+ File file7 = new File(_baseDir, "file7.txt");//doesn't exist
+
+ Binding binding0 = new Binding(new URL(_HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file0.txt"), _file0);
+ bindings.add(binding0);
+
+ Binding binding3 = new Binding(new URL(_HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file3.jar"), _file3);
+ bindings.add(binding3);
+
+ Binding binding4 = new Binding(new URL(_HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file4.so"), _file4);
+ bindings.add(binding4);
+
+ Binding binding5 = new Binding(new URL(_HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file5.jpg"), _file5);
+ bindings.add(binding5);
+
+ Binding binding6 = new Binding(new URL(_HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file6.txt"), file6);
+ bindings.add(binding6);
+
+ Binding binding7 = new Binding(new URL(_HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file7.txt"), file7);
+ bindings.add(binding7);
+
+ request.setBindings(bindings);
+ request.setFailFast(true);
+ DeployResponse response = _deployer.deploy(request);
+
+// for (HttpClientException t:response.getExceptions())
+// t.printStackTrace();
+
+ //with failfast==true and the server side not running the mercury enhancements, we have no way to know
+ //how many files actually did get uploaded, but the first exception should cause it to stop
+ assertEquals(1, response.getExceptions().size());
+
+ File f6 = new File(_putServer.getPutDir(), "file6.txt");
+ File f6cs = new File (_putServer.getPutDir(), "file6.txt.sha1");
+ assertFalse (f6.exists());
+ assertFalse (f6cs.exists());
+ File f7 = new File(_putServer.getPutDir(), "file7.txt");
+ File f7cs = new File (_putServer.getPutDir(), "file7.txt.sha1");
+ assertFalse (f7.exists());
+ assertFalse (f7cs.exists());
+
+
+ Thread.sleep(500);
+ }
+
+ public void testMemoryDeployment () throws Exception
+ {
+ factories.add(new SHA1VerifierFactory(false, true)); //!lenient, sufficient
+ remoteServerType.setWriterStreamVerifierFactories(factories);
+ HashSet<Binding> bindings = new HashSet<Binding>();
+ DeployRequestImpl request = new DeployRequestImpl();
+
+ String s0 = "memory contents0";
+ InputStream is0 = new ByteArrayInputStream(s0.getBytes());
+ Binding binding0 = new Binding(new URL(_HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file0.txt"), is0);
+ bindings.add(binding0);
+
+ String s5 = "memory contents5";
+ InputStream is5 = new ByteArrayInputStream(s5.getBytes());
+ Binding binding5 = new Binding(new URL(_HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file5.jpg"), is5);
+ bindings.add(binding5);
+
+ request.setBindings(bindings);
+ request.setFailFast(true);
+ DeployResponse response = _deployer.deploy(request);
+
+// for (HttpClientException t:response.getExceptions())
+// t.printStackTrace();
+
+
+ assertEquals(0, response.getExceptions().size());
+
+
+ File f0 = new File(_putServer.getPutDir(), "file0.txt");
+ File f0cs = new File (_putServer.getPutDir(), "file0.txt.sha1");
+ assertTrue (f0.exists());
+ BufferedReader reader = new BufferedReader(new FileReader(f0));
+ String s = reader.readLine();
+ reader.close();
+ assertEquals(s0, s.trim());
+ assertTrue (f0cs.exists());
+
+ File f5 = new File(_putServer.getPutDir(), "file5.jpg");
+ File f5cs = new File (_putServer.getPutDir(), "file5.jpg.sha1");
+ assertTrue (f5.exists());
+ reader = new BufferedReader(new FileReader(f5));
+ s = reader.readLine();
+ reader.close();
+ assertEquals(s5, s.trim());
+ assertTrue (f5cs.exists());
+ }
+}
Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/JettyDeployerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/JettyDeployerTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/JettyRetrieverTest.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/JettyRetrieverTest.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/JettyRetrieverTest.java (added)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/JettyRetrieverTest.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,625 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.maven.mercury.spi.http.client;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.HashSet;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.maven.mercury.crypto.api.StreamVerifierAttributes;
+import org.apache.maven.mercury.crypto.api.StreamVerifierFactory;
+import org.apache.maven.mercury.crypto.pgp.PgpStreamVerifierFactory;
+import org.apache.maven.mercury.crypto.sha.SHA1VerifierFactory;
+import org.apache.maven.mercury.spi.http.client.retrieve.DefaultRetrievalRequest;
+import org.apache.maven.mercury.spi.http.client.retrieve.DefaultRetriever;
+import org.apache.maven.mercury.spi.http.client.retrieve.RetrievalResponse;
+import org.apache.maven.mercury.spi.http.server.SimpleTestServer;
+import org.apache.maven.mercury.spi.http.validate.Validator;
+import org.apache.maven.mercury.transport.api.Binding;
+import org.apache.maven.mercury.transport.api.Server;
+import org.mortbay.util.IO;
+
+public class JettyRetrieverTest extends TestCase
+{
+ public static final String __HOST_FRAGMENT = "http://localhost:";
+ public static final String __PATH_FRAGMENT = "/maven2/repo/";
+
+ private static final String publicKeyFile = "/pgp/pubring.gpg";
+
+ public String _port;
+ File file0;
+ File file1;
+ File file2;
+ File file3;
+ File file4;
+ File file5;
+ File file6;
+
+ DefaultRetriever retriever;
+ SimpleTestServer server;
+ Server remoteServerType;
+ HashSet<StreamVerifierFactory> factories;
+ File dir;
+
+
+ public class TxtValidator implements Validator
+ {
+
+ public String getFileExtension()
+ {
+ return "txt";
+ }
+
+ public boolean validate(String stagedFile, List<String> errors)
+ {
+ if (stagedFile==null)
+ return true;
+ int i = stagedFile.lastIndexOf(".");
+ String ext = (i>=0?stagedFile.substring(i+1):"");
+ if ("txt".equalsIgnoreCase(ext))
+ {
+ //just accept any file contents
+ File f = new File(stagedFile);
+ return f.isFile();
+ }
+
+ return false;
+ }
+
+ }
+
+ public class AlwaysFalseTxtValidator extends TxtValidator
+ {
+ public String getFileExtension()
+ {
+ return "txt";
+ }
+
+ public boolean validate(String stagedFile, List<String> errors)
+ {
+ errors.add("Always false");
+ return false;
+ }
+ }
+
+ public void setUp ()
+ throws Exception
+ {
+ server = new SimpleTestServer();
+ server.start();
+ _port=String.valueOf(server.getPort());
+
+ HashSet<Server> remoteServerTypes = new HashSet<Server>();
+ remoteServerType = new Server( "test", new URL(__HOST_FRAGMENT+_port));
+ factories = new HashSet<StreamVerifierFactory>();
+
+ remoteServerTypes.add(remoteServerType);
+
+ retriever = new DefaultRetriever();
+ retriever.setServers(remoteServerTypes);
+ }
+
+
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ server.stop();
+ server.destroy();
+ destroy(dir);
+ }
+
+
+ public void destroy (File f)
+ {
+ if (f == null)
+ return;
+ if (f.isDirectory())
+ {
+ File[] files = f.listFiles();
+ for (int i=0;files!=null && i<files.length; i++)
+ {
+ destroy (files[i]);
+ }
+ }
+ f.delete();
+ }
+
+ public File mkTempDir()
+ throws Exception
+ {
+ File dir = File.createTempFile("mercury", "tmp");
+ dir.delete();
+ dir.mkdir();
+ dir.deleteOnExit();
+
+ assert dir.exists();
+ assert dir.isDirectory();
+ assert dir.canWrite();
+ return dir;
+ }
+
+ public void testSyncRetrievalAllGood()
+ throws Exception
+ {
+ factories.add( new SHA1VerifierFactory(false, true) ); //!lenient, sufficient
+ remoteServerType.setReaderStreamVerifierFactories(factories);
+
+ //make local dir to put stuff in
+ dir = mkTempDir();
+ DefaultRetrievalRequest request = new DefaultRetrievalRequest();
+ HashSet<Binding> bindings = new HashSet<Binding>();
+
+ file0 = new File(dir, "file0.txt");
+ file1 = new File(dir, "file1.txt");
+ file2 = new File(dir, "file2.txt");
+ file3 = new File(dir, "file3.jar");
+ file4 = new File(dir, "file4.so");
+ file5 = new File(dir, "file5.jpg");
+
+ Binding binding0 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file0.txt"), file0);
+ bindings.add(binding0);
+
+ Binding binding1 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file1.txt"),file1); //has no sha file
+ bindings.add(binding1);
+
+ Binding binding2 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file2.txt"), file2); //has wrong sha file
+ bindings.add(binding2);
+
+ Binding binding3 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file3.jar"), file3);
+ bindings.add(binding3);
+
+ Binding binding4 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file4.so"), file4);
+ bindings.add(binding4);
+
+ Binding binding5 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file5.jpg"), file5);
+ bindings.add(binding5);
+
+ request.setBindings(bindings);
+
+ RetrievalResponse response = retriever.retrieve(request);
+
+// System.err.println("--------- testSyncRetrievalAllGood --------------");
+// for (HttpClientException t:response.getExceptions())
+// t.printStackTrace();
+// System.err.println("-------------------------------------------------");
+ assertEquals( 2, response.getExceptions().size() );
+ assertTrue(!file0.exists());
+ assertTrue(!file1.exists());
+ assertTrue(!file2.exists());
+ assertTrue(!file3.exists());
+ assertTrue(!file4.exists());
+ assertTrue(!file5.exists());
+ }
+
+
+ public void testSyncRetrievalPgpGood()
+ throws Exception
+ {
+ factories.add(
+ new PgpStreamVerifierFactory(
+ new StreamVerifierAttributes( PgpStreamVerifierFactory.DEFAULT_EXTENSION, false, true )
+ , getClass().getResourceAsStream( publicKeyFile )
+ )
+ );
+ remoteServerType.setReaderStreamVerifierFactories(factories);
+
+ //make local dir to put stuff in
+ dir = mkTempDir();
+ DefaultRetrievalRequest request = new DefaultRetrievalRequest();
+ HashSet<Binding> bindings = new HashSet<Binding>();
+
+ file6 = new File(dir, "file6.gif");
+ Binding binding0 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file6.gif"), file6);
+ bindings.add(binding0);
+
+ request.setBindings(bindings);
+
+ RetrievalResponse response = retriever.retrieve(request);
+
+ assertEquals( 0, response.getExceptions().size() );
+ assertTrue( file6.exists() );
+
+ }
+
+
+ public void testSyncRetrievalPgpBad()
+ throws Exception
+ {
+ factories.add(
+ new PgpStreamVerifierFactory(
+ new StreamVerifierAttributes( PgpStreamVerifierFactory.DEFAULT_EXTENSION, false, true )
+ , getClass().getResourceAsStream( publicKeyFile )
+ )
+ );
+ remoteServerType.setReaderStreamVerifierFactories(factories);
+
+ //make local dir to put stuff in
+ dir = mkTempDir();
+ DefaultRetrievalRequest request = new DefaultRetrievalRequest();
+ HashSet<Binding> bindings = new HashSet<Binding>();
+
+ file6 = new File( dir, "file5.jpg" );
+ Binding binding0 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file5.jpg"), file6);
+ bindings.add(binding0);
+
+ request.setBindings(bindings);
+
+ RetrievalResponse response = retriever.retrieve(request);
+
+ assertEquals( 1, response.getExceptions().size() );
+ assertFalse( file6.exists() );
+
+ }
+
+ public void testSyncRetrievalPgpBadExempt()
+ throws Exception
+ {
+ factories.add(
+ new PgpStreamVerifierFactory(
+ new StreamVerifierAttributes( PgpStreamVerifierFactory.DEFAULT_EXTENSION, false, true )
+ , getClass().getResourceAsStream( publicKeyFile )
+ )
+ );
+ remoteServerType.setReaderStreamVerifierFactories(factories);
+
+ //make local dir to put stuff in
+ dir = mkTempDir();
+ DefaultRetrievalRequest request = new DefaultRetrievalRequest();
+ HashSet<Binding> bindings = new HashSet<Binding>();
+
+ file6 = new File( dir, "file5.jpg" );
+ Binding binding0 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file5.jpg"), file6, true );
+ bindings.add(binding0);
+
+ request.setBindings(bindings);
+
+ RetrievalResponse response = retriever.retrieve(request);
+
+ assertEquals( 0, response.getExceptions().size() );
+ assertTrue( file6.exists() );
+
+ }
+
+
+ public void testSyncRetrievalFailFast()
+ throws Exception
+ {
+ factories.add(new SHA1VerifierFactory(false, true)); //!lenient, sufficient
+ remoteServerType.setReaderStreamVerifierFactories(factories);
+
+ //make local dir to put stuff in
+ dir = mkTempDir();
+ DefaultRetrievalRequest request = new DefaultRetrievalRequest();
+ HashSet<Binding> bindings = new HashSet<Binding>();
+
+ file0 = new File(dir, "file0.txt");
+ file1 = new File(dir, "file1.txt");
+ file2 = new File(dir, "file2.txt");
+ file3 = new File(dir, "file3.jar");
+ file4 = new File(dir, "file4.so");
+ file5 = new File(dir, "file5.jpg");
+
+ Binding binding0 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file0.txt"), file0);
+ bindings.add(binding0);
+
+ Binding binding1 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file1.txt"), file1); //has no sha file
+ bindings.add(binding1);
+
+ Binding binding2 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file2.txt"), file2); //has wrong sha file
+ bindings.add(binding2);
+
+ Binding binding3 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file3.jar"), file3);
+ bindings.add(binding3);
+
+ Binding binding4 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file4.so"), file4);
+ bindings.add(binding4);
+
+ Binding binding5 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file5.jpg"), file5);
+ bindings.add(binding5);
+
+
+ request = new DefaultRetrievalRequest();
+ request.setBindings(bindings);
+ request.setFailFast(true);
+
+ request.setBindings(bindings);
+
+ RetrievalResponse response = retriever.retrieve(request);
+
+// System.err.println("--------- testSyncRetrievalFailFast -------------");
+// for (HttpClientException t:response.getExceptions())
+// t.printStackTrace();
+// System.err.println("-------------------------------------------------");
+
+ assertTrue(!file0.exists());
+ assertTrue(!file1.exists());
+ assertTrue(!file2.exists());
+ assertTrue(!file3.exists());
+ assertTrue(!file4.exists());
+ assertTrue(!file5.exists());
+
+ Thread.sleep(100);
+ }
+
+ public void testSyncRetrievalLenient0()
+ throws Exception
+ {
+ factories.add(new SHA1VerifierFactory(true, true)); //lenient, sufficient
+ remoteServerType.setReaderStreamVerifierFactories(factories);
+
+ //make local dir to put stuff in
+ dir = mkTempDir();
+ DefaultRetrievalRequest request = new DefaultRetrievalRequest();
+ HashSet<Binding> bindings = new HashSet<Binding>();
+
+ file0 = new File(dir, "file0.txt");
+ file1 = new File(dir, "file1.txt");
+ file2 = new File(dir, "file2.txt");
+ file3 = new File(dir, "file3.jar");
+ file4 = new File(dir, "file4.so");
+ file5 = new File(dir, "file5.jpg");
+ Binding binding0 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file0.txt"), file0);
+ bindings.add(binding0);
+
+ Binding binding1 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file1.txt"), file1); //has no sha file
+ bindings.add(binding1);
+
+ Binding binding2 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file2.txt"), file2); //has wrong sha file
+ bindings.add(binding2);
+
+ Binding binding3 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file3.jar"),file3 );
+ bindings.add(binding3);
+
+ Binding binding4 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file4.so"), file4);
+ bindings.add(binding4);
+
+ Binding binding5 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file5.jpg"), file5);
+ bindings.add(binding5);
+
+ request.setBindings(bindings);
+ request.setFailFast(false);
+ RetrievalResponse response = retriever.retrieve(request);
+
+// System.err.println("--------- testSyncRetrievalLenient0 -------------");
+// for (HttpClientException t:response.getExceptions())
+// t.printStackTrace();
+// System.err.println("-------------------------------------------------");
+
+ assertEquals(1,response.getExceptions().size());
+ assertEquals(binding2,response.getExceptions().iterator().next().getBinding());
+ assertTrue(!file0.exists());
+ assertTrue(!file1.exists());
+ assertTrue(!file2.exists());
+ assertTrue(!file3.exists());
+ assertTrue(!file4.exists());
+ assertTrue(!file5.exists());
+ }
+
+ public void testSyncRetrievalLenient1()
+ throws Exception
+ {
+ factories.add(new SHA1VerifierFactory(true, true)); //lenient, sufficient
+ remoteServerType.setReaderStreamVerifierFactories(factories);
+ //make local dir to put stuff in
+ dir = mkTempDir();
+ DefaultRetrievalRequest request = new DefaultRetrievalRequest();
+ HashSet<Binding> bindings = new HashSet<Binding>();
+
+ file0 = new File(dir, "file0.txt");
+ file1 = new File(dir, "file1.txt");
+ file2 = new File(dir, "file2.txt");
+ file3 = new File(dir, "file3.jar");
+ file4 = new File(dir, "file4.so");
+ file5 = new File(dir, "file5.jpg");
+ Binding binding0 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file0.txt"), file0);
+ bindings.add(binding0);
+
+ Binding binding1 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file1.txt"), file1); //has no sha file
+ bindings.add(binding1);
+
+ Binding binding3 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file3.jar"), file3);
+ bindings.add(binding3);
+
+ Binding binding4 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file4.so"), file4);
+ bindings.add(binding4);
+
+ Binding binding5 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file5.jpg"), file5);
+ bindings.add(binding5);
+
+ request.setBindings(bindings);
+ request.setFailFast(false);
+ RetrievalResponse response = retriever.retrieve(request);
+
+// System.err.println("------------- testSyncRetrievalLenient1 ---------");
+// for (HttpClientException t:response.getExceptions())
+// t.printStackTrace();
+// System.err.println("-------------------------------------------------");
+
+ assertEquals(0,response.getExceptions().size());
+ assertTrue(file0.exists());
+ assertTrue(file1.exists());
+ assertTrue(!file2.exists());
+ assertTrue(file3.exists());
+ assertTrue(file4.exists());
+ assertTrue(file5.exists());
+
+ }
+
+ public void testValidatorSuccess() throws Exception
+ {
+ factories.add(new SHA1VerifierFactory(true, true)); //lenient, sufficient
+ remoteServerType.setReaderStreamVerifierFactories(factories);
+
+ //make local dir to put stuff in
+ dir = mkTempDir();
+ DefaultRetrievalRequest request = new DefaultRetrievalRequest();
+ HashSet<Binding> bindings = new HashSet<Binding>();
+ HashSet<Validator> validators = new HashSet<Validator>();
+ validators.add(new TxtValidator());
+ request.setValidators(validators);
+
+ file0 = new File(dir, "file0.txt");
+ file1 = new File(dir, "file1.txt");
+ file2 = new File(dir, "file2.txt");
+ file3 = new File(dir, "file3.jar");
+ file4 = new File(dir, "file4.so");
+ file5 = new File(dir, "file5.jpg");
+
+ Binding binding0 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file0.txt"), file0);
+ bindings.add(binding0);
+
+ Binding binding1 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file1.txt"), file1); //has no sha file
+ bindings.add(binding1);
+
+ Binding binding3 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file3.jar"), file3);
+ bindings.add(binding3);
+
+ Binding binding4 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file4.so"), file4);
+ bindings.add(binding4);
+
+ Binding binding5 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file5.jpg"), file5);
+ bindings.add(binding5);
+
+ request.setFailFast(false);
+
+ request.setBindings(bindings);
+ RetrievalResponse response = retriever.retrieve(request);
+
+// System.err.println("------------ testValidatorSuccess ---------------");
+// for (HttpClientException t:response.getExceptions())
+// t.printStackTrace();
+// System.err.println("-------------------------------------------------");
+
+ assertEquals(0,response.getExceptions().size());
+ assertTrue(file0.exists());
+ assertTrue(file1.exists());
+ assertTrue(!file2.exists());
+ assertTrue(file3.exists());
+ assertTrue(file4.exists());
+ assertTrue(file5.exists());
+ }
+
+ public void testValidatorFailure () throws Exception
+ {
+ factories.add(new SHA1VerifierFactory(true, true)); //lenient, sufficient
+ remoteServerType.setReaderStreamVerifierFactories(factories);
+
+ //make local dir to put stuff in
+ dir = mkTempDir();
+ DefaultRetrievalRequest request = new DefaultRetrievalRequest();
+ HashSet<Binding> bindings = new HashSet<Binding>();
+ HashSet<Validator> validators = new HashSet<Validator>();
+ validators.add(new AlwaysFalseTxtValidator());
+ request.setValidators(validators);
+
+ file0 = new File(dir, "file0.txt");
+ file1 = new File(dir, "file1.txt");
+ file2 = new File(dir, "file2.txt");
+ file3 = new File(dir, "file3.jar");
+ file4 = new File(dir, "file4.so");
+ file5 = new File(dir, "file5.jpg");
+
+ Binding binding0 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file0.txt"), file0);
+ bindings.add(binding0);
+
+ Binding binding1 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file1.txt"), file1); //has no sha file
+ bindings.add(binding1);
+
+ Binding binding3 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file3.jar"), file3);
+ bindings.add(binding3);
+
+ Binding binding4 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file4.so"), file4);
+ bindings.add(binding4);
+
+ Binding binding5 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file5.jpg"), file5);
+ bindings.add(binding5);
+
+ request.setFailFast(false);
+
+ request.setBindings(bindings);
+ RetrievalResponse response = retriever.retrieve(request);
+
+// System.err.println("---------- testValidatorFail --------------------");
+// for (HttpClientException t:response.getExceptions())
+// t.printStackTrace();
+// System.err.println("-------------------------------------------------");
+
+ assertEquals(2,response.getExceptions().size());
+ assertTrue(!file0.exists());
+ assertTrue(!file1.exists());
+ assertTrue(!file2.exists());
+ assertTrue(!file3.exists());
+ assertTrue(!file4.exists());
+ assertTrue(!file5.exists());
+ }
+
+ public void testMemoryRetrieval () throws Exception
+ {
+ factories.add(new SHA1VerifierFactory(true, true)); //lenient, sufficient
+ remoteServerType.setReaderStreamVerifierFactories(factories);
+
+ //make local dir to put stuff in
+ dir = mkTempDir();
+ DefaultRetrievalRequest request = new DefaultRetrievalRequest();
+ HashSet<Binding> bindings = new HashSet<Binding>();
+ HashSet<Validator> validators = new HashSet<Validator>();
+ validators.add(new TxtValidator());
+ request.setValidators(validators);
+
+ Binding binding0 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file0.txt"));
+ bindings.add(binding0);
+
+ Binding binding5 = new Binding(new URL(__HOST_FRAGMENT+_port+__PATH_FRAGMENT+"file5.jpg"));
+ bindings.add(binding5);
+
+ request.setFailFast(false);
+
+ request.setBindings(bindings);
+ RetrievalResponse response = retriever.retrieve(request);
+
+// System.err.println("--------- testMemoryRetrieval -------------------");
+// for (HttpClientException t:response.getExceptions())
+// t.printStackTrace();
+// System.err.println("-------------------------------------------------");
+
+ assertEquals(0,response.getExceptions().size());
+
+
+ InputStream is = this.getClass().getResourceAsStream("/testRepo/file0.txt");
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ IO.copy(is, os);
+ assertEquals(os.toByteArray().length, binding0.getInboundContent().length);
+ is.close();
+ os.close();
+
+ is = this.getClass().getResourceAsStream("/testRepo/file5.jpg");
+ os.reset();
+ IO.copy(is,os);
+ assertEquals(os.toByteArray().length, binding5.getInboundContent().length);
+ is.close();
+ os.close();
+ }
+
+}
Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/JettyRetrieverTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/JettyRetrieverTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/ProxyJettyDeployerTest.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/ProxyJettyDeployerTest.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/ProxyJettyDeployerTest.java (added)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/ProxyJettyDeployerTest.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,84 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.maven.mercury.spi.http.client;
+
+import java.net.URL;
+import java.util.HashSet;
+
+import org.apache.maven.mercury.crypto.api.StreamVerifierFactory;
+import org.apache.maven.mercury.spi.http.client.deploy.DefaultDeployer;
+import org.apache.maven.mercury.spi.http.server.AuthenticatingProxyServer;
+import org.apache.maven.mercury.spi.http.server.AuthenticatingPutServer;
+import org.apache.maven.mercury.transport.api.Credentials;
+
+public class ProxyJettyDeployerTest extends JettyDeployerTest
+{
+
+
+ AuthenticatingProxyServer _proxyServer;
+ String _proxyPort;
+
+
+ public ProxyJettyDeployerTest() throws Exception
+ {
+ super();
+ }
+ protected void setUp() throws Exception
+ {
+ setUpFiles();
+ //Set up a proxy server (which requires authentication)
+ _proxyServer = new AuthenticatingProxyServer();
+ _proxyServer.start();
+ _proxyPort = String.valueOf(_proxyServer.getPort());
+
+ _deployer = new DefaultDeployer();
+
+ //set up a target server (which requires authentication)
+ _putServer = new AuthenticatingPutServer();
+ _putServer.start();
+ _port = String.valueOf(_putServer.getPort());
+ setUpServerType();
+ }
+
+
+
+ protected void setUpServerType () throws Exception
+ {
+ HashSet<org.apache.maven.mercury.transport.api.Server> remoteServerTypes = new HashSet<org.apache.maven.mercury.transport.api.Server>();
+ remoteServerType = new org.apache.maven.mercury.transport.api.Server( "test",
+ new URL(_HOST_FRAGMENT+_port),
+ false,
+ false,
+ new Credentials(((AuthenticatingPutServer)_putServer).getUsername(), ((AuthenticatingPutServer)_putServer).getPassword()),
+ new URL(_HOST_FRAGMENT+_proxyPort),
+ new Credentials(_proxyServer.getUsername(), _proxyServer.getPassword()));
+ factories = new HashSet<StreamVerifierFactory>();
+ remoteServerTypes.add(remoteServerType);
+ _deployer.setServers(remoteServerTypes);
+ }
+
+
+
+ protected void tearDown() throws Exception
+ {
+ _proxyServer.stop();
+ super.tearDown();
+ }
+}
Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/ProxyJettyDeployerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/ProxyJettyDeployerTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/ProxyJettyRetrieverTest.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/ProxyJettyRetrieverTest.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/ProxyJettyRetrieverTest.java (added)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/ProxyJettyRetrieverTest.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,70 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.mercury.spi.http.client;
+
+import java.net.URL;
+import java.util.HashSet;
+
+import org.apache.maven.mercury.crypto.api.StreamVerifierFactory;
+import org.apache.maven.mercury.spi.http.client.retrieve.DefaultRetriever;
+import org.apache.maven.mercury.spi.http.server.AuthenticatingProxyServer;
+import org.apache.maven.mercury.spi.http.server.AuthenticatingTestServer;
+import org.apache.maven.mercury.transport.api.Credentials;
+import org.apache.maven.mercury.transport.api.Server;
+
+public class ProxyJettyRetrieverTest extends JettyRetrieverTest
+{
+ AuthenticatingProxyServer _proxyServer;
+ String _proxyPort;
+
+ public void setUp ()
+ throws Exception
+ {
+ //Set up a proxy server (which requires authentication)
+ _proxyServer = new AuthenticatingProxyServer();
+ _proxyServer.start();
+ _proxyPort = String.valueOf(_proxyServer.getPort());
+
+ //Set up the real target server (which requires authentication)
+ server = new AuthenticatingTestServer();
+ server.start();
+ _port=String.valueOf(server.getPort());
+
+ HashSet<Server> remoteServerTypes = new HashSet<Server>();
+ remoteServerType = new Server( "test", new URL(__HOST_FRAGMENT+_port),
+ false,
+ false,
+ new Credentials(((AuthenticatingTestServer)server).getUsername(), ((AuthenticatingTestServer)server).getPassword()),
+ new URL(__HOST_FRAGMENT+_proxyPort),
+ new Credentials(_proxyServer.getUsername(), _proxyServer.getPassword()));
+ factories = new HashSet<StreamVerifierFactory>();
+
+ remoteServerTypes.add(remoteServerType);
+
+ retriever = new DefaultRetriever();
+ retriever.setServers(remoteServerTypes);
+ }
+
+
+ protected void tearDown() throws Exception
+ {
+ _proxyServer.stop();
+ super.tearDown();
+ }
+}
Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/ProxyJettyRetrieverTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/ProxyJettyRetrieverTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/SecureJettyDeployerTest.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/SecureJettyDeployerTest.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/SecureJettyDeployerTest.java (added)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/SecureJettyDeployerTest.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,46 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.maven.mercury.spi.http.client;
+
+import org.apache.maven.mercury.spi.http.client.deploy.DefaultDeployer;
+import org.apache.maven.mercury.spi.http.server.SecurePutServer;
+
+public class SecureJettyDeployerTest extends JettyDeployerTest
+{
+ public SecureJettyDeployerTest() throws Exception
+ {
+ super();
+ }
+
+ protected void setUp() throws Exception
+ {
+ _HOST_FRAGMENT = "https://localhost:";
+
+ setUpFiles();
+ _deployer = new DefaultDeployer();
+ _putServer = new SecurePutServer();
+ _putServer.start();
+ _port = String.valueOf(_putServer.getPort());
+ setUpServerType();
+ //super.setUp();
+ }
+
+
+}
Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/SecureJettyDeployerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/client/SecureJettyDeployerTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/AuthenticatingProxyServer.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/AuthenticatingProxyServer.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/AuthenticatingProxyServer.java (added)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/AuthenticatingProxyServer.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,111 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.mercury.spi.http.server;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.handler.DefaultHandler;
+import org.mortbay.jetty.handler.HandlerCollection;
+import org.mortbay.jetty.security.B64Code;
+import org.mortbay.jetty.security.HashUserRealm;
+import org.mortbay.jetty.servlet.Context;
+import org.mortbay.servlet.ProxyServlet;
+import org.mortbay.util.StringUtil;
+
+public class AuthenticatingProxyServer extends Server
+{
+ public static final String __username = "foo";
+ public static final String __password = "banana";
+ public static final String __role = "fooproxy";
+ protected Context _context;
+
+
+
+
+ public static class AuthProxyServlet extends ProxyServlet
+ {
+ public void service(ServletRequest request, ServletResponse response)
+ throws ServletException, IOException
+ {
+ String proxyAuth = ((HttpServletRequest)request).getHeader("Proxy-Authorization");
+ if (proxyAuth!=null)
+ {
+ String authType = proxyAuth.substring(0,6);
+
+ if (authType.equalsIgnoreCase("basic "))
+ proxyAuth = proxyAuth.substring(6);
+
+ proxyAuth = B64Code.decode(proxyAuth,StringUtil.__ISO_8859_1);
+ int sep = proxyAuth.indexOf(":");
+ String username = proxyAuth.substring(0,sep);
+ String password = proxyAuth.substring(sep+1);
+
+ if (__username.equalsIgnoreCase(username) && __password.equalsIgnoreCase(password))
+ super.service(request, response);
+ else
+ ((HttpServletResponse)response).setStatus(HttpServletResponse.SC_FORBIDDEN);
+ }
+ else
+ {
+ ((HttpServletResponse)response).setStatus(HttpServletResponse.SC_FORBIDDEN);
+ }
+ }
+ }
+
+ public AuthenticatingProxyServer()
+ throws Exception
+ {
+ super( 0 );
+
+ HandlerCollection handlers = new HandlerCollection();
+ setHandler( handlers );
+
+ _context = new Context( handlers, "/" );
+ handlers.addHandler( new DefaultHandler() );
+
+ _context.addServlet( AuthProxyServlet.class, "/" );
+
+ HashUserRealm realm = new HashUserRealm();
+ realm.put (__username, __password);
+ realm.addUserToRole(__username, __role);
+ realm.setName("proxyrealm");
+ }
+
+ public int getPort()
+ {
+ return getConnectors()[0].getLocalPort();
+ }
+
+ public String getUsername()
+ {
+ return __username;
+ }
+
+ public String getPassword()
+ {
+ return __password;
+ }
+}
Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/AuthenticatingProxyServer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/AuthenticatingProxyServer.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/AuthenticatingPutServer.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/AuthenticatingPutServer.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/AuthenticatingPutServer.java (added)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/AuthenticatingPutServer.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.mercury.spi.http.server;
+
+import org.mortbay.jetty.security.BasicAuthenticator;
+import org.mortbay.jetty.security.Constraint;
+import org.mortbay.jetty.security.ConstraintMapping;
+import org.mortbay.jetty.security.HashUserRealm;
+import org.mortbay.jetty.security.SecurityHandler;
+
+public class AuthenticatingPutServer extends SimplePutServer
+{
+ private String _username = "foo";
+ private String _password = "bar";
+ private String _role = "foomeister";
+
+ public AuthenticatingPutServer()
+ throws Exception
+ {
+ super();
+
+ HashUserRealm realm = new HashUserRealm();
+ realm.put (_username, _password);
+ realm.addUserToRole(_username, _role);
+ realm.setName("foorealm");
+
+ SecurityHandler securityHandler = new SecurityHandler();
+ securityHandler.setAuthenticator(new BasicAuthenticator());
+ securityHandler.setUserRealm(realm);
+ Constraint constraint = new Constraint();
+ constraint.setAuthenticate(true);
+ constraint.setRoles(new String[]{_role});
+ ConstraintMapping cm = new ConstraintMapping();
+ cm.setConstraint(constraint);
+ cm.setPathSpec("/*");
+ securityHandler.setConstraintMappings(new ConstraintMapping[]{cm});
+ context.addHandler(securityHandler);
+ }
+
+ public static void main(String[] args)
+ throws Exception
+ {
+ AuthenticatingPutServer server = new AuthenticatingPutServer();
+ server.start();
+ server.join();
+ }
+
+ public String getUsername()
+ {
+ return _username;
+ }
+
+ public String getPassword ()
+ {
+ return _password;
+ }
+}
Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/AuthenticatingPutServer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/AuthenticatingPutServer.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/AuthenticatingTestServer.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/AuthenticatingTestServer.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/AuthenticatingTestServer.java (added)
+++ maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/AuthenticatingTestServer.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,86 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.mercury.spi.http.server;
+
+import java.io.File;
+
+import org.mortbay.jetty.security.BasicAuthenticator;
+import org.mortbay.jetty.security.Constraint;
+import org.mortbay.jetty.security.ConstraintMapping;
+import org.mortbay.jetty.security.HashUserRealm;
+import org.mortbay.jetty.security.SecurityHandler;
+
+public class AuthenticatingTestServer
+extends SimpleTestServer
+{
+ private static final String __username = "foo";
+ private static final String __password = "bar";
+ private static final String __role = "foomeister";
+
+ public void secure()
+ {
+ HashUserRealm realm = new HashUserRealm();
+ realm.put (__username, __password);
+ realm.addUserToRole(__username, __role);
+ realm.setName("foorealm");
+
+ SecurityHandler securityHandler = new SecurityHandler();
+ securityHandler.setAuthenticator(new BasicAuthenticator());
+ securityHandler.setUserRealm(realm);
+ Constraint constraint = new Constraint();
+ constraint.setAuthenticate(true);
+ constraint.setRoles(new String[]{__role});
+ ConstraintMapping cm = new ConstraintMapping();
+ cm.setConstraint(constraint);
+ cm.setPathSpec("/*");
+ securityHandler.setConstraintMappings(new ConstraintMapping[]{cm});
+ context.addHandler(securityHandler);
+ }
+
+ public AuthenticatingTestServer( int port, File localBase, String remotePathFragment, boolean secured )
+ throws Exception
+ {
+ super( port, localBase, remotePathFragment );
+ if( secured )
+ secure();
+ }
+
+ public AuthenticatingTestServer( int port, File localBase, String remotePathFragment )
+ throws Exception
+ {
+ this( port, localBase, remotePathFragment, true );
+ }
+
+ public AuthenticatingTestServer()
+ throws Exception
+ {
+ super();
+ secure();
+ }
+
+ public String getUsername()
+ {
+ return __username;
+ }
+
+ public String getPassword()
+ {
+ return __password;
+ }
+}
Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/AuthenticatingTestServer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/test/java/org/apache/maven/mercury/spi/http/server/AuthenticatingTestServer.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision