maven-wagon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brett Porter <br...@apache.org>
Subject Re: svn commit: r730869 - in /maven/wagon/trunk/wagon-providers/wagon-ssh-common/src: main/java/org/apache/maven/wagon/providers/ssh/knownhost/ test/java/org/apache/maven/wagon/providers/ssh/knownhost/ test/resources/
Date Mon, 05 Jan 2009 02:32:39 GMT
This seems to have broken the unit tests... are they working for you?

- Brett

On 03/01/2009, at 10:35 AM, dantran@apache.org wrote:

> Author: dantran
> Date: Fri Jan  2 15:35:51 2009
> New Revision: 730869
>
> URL: http://svn.apache.org/viewvc?rev=730869&view=rev
> Log:
> WAGON-254: rewritten known_hosts file only if its contents are changed
>
> Added:
>    maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/main/java/ 
> org/apache/maven/wagon/providers/ssh/knownhost/KnownHostEntry.java
>    maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/test/java/ 
> org/apache/maven/wagon/providers/ssh/knownhost/
>    maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/test/java/ 
> org/apache/maven/wagon/providers/ssh/knownhost/ 
> FileKnownHostsProviderTest.java
>    maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/test/ 
> resources/
>    maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/test/ 
> resources/known_hosts
>    maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/test/ 
> resources/known_hosts_same
> Modified:
>    maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/main/java/ 
> org/apache/maven/wagon/providers/ssh/knownhost/ 
> AbstractKnownHostsProvider.java
>    maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/main/java/ 
> org/apache/maven/wagon/providers/ssh/knownhost/ 
> FileKnownHostsProvider.java
>    maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/main/java/ 
> org/apache/maven/wagon/providers/ssh/knownhost/ 
> StreamKnownHostsProvider.java
>
> Modified: maven/wagon/trunk/wagon-providers/wagon-ssh-common/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-common/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/AbstractKnownHostsProvider.java?rev=730869&r1=730868&r2=730869&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/main/java/ 
> org/apache/maven/wagon/providers/ssh/knownhost/ 
> AbstractKnownHostsProvider.java (original)
> +++ maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/main/java/ 
> org/apache/maven/wagon/providers/ssh/knownhost/ 
> AbstractKnownHostsProvider.java Fri Jan  2 15:35:51 2009
> @@ -20,6 +20,8 @@
>  */
>
> import java.io.IOException;
> +import java.util.HashSet;
> +import java.util.Set;
>
> /**
>  * Common base for known hosts providers.
> @@ -41,6 +43,8 @@
>      * the known hosts, in the openssh format
>      */
>     protected String contents;
> +
> +    protected Set knownHosts = new HashSet();
>
>     public void setHostKeyChecking( String hostKeyChecking )
>     {
> @@ -56,14 +60,11 @@
>     {
>         return contents;
>     }
> -
> -    public void setContents( String contents )
> -    {
> -        this.contents = contents;
> -    }
>
>     public void storeKnownHosts( String contents )
>         throws IOException
>     {
>     }
> +
> +
> }
>
> Modified: maven/wagon/trunk/wagon-providers/wagon-ssh-common/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-common/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/FileKnownHostsProvider.java?rev=730869&r1=730868&r2=730869&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/main/java/ 
> org/apache/maven/wagon/providers/ssh/knownhost/ 
> FileKnownHostsProvider.java (original)
> +++ maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/main/java/ 
> org/apache/maven/wagon/providers/ssh/knownhost/ 
> FileKnownHostsProvider.java Fri Jan  2 15:35:51 2009
> @@ -19,13 +19,14 @@
>  * under the License.
>  */
>
> -import org.codehaus.plexus.util.FileUtils;
> -
> import java.io.ByteArrayInputStream;
> import java.io.File;
> import java.io.FileInputStream;
> import java.io.IOException;
> import java.io.InputStream;
> +import java.util.Set;
> +
> +import org.codehaus.plexus.util.FileUtils;
>
> /**
>  * Provides known hosts from a file
> @@ -70,10 +71,16 @@
>     public void storeKnownHosts( String contents )
>         throws IOException
>     {
> -        file.getParentFile().mkdirs();
> -        FileUtils.fileWrite( file.getAbsolutePath(), contents );
> +        Set hosts = this.loadKnownHosts( contents );
> +
> +        if ( ! this.knownHosts.equals( hosts ) )
> +        {
> +            file.getParentFile().mkdirs();
> +            FileUtils.fileWrite( file.getAbsolutePath(), contents );
> +            this.knownHosts = hosts;
> +        }
>     }
> -
> +
>     public File getFile()
>     {
>         return file;
>
> Added: maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/main/ 
> java/org/apache/maven/wagon/providers/ssh/knownhost/ 
> KnownHostEntry.java
> URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/KnownHostEntry.java?rev=730869&view=auto
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/main/java/ 
> org/apache/maven/wagon/providers/ssh/knownhost/KnownHostEntry.java  
> (added)
> +++ maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/main/java/ 
> org/apache/maven/wagon/providers/ssh/knownhost/KnownHostEntry.java  
> Fri Jan  2 15:35:51 2009
> @@ -0,0 +1,97 @@
> +package org.apache.maven.wagon.providers.ssh.knownhost;
> +
> +public class KnownHostEntry
> +{
> +
> +    private String hostName;
> +
> +    private String keyType;
> +
> +    private String keyValue;
> +
> +    public KnownHostEntry()
> +    {
> +
> +    }
> +
> +    public KnownHostEntry( String hostName, String keyType, String  
> keyValue )
> +    {
> +        this.hostName = hostName;
> +        this.keyType = keyType;
> +        this.keyValue = keyValue;
> +    }
> +
> +    public String getHostName()
> +    {
> +        return hostName;
> +    }
> +
> +    public void setHostName( String hostName )
> +    {
> +        this.hostName = hostName;
> +    }
> +
> +    public String getKeyType()
> +    {
> +        return keyType;
> +    }
> +
> +    public void setKeyType( String keyType )
> +    {
> +        this.keyType = keyType;
> +    }
> +
> +    public String getKeyValue()
> +    {
> +        return keyValue;
> +    }
> +
> +    public void setKeyValue( String keyValue )
> +    {
> +        this.keyValue = keyValue;
> +    }
> +
> +    public int hashCode()
> +    {
> +        final int prime = 31;
> +        int result = 1;
> +        result = prime * result + ( ( hostName == null ) ? 0 :  
> hostName.hashCode() );
> +        result = prime * result + ( ( keyType == null ) ? 0 :  
> keyType.hashCode() );
> +        result = prime * result + ( ( keyValue == null ) ? 0 :  
> keyValue.hashCode() );
> +        return result;
> +    }
> +
> +    public boolean equals( Object obj )
> +    {
> +        if ( this == obj )
> +            return true;
> +        if ( obj == null )
> +            return false;
> +        if ( getClass() != obj.getClass() )
> +            return false;
> +        KnownHostEntry other = (KnownHostEntry) obj;
> +        if ( hostName == null )
> +        {
> +            if ( other.hostName != null )
> +                return false;
> +        }
> +        else if ( !hostName.equals( other.hostName ) )
> +            return false;
> +        if ( keyType == null )
> +        {
> +            if ( other.keyType != null )
> +                return false;
> +        }
> +        else if ( !keyType.equals( other.keyType ) )
> +            return false;
> +        if ( keyValue == null )
> +        {
> +            if ( other.keyValue != null )
> +                return false;
> +        }
> +        else if ( !keyValue.equals( other.keyValue ) )
> +            return false;
> +        return true;
> +    }
> +
> +}
>
> Modified: maven/wagon/trunk/wagon-providers/wagon-ssh-common/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-common/src/main/java/org/apache/maven/wagon/providers/ssh/knownhost/StreamKnownHostsProvider.java?rev=730869&r1=730868&r2=730869&view=diff
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/main/java/ 
> org/apache/maven/wagon/providers/ssh/knownhost/ 
> StreamKnownHostsProvider.java (original)
> +++ maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/main/java/ 
> org/apache/maven/wagon/providers/ssh/knownhost/ 
> StreamKnownHostsProvider.java Fri Jan  2 15:35:51 2009
> @@ -19,11 +19,16 @@
>  * under the License.
>  */
>
> -import org.codehaus.plexus.util.IOUtil;
> -import org.codehaus.plexus.util.StringOutputStream;
> -
> +import java.io.BufferedReader;
> import java.io.IOException;
> import java.io.InputStream;
> +import java.io.StringReader;
> +import java.util.HashSet;
> +import java.util.Set;
> +
> +import org.codehaus.plexus.util.IOUtil;
> +import org.codehaus.plexus.util.StringOutputStream;
> +import org.codehaus.plexus.util.StringUtils;
>
> /**
>  * Provides known hosts from a file
> @@ -43,10 +48,38 @@
>             StringOutputStream stringOutputStream = new  
> StringOutputStream();
>             IOUtil.copy( stream, stringOutputStream );
>             this.contents = stringOutputStream.toString();
> +
> +            this.knownHosts = this.loadKnownHosts( this.contents );
>         }
>         finally
>         {
>             IOUtil.close( stream );
>         }
>     }
> +
> +    protected Set loadKnownHosts( String contents )
> +        throws IOException
> +    {
> +        Set hosts = new HashSet();
> +
> +        BufferedReader br = new BufferedReader( new  
> StringReader( contents ) );
> +
> +        String line = null;
> +
> +        do
> +        {
> +            line = br.readLine();
> +            if ( line != null )
> +            {
> +                String tokens[] = StringUtils.split( line );
> +                if ( tokens.length == 3 )
> +                {
> +                    hosts.add( new KnownHostEntry( tokens[0],  
> tokens[1], tokens[2] ) );
> +                }
> +            }
> +
> +        }while ( line != null );
> +
> +        return hosts;
> +    }
> }
>
> Added: maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/test/ 
> java/org/apache/maven/wagon/providers/ssh/knownhost/ 
> FileKnownHostsProviderTest.java
> URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/test/java/org/apache/maven/wagon/providers/ssh/knownhost/FileKnownHostsProviderTest.java?rev=730869&view=auto
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/test/java/ 
> org/apache/maven/wagon/providers/ssh/knownhost/ 
> FileKnownHostsProviderTest.java (added)
> +++ maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/test/java/ 
> org/apache/maven/wagon/providers/ssh/knownhost/ 
> FileKnownHostsProviderTest.java Fri Jan  2 15:35:51 2009
> @@ -0,0 +1,57 @@
> +package org.apache.maven.wagon.providers.ssh.knownhost;
> +
> +import java.io.File;
> +
> +import org.codehaus.plexus.util.FileUtils;
> +
> +import junit.framework.TestCase;
> +
> +public class FileKnownHostsProviderTest
> +    extends TestCase
> +{
> +    private File basedir = new File( System.getProperty( "basedir",  
> "." ) );
> +
> +    private File testKnownHostsFile;
> +
> +
> +    private FileKnownHostsProvider provider;
> +
> +    public void setUp()
> +        throws Exception
> +    {
> +        File readonlyKnownHostFile = new File( basedir, "src/test/ 
> resources/known_hosts" );
> +        testKnownHostsFile = new File( basedir, "target/ 
> known_hosts" );
> +        testKnownHostsFile.delete();
> +        FileUtils.copyFile( readonlyKnownHostFile,  
> testKnownHostsFile );
> +
> +        provider = new FileKnownHostsProvider( testKnownHostsFile );
> +
> +    }
> +
> +    public void testStoreKnownHostsNoChange()
> +        throws Exception
> +    {
> +        long timestamp = this.testKnownHostsFile.lastModified();
> +        //file with the same contents, but with entries swapped
> +        File sameKnownHostFile = new File( basedir, "src/test/ 
> resources/known_hosts_same" );
> +        String contents = FileUtils.fileRead( sameKnownHostFile );
> +
> +        Thread.sleep( 50 );
> +        provider.storeKnownHosts( contents );
> +        assertEquals( "known_hosts file is rewritten", timestamp,  
> testKnownHostsFile.lastModified() );
> +    }
> +
> +    public void testStoreKnownHostsWithChange()
> +        throws Exception
> +    {
> +        long timestamp = this.testKnownHostsFile.lastModified();
> +        File sameKnownHostFile = new File( basedir, "src/test/ 
> resources/known_hosts_same" );
> +        String contents = FileUtils.fileRead( sameKnownHostFile );
> +        contents += "1 2 3";
> +
> +        Thread.sleep( 50 );
> +        provider.storeKnownHosts( contents );
> +        assertTrue( "known_hosts file is not rewritten", timestamp ! 
> = testKnownHostsFile.lastModified() );
> +    }
> +
> +}
>
> Added: maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/test/ 
> resources/known_hosts
> URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/test/resources/known_hosts?rev=730869&view=auto
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/test/ 
> resources/known_hosts (added)
> +++ maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/test/ 
> resources/known_hosts Fri Jan  2 15:35:51 2009
> @@ -0,0 +1,2 @@
> +server,192.168.0.10 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAtnWEbH/ 
> WTZG2aAl9gX8HtMqXidzQXgluARIOijWigbvA4/3N4fnNmckXBUHR32iqHQM/ 
> ySIRhc9EVDanDy0JyKdm738PwP0DbWGqiIDTtukbju4DAtXtOx3LgIqHc0PD+cquO9Ut/ 
> 68o6/GdBgN18nVOMt+8Q9Vr1VSFqfHoLEx04NI+4BbGaGKQOFU25VJ3KtM0zkoyDfu0/ 
> MDusVoFIDVb0KtfxZVEDRmEFnySpFHOBdSdODsunftYccCNTNdsh 
> + 
> 58jSqChUUlP3B0bTykm7o52CrXCMWCsLzH6dDkN7GUQwLvjPG04gedeZg6tEN8vTInRmHQrp0TTW7JGNjXgw

> ==
> +192.168.0.11 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAtnWEbH/ 
> WTZG2aAl9gX8HtMqXidzQXgluARIOijWigbvA4/3N4fnNmckXBUHR32iqHQM/ 
> ySIRhc9EVDanDy0JyKdm738PwP0DbWGqiIDTtukbju4DAtXtOx3LgIqHc0PD+cquO9Ut/ 
> 68o6/GdBgN18nVOMt+8Q9Vr1VSFqfHoLEx04NI+4BbGaGKQOFU25VJ3KtM0zkoyDfu0/ 
> MDusVoFIDVb0KtfxZVEDRmEFnySpFHOBdSdODsunftYccCNTNdsh 
> + 
> 58jSqChUUlP3B0bTykm7o52CrXCMWCsLzH6dDkN7GUQwLvjPG04gedeZg6tEN8vTInRmHQrp0TTW7JGNjXgw

> ==
>
> Added: maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/test/ 
> resources/known_hosts_same
> URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/test/resources/known_hosts_same?rev=730869&view=auto
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/test/ 
> resources/known_hosts_same (added)
> +++ maven/wagon/trunk/wagon-providers/wagon-ssh-common/src/test/ 
> resources/known_hosts_same Fri Jan  2 15:35:51 2009
> @@ -0,0 +1,2 @@
> +192.168.0.11 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAtnWEbH/ 
> WTZG2aAl9gX8HtMqXidzQXgluARIOijWigbvA4/3N4fnNmckXBUHR32iqHQM/ 
> ySIRhc9EVDanDy0JyKdm738PwP0DbWGqiIDTtukbju4DAtXtOx3LgIqHc0PD+cquO9Ut/ 
> 68o6/GdBgN18nVOMt+8Q9Vr1VSFqfHoLEx04NI+4BbGaGKQOFU25VJ3KtM0zkoyDfu0/ 
> MDusVoFIDVb0KtfxZVEDRmEFnySpFHOBdSdODsunftYccCNTNdsh 
> + 
> 58jSqChUUlP3B0bTykm7o52CrXCMWCsLzH6dDkN7GUQwLvjPG04gedeZg6tEN8vTInRmHQrp0TTW7JGNjXgw

> ==
> +server,192.168.0.10 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAtnWEbH/ 
> WTZG2aAl9gX8HtMqXidzQXgluARIOijWigbvA4/3N4fnNmckXBUHR32iqHQM/ 
> ySIRhc9EVDanDy0JyKdm738PwP0DbWGqiIDTtukbju4DAtXtOx3LgIqHc0PD+cquO9Ut/ 
> 68o6/GdBgN18nVOMt+8Q9Vr1VSFqfHoLEx04NI+4BbGaGKQOFU25VJ3KtM0zkoyDfu0/ 
> MDusVoFIDVb0KtfxZVEDRmEFnySpFHOBdSdODsunftYccCNTNdsh 
> + 
> 58jSqChUUlP3B0bTykm7o52CrXCMWCsLzH6dDkN7GUQwLvjPG04gedeZg6tEN8vTInRmHQrp0TTW7JGNjXgw

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

--
Brett Porter
brett@apache.org
http://blogs.exist.com/bporter/


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


Mime
View raw message