maven-wagon-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r477167 - in /maven/wagon/trunk/wagon-providers/wagon-ssh/src: main/java/org/apache/maven/wagon/providers/ssh/ main/java/org/apache/maven/wagon/providers/ssh/knownhost/ test/java/org/apache/maven/wagon/providers/ssh/knownhost/ test/resource...
Date Mon, 20 Nov 2006 13:16:25 GMT
Author: brett
Date: Mon Nov 20 05:16:22 2006
New Revision: 477167

URL: http://svn.apache.org/viewvc?view=rev&rev=477167
Log:
Factor out jsch specifics

Added:
    maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/KnownHostChangedException.java
  (with props)
    maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/UnknownHostException.java
  (with props)
    maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/resources/org/apache/maven/wagon/providers/ssh/knownhost/changed.knownhosts
Removed:
    maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/resources/org/apache/maven/wagon/providers/ssh/knownhost/ok.knownhosts
Modified:
    maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/AbstractSshWagon.java
    maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/AbstractKnownHostsProvider.java
    maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/FileKnownHostsProvider.java
    maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/KnownHostsProvider.java
    maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/NullKnownHostProvider.java
    maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/SingleKnownHostProvider.java
    maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/StreamKnownHostsProvider.java
    maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/AbstractKnownHostsProviderTest.java
    maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/SingleKnownHostsProviderTest.java
    maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/StreamKnownHostsProviderTest.java
    maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/resources/org/apache/maven/wagon/providers/ssh/knownhost/fail.knownhosts

Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/AbstractSshWagon.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/AbstractSshWagon.java?view=diff&rev=477167&r1=477166&r2=477167
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/AbstractSshWagon.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/AbstractSshWagon.java
Mon Nov 20 05:16:22 2006
@@ -17,6 +17,8 @@
  */
 
 import com.jcraft.jsch.ChannelExec;
+import com.jcraft.jsch.HostKey;
+import com.jcraft.jsch.HostKeyRepository;
 import com.jcraft.jsch.JSch;
 import com.jcraft.jsch.JSchException;
 import com.jcraft.jsch.Proxy;
@@ -40,10 +42,13 @@
 import org.apache.maven.wagon.providers.ssh.interactive.NullInteractiveUserInfo;
 import org.apache.maven.wagon.providers.ssh.interactive.UserInfoUIKeyboardInteractiveProxy;
 import org.apache.maven.wagon.providers.ssh.knownhost.KnownHostsProvider;
+import org.apache.maven.wagon.providers.ssh.knownhost.UnknownHostException;
+import org.apache.maven.wagon.providers.ssh.knownhost.KnownHostChangedException;
 import org.apache.maven.wagon.repository.RepositoryPermissions;
 import org.apache.maven.wagon.resource.Resource;
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.StringInputStream;
 import org.codehaus.plexus.util.StringUtils;
 
 import java.io.BufferedReader;
@@ -52,7 +57,9 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
+import java.io.PrintWriter;
 import java.io.StringReader;
+import java.io.StringWriter;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Properties;
@@ -140,21 +147,16 @@
             }
         }
 
-        Properties config = new Properties();
-        config.setProperty( "BatchMode", interactive ? "no" : "yes" );
-
         if ( !interactive )
         {
             interactiveUserInfo = new NullInteractiveUserInfo();
             uIKeyboardInteractive = null;
         }
 
-        knownHostsProvider.addConfiguration( config );
-
-        initJsch( privateKey, host, port, config );
+        initJsch( privateKey, host, port );
     }
 
-    private void initJsch( File privateKey, String host, int port, Properties config )
+    private void initJsch( File privateKey, String host, int port )
         throws AuthenticationException
     {
         JSch sch = new JSch();
@@ -217,37 +219,80 @@
             ui = new UserInfoUIKeyboardInteractiveProxy( ui, uIKeyboardInteractive );
         }
 
+        Properties config = new Properties();
         if ( knownHostsProvider != null )
         {
             try
             {
-                knownHostsProvider.addKnownHosts( sch, ui );
+                String contents = knownHostsProvider.getContents();
+                if ( contents != null )
+                {
+                    sch.setKnownHosts( new StringInputStream( contents ) );
+                }
             }
             catch ( JSchException e )
             {
                 fireSessionError( e );
                 // continue without known_hosts
             }
+            config.setProperty( "StrictHostKeyChecking", knownHostsProvider.getHostKeyChecking()
);
         }
 
+        config.setProperty( "BatchMode", interactive ? "no" : "yes" );
+
         session.setConfig( config );
 
         session.setUserInfo( ui );
 
+        StringWriter stringWriter = new StringWriter();
         try
         {
             session.connect();
 
             if ( knownHostsProvider != null )
             {
-                knownHostsProvider.storeKnownHosts( sch );
+                PrintWriter w = new PrintWriter( stringWriter );
+
+                HostKeyRepository hkr = sch.getHostKeyRepository();
+                HostKey[] keys = hkr.getHostKey();
+
+                for ( int i = 0; i < keys.length; i++ )
+                {
+                    HostKey key = keys[i];
+                    w.println( key.getHost() + " " + key.getType() + " " + key.getKey() );
+                }
             }
         }
         catch ( JSchException e )
         {
             fireSessionError( e );
 
-            throw new AuthenticationException( "Cannot connect. Reason: " + e.getMessage(),
e );
+            if ( e.getMessage().startsWith( "UnknownHostKey:" ) || e.getMessage().startsWith(
"reject HostKey:") )
+            {
+                throw new UnknownHostException( host, e );
+            }
+            else if ( e.getMessage().indexOf( "HostKey has been changed" ) >= 0 )
+            {
+                throw new KnownHostChangedException( host, e );
+            }
+            else
+            {
+                throw new AuthenticationException( "Cannot connect. Reason: " + e.getMessage(),
e );
+            }
+        }
+
+        try
+        {
+            knownHostsProvider.storeKnownHosts( stringWriter.toString() );
+        }
+        catch ( IOException e )
+        {
+            closeConnection();
+
+            fireSessionError( e );
+
+            throw new AuthenticationException(
+                "Connection aborted - failed to write to known_hosts. Reason: " + e.getMessage(),
e );
         }
     }
 

Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/AbstractKnownHostsProvider.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/AbstractKnownHostsProvider.java?view=diff&rev=477167&r1=477166&r2=477167
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/AbstractKnownHostsProvider.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/AbstractKnownHostsProvider.java
Mon Nov 20 05:16:22 2006
@@ -16,9 +16,6 @@
  * limitations under the License.
  */
 
-import com.jcraft.jsch.JSch;
-
-import java.util.Properties;
 import java.io.IOException;
 
 /**
@@ -30,12 +27,15 @@
 public abstract class AbstractKnownHostsProvider
     implements KnownHostsProvider
 {
-    private String hostKeyChecking;
-
-    public void addConfiguration( Properties config )
-    {
-        config.setProperty( HOST_KEY_CHECKING, hostKeyChecking );
-    }
+    /**
+     * Valid values are ask, yes, no.
+     */
+    private String hostKeyChecking = "yes";
+
+    /**
+     * the known hosts, in the openssh format
+     */
+    protected String contents;
 
     public void setHostKeyChecking( String hostKeyChecking )
     {
@@ -47,7 +47,13 @@
         return hostKeyChecking;
     }
 
-    public void storeKnownHosts( JSch sch )
+    public String getContents()
+    {
+        return contents;
+    }
+
+    public void storeKnownHosts( String contents )
+        throws IOException
     {
     }
 }

Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/FileKnownHostsProvider.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/FileKnownHostsProvider.java?view=diff&rev=477167&r1=477166&r2=477167
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/FileKnownHostsProvider.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/FileKnownHostsProvider.java
Mon Nov 20 05:16:22 2006
@@ -2,7 +2,6 @@
 
 import com.jcraft.jsch.HostKey;
 import com.jcraft.jsch.HostKeyRepository;
-import com.jcraft.jsch.JSch;
 
 import java.io.ByteArrayInputStream;
 import java.io.File;
@@ -13,6 +12,7 @@
 import java.io.PrintWriter;
 
 import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.FileUtils;
 
 /*
  * Copyright 2001-2005 The Apache Software Foundation.
@@ -66,32 +66,11 @@
         this( new File( System.getProperty( "user.home" ), ".ssh/known_hosts" ) );
     }
 
-    public void storeKnownHosts( JSch sch )
+    public void storeKnownHosts( String contents )
+        throws IOException
     {
-        PrintWriter w = null;
-        try
-        {
-            w = new PrintWriter( new FileWriter( file ) );
-
-            HostKeyRepository hkr = sch.getHostKeyRepository();
-            HostKey[] keys = hkr.getHostKey();
-
-            for ( int i = 0; i < keys.length; i++ )
-            {
-                HostKey key = keys[i];
-                w.println( key.getHost() + " " + key.getType() + " " + key.getKey() );
-            }
-        }
-        catch ( IOException e )
-        {
-            // TODO: log it
-        }
-        finally
-        {
-            IOUtil.close( w );
-        }
-
-        super.storeKnownHosts( sch );
+        file.getParentFile().mkdirs();
+        FileUtils.fileWrite( file.getAbsolutePath(), contents );
     }
 
     public File getFile()

Added: maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/KnownHostChangedException.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/KnownHostChangedException.java?view=auto&rev=477167
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/KnownHostChangedException.java
(added)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/KnownHostChangedException.java
Mon Nov 20 05:16:22 2006
@@ -0,0 +1,15 @@
+package org.apache.maven.wagon.providers.ssh.knownhost;
+
+import org.apache.maven.wagon.authentication.AuthenticationException;
+
+/**
+ * Exception related to known_host check failures.
+ */
+public class KnownHostChangedException
+    extends AuthenticationException
+{
+    public KnownHostChangedException( String host, Throwable cause )
+    {
+        super( "The host key was different to that in the known_hosts configuration for host:
" + host, cause );
+    }
+}

Propchange: maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/KnownHostChangedException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/KnownHostsProvider.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/KnownHostsProvider.java?view=diff&rev=477167&r1=477166&r2=477167
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/KnownHostsProvider.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/KnownHostsProvider.java
Mon Nov 20 05:16:22 2006
@@ -21,6 +21,7 @@
 import com.jcraft.jsch.UserInfo;
 
 import java.util.Properties;
+import java.io.IOException;
 
 /**
  * Provides a way to add Known Hosts fingerprints to the JSch transport
@@ -32,21 +33,12 @@
 {
     String ROLE = KnownHostsProvider.class.getName();
 
-    String HOST_KEY_CHECKING = "StrictHostKeyChecking";
-
-    /**
-     * Adds to the session all the known hosts
-     * 
-     * @param sch JSch transport
-     */
-    void addKnownHosts( JSch sch, UserInfo userInfo )
-        throws JSchException;
-
-    void addConfiguration( Properties config );
-
-    void storeKnownHosts( JSch sch );
+    void storeKnownHosts( String contents )
+        throws IOException;
 
     void setHostKeyChecking( String hostKeyChecking );
 
     String getHostKeyChecking();
+
+    String getContents();
 }

Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/NullKnownHostProvider.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/NullKnownHostProvider.java?view=diff&rev=477167&r1=477166&r2=477167
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/NullKnownHostProvider.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/NullKnownHostProvider.java
Mon Nov 20 05:16:22 2006
@@ -31,11 +31,4 @@
 public final class NullKnownHostProvider
     extends AbstractKnownHostsProvider
 {
-    /**
-     * @see KnownHostsProvider#addKnownHosts(com.jcraft.jsch.JSch, com.jcraft.jsch.UserInfo)
-     */
-    public void addKnownHosts( JSch sch, UserInfo userInfo )
-    {
-        // nothing to do ;-)
-    }
 }

Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/SingleKnownHostProvider.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/SingleKnownHostProvider.java?view=diff&rev=477167&r1=477166&r2=477167
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/SingleKnownHostProvider.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/SingleKnownHostProvider.java
Mon Nov 20 05:16:22 2006
@@ -31,34 +31,10 @@
     extends AbstractKnownHostsProvider
 {
     /**
-     * the host ...
-     */
-    private String host;
-
-    /**
-     * the key ...
-     */
-    private String key;
-
-    public SingleKnownHostProvider()
-    {
-    }
-
-    /**
      * Creates the SingleKnownHostProvider.
      */
     public SingleKnownHostProvider( String host, String key )
     {
-        this.host = host;
-        this.key = key;
-    }
-
-    /**
-     * @see KnownHostsProvider#addKnownHosts(com.jcraft.jsch.JSch, UserInfo)
-     */
-    public void addKnownHosts( JSch sch, UserInfo userInfo )
-    {
-        HostKeyRepository hkr = sch.getHostKeyRepository();
-        hkr.add( host, Base64.decodeBase64( key.getBytes() ), userInfo );
+        this.contents = host + " ssh-rsa " + key + "\n";
     }
 }

Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/StreamKnownHostsProvider.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/StreamKnownHostsProvider.java?view=diff&rev=477167&r1=477166&r2=477167
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/StreamKnownHostsProvider.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/StreamKnownHostsProvider.java
Mon Nov 20 05:16:22 2006
@@ -35,10 +35,6 @@
 public class StreamKnownHostsProvider
     extends AbstractKnownHostsProvider
 {
-    /**
-     * the known hosts, in the openssh format
-     */
-    private final String contents;
 
     public StreamKnownHostsProvider( InputStream stream )
         throws IOException
@@ -53,14 +49,5 @@
         {
             IOUtil.close( stream );
         }
-    }
-
-    /**
-     * @see KnownHostsProvider#addKnownHosts(com.jcraft.jsch.JSch, UserInfo)
-     */
-    public void addKnownHosts( JSch sch, UserInfo userInfo )
-        throws JSchException
-    {
-        sch.setKnownHosts( new StringInputStream( contents ) );
     }
 }

Added: maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/UnknownHostException.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/UnknownHostException.java?view=auto&rev=477167
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/UnknownHostException.java
(added)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/UnknownHostException.java
Mon Nov 20 05:16:22 2006
@@ -0,0 +1,31 @@
+package org.apache.maven.wagon.providers.ssh.knownhost;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+import org.apache.maven.wagon.authentication.AuthenticationException;
+
+/**
+ * Exception related to known_host check failures.
+ */
+public class UnknownHostException
+    extends AuthenticationException
+{
+    public UnknownHostException( String host, Throwable cause )
+    {
+        super( "The host was not known and was not accepted by the configuration: " + host,
cause );
+    }
+}

Propchange: maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/UnknownHostException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/AbstractKnownHostsProviderTest.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/AbstractKnownHostsProviderTest.java?view=diff&rev=477167&r1=477166&r2=477167
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/AbstractKnownHostsProviderTest.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/AbstractKnownHostsProviderTest.java
Mon Nov 20 05:16:22 2006
@@ -16,12 +16,11 @@
  * limitations under the License.
  */
 
-import com.jcraft.jsch.JSch;
-import com.jcraft.jsch.JSchException;
-import com.jcraft.jsch.Session;
-import junit.framework.TestCase;
-import org.apache.maven.wagon.providers.ssh.knownhost.KnownHostsProvider;
+import org.apache.maven.wagon.Wagon;
+import org.apache.maven.wagon.providers.ssh.AbstractSshWagon;
 import org.apache.maven.wagon.providers.ssh.TestData;
+import org.apache.maven.wagon.repository.Repository;
+import org.codehaus.plexus.PlexusTestCase;
 
 /**
  * Generic Unit test for <code>KnownHostsProvider</code>
@@ -31,15 +30,17 @@
  * @since Sep 12, 2005
  */
 public abstract class AbstractKnownHostsProviderTest
-    extends TestCase
+    extends PlexusTestCase
 {
     protected KnownHostsProvider okHostsProvider;
 
     protected KnownHostsProvider failHostsProvider;
 
-    protected final String user = TestData.getUserName();
+    protected KnownHostsProvider changedHostsProvider;
 
-    protected String host;
+    private AbstractSshWagon wagon;
+
+    private Repository source;
 
     /**
      * tests what happens if the remote host has a different key than the one
@@ -50,43 +51,63 @@
     public void testIncorrectKey()
         throws Exception
     {
-        final JSch sch = new JSch();
+        wagon.setKnownHostsProvider( failHostsProvider );
 
-        failHostsProvider.addKnownHosts( sch, null );
         try
         {
-            sch.getSession( user, host ).connect();
+            wagon.connect( source );
 
             fail( "Should not have successfully connected - host is not known" );
         }
-        catch ( JSchException e )
+        catch ( UnknownHostException e )
         {
-            assertTrue( e.getMessage().startsWith( "UnknownHostKey:" ) );
+            // ok
         }
     }
 
     /**
-     * tests what happens if the remote host has the expected key
+     * tests what happens if the remote host has changed since being recorded.
      *
      * @throws Exception on error
      */
-    public void testCorrectKey()
+    public void testChangedKey()
         throws Exception
     {
-        final JSch sch = new JSch();
-        sch.addIdentity( TestData.getPrivateKey().getAbsolutePath(), "" );
-
-        okHostsProvider.addKnownHosts( sch, null );
-
-        final Session session = sch.getSession( user, host );
+        wagon.setKnownHostsProvider( changedHostsProvider );
 
         try
         {
-            session.connect();
+            wagon.connect( source );
+
+            fail( "Should not have successfully connected - host is changed" );
         }
-        catch ( JSchException e )
+        catch ( KnownHostChangedException e )
         {
-            assertFalse( e.getMessage().indexOf( "UnknownHostKey") >= 0 );
+            // ok
         }
+    }
+
+    /**
+     * tests what happens if the remote host has the expected key
+     *
+     * @throws Exception on error
+     */
+    public void testCorrectKey()
+        throws Exception
+    {
+        wagon.setKnownHostsProvider( okHostsProvider );
+
+        wagon.connect( source );
+    }
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+        source =
+            new Repository( "test", "scp://" + TestData.getUserName() + "@" + TestData.getHostname()
+ "/tmp/foo" );
+
+        wagon = (AbstractSshWagon) lookup( Wagon.ROLE, "scp" );
+        wagon.setInteractive( false );
     }
 }

Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/SingleKnownHostsProviderTest.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/SingleKnownHostsProviderTest.java?view=diff&rev=477167&r1=477166&r2=477167
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/SingleKnownHostsProviderTest.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/SingleKnownHostsProviderTest.java
Mon Nov 20 05:16:22 2006
@@ -1,7 +1,5 @@
 package org.apache.maven.wagon.providers.ssh.knownhost;
 
-import org.apache.maven.wagon.providers.ssh.TestData;
-
 /*
  * Copyright 2001-2005 The Apache Software Foundation.
  *
@@ -18,6 +16,8 @@
  * limitations under the License.
  */
 
+import org.apache.maven.wagon.providers.ssh.TestData;
+
 /**
  * Unit test for <code>SingleKnownHostProvider</code>
  *
@@ -28,17 +28,18 @@
 public class SingleKnownHostsProviderTest
     extends AbstractKnownHostsProviderTest
 {
-    private final String correctKey = TestData.getHostKey();
+    private final String CORRECT_KEY = TestData.getHostKey();
 
-    private final String incorrectKey = "thisisawrongkey=";
+    private static final String CHANGED_KEY =
+        "AAAAB3NzaC1yc2EAAAABIwAAAQEA8VLKkfHl2CNqW+m0603z07dyweWzzdVGQlMPUX4z1264E7M/h+6lPKiOo+u49CL7eQVA+FtWTZoJ3oBAMABcKnHx41TnSpQUkbdR6rzyC6IG1lXiVtEjG2w7DUnxpCtVo5PaQuJobwoXv5NNL3vx03THPgcDJquLPWvGnDWhnXoEh3/6c7rprwT+PrjZ6LIT35ZCUGajoehhF151oNbFMQHllfR6EAiZIP0z0nIVI+Jiv6g+XZapumVPVYjdOfxvLKQope1H9HJamT3bDIm8mkebUB10DzQJYxFt4/0wiNH3L4jsIFn+CiW1/IQm5yyff1CUO87OqVbtp9BlaXZNmw==";
 
     protected void setUp()
         throws Exception
     {
         super.setUp();
 
-        this.host = TestData.getHostname();
-        this.okHostsProvider = new SingleKnownHostProvider( host, correctKey );
-        this.failHostsProvider = new SingleKnownHostProvider( host, incorrectKey );
+        this.okHostsProvider = new SingleKnownHostProvider( TestData.getHostname(), CORRECT_KEY
);
+        this.failHostsProvider = new SingleKnownHostProvider( "beaver.codehaus.org", CORRECT_KEY
);
+        this.changedHostsProvider = new SingleKnownHostProvider( TestData.getHostname(),
CHANGED_KEY );
     }
 }

Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/StreamKnownHostsProviderTest.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/StreamKnownHostsProviderTest.java?view=diff&rev=477167&r1=477166&r2=477167
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/StreamKnownHostsProviderTest.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/StreamKnownHostsProviderTest.java
Mon Nov 20 05:16:22 2006
@@ -16,8 +16,11 @@
  * limitations under the License.
  */
 
-import java.io.InputStream;
+import org.apache.maven.wagon.providers.ssh.TestData;
+import org.codehaus.plexus.util.StringInputStream;
+
 import java.io.IOException;
+import java.io.InputStream;
 
 /**
  * Unit test for <code>StreamKnownHostsProviderTest</code>
@@ -34,9 +37,10 @@
     {
         super.setUp();
 
-        host = "beaver.codehaus.org";
-        okHostsProvider = getProvider( "ok.knownhosts" );
+        okHostsProvider = new StreamKnownHostsProvider(
+            new StringInputStream( TestData.getHostname() + " ssh-rsa " + TestData.getHostKey()
+ "\n" ) );
         failHostsProvider = getProvider( "fail.knownhosts" );
+        changedHostsProvider = getProvider( "changed.knownhosts" );
     }
 
     private StreamKnownHostsProvider getProvider( String s )

Added: maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/resources/org/apache/maven/wagon/providers/ssh/knownhost/changed.knownhosts
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/resources/org/apache/maven/wagon/providers/ssh/knownhost/changed.knownhosts?view=auto&rev=477167
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/resources/org/apache/maven/wagon/providers/ssh/knownhost/changed.knownhosts
(added)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/resources/org/apache/maven/wagon/providers/ssh/knownhost/changed.knownhosts
Mon Nov 20 05:16:22 2006
@@ -0,0 +1 @@
+localhost ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA8VLKkfHl2CNqW+m0603z07dyweWzzdVGQlMPUX4z1264E7M/h+6lPKiOo+u49CL7eQVA+FtWTZoJ3oBAMABcKnHx41TnSpQUkbdR6rzyC6IG1lXiVtEjG2w7DUnxpCtVo5PaQuJobwoXv5NNL3vx03THPgcDJquLPWvGnDWhnXoEh3/6c7rprwT+PrjZ6LIT35ZCUGajoehhF151oNbFMQHllfR6EAiZIP0z0nIVI+Jiv6g+XZapumVPVYjdOfxvLKQope1H9HJamT3bDIm8mkebUB10DzQJYxFt4/0wiNH3L4jsIFn+CiW1/IQm5yyff1CUO87OqVbtp9BlaXZNmw==

Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/resources/org/apache/maven/wagon/providers/ssh/knownhost/fail.knownhosts
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/resources/org/apache/maven/wagon/providers/ssh/knownhost/fail.knownhosts?view=diff&rev=477167&r1=477166&r2=477167
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/resources/org/apache/maven/wagon/providers/ssh/knownhost/fail.knownhosts
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/resources/org/apache/maven/wagon/providers/ssh/knownhost/fail.knownhosts
Mon Nov 20 05:16:22 2006
@@ -1 +1 @@
-beaver.codehaus.org,64.7.141.17 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAwps9EL+UKFG6Fb9spvV6YSOiyLFwVGAgtyQ5r6xdADZRw0AdcCE87uwlVgUgMjGm0D/kifVEYFZu1DQUaKfg+6B3LEz7Dgq5Ir8eJJXq62mIVqHnXKPOqGIp1TPrtc2BMhSHk5z+4puun6Nbi0hw+g7b0/ywHVbs+7wb01SMREU=
\ No newline at end of file
+beaver.codehaus.org ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAwps9EL+UKFG6Fb9spvV6YSOiyLFwVGAgtyQ5r6xdADZRw0AdcCE87uwlVgUgMjGm0D/kifVEYFZu1DQUaKfg+6B3LEz7Dgq5Ir8eJJXq62mIVqHnXKPOqGIp1TPrtc2BMhSHk5z+4puun6Nbi0hw+g7b0/ywHVbs+7wb01SMREU=



---------------------------------------------------------------------
To unsubscribe, e-mail: wagon-commits-unsubscribe@maven.apache.org
For additional commands, e-mail: wagon-commits-help@maven.apache.org


Mime
View raw message