View Javadoc
1   package org.apache.maven.wagon.providers.ssh.jsch;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.io.IOException;
24  
25  import org.apache.maven.wagon.ConnectionException;
26  import org.apache.maven.wagon.StreamingWagonTestCase;
27  import org.apache.maven.wagon.authentication.AuthenticationException;
28  import org.apache.maven.wagon.authentication.AuthenticationInfo;
29  import org.apache.maven.wagon.providers.ssh.TestData;
30  import org.apache.maven.wagon.repository.Repository;
31  import org.apache.maven.wagon.resource.Resource;
32  
33  /**
34   * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
35   *
36   */
37  public class ScpWagonWithSshPrivateKeySearchTest
38      extends StreamingWagonTestCase
39  {
40      protected String getProtocol()
41      {
42          return "scp";
43      }
44  
45      public String getTestRepositoryUrl()
46      {
47          return TestData.getTestRepositoryUrl(0);
48      }
49  
50      protected AuthenticationInfo getAuthInfo()
51      {
52          AuthenticationInfo authInfo = super.getAuthInfo();
53  
54          authInfo.setUserName( TestData.getUserName() );
55  
56          authInfo.setPassphrase( "" );
57  
58          return authInfo;
59      }
60  
61      protected long getExpectedLastModifiedOnGet( Repository repository, Resource resource )
62      {
63          return new File( repository.getBasedir(), resource.getName() ).lastModified();
64      }
65  
66      public void testMissingPrivateKey()
67          throws Exception
68      {
69          File file = File.createTempFile( "wagon", "tmp" );
70          file.delete();
71  
72          AuthenticationInfo authInfo = new AuthenticationInfo();
73          authInfo.setPrivateKey( file.getAbsolutePath() );
74  
75          try
76          {
77              getWagon().connect( new Repository(), authInfo );
78              fail();
79          }
80          catch ( AuthenticationException e )
81          {
82              assertTrue( true );
83          }
84      }
85  
86      public void testBadPrivateKey()
87          throws Exception
88      {
89          File file = File.createTempFile( "wagon", "tmp" );
90          file.deleteOnExit();
91  
92          AuthenticationInfo authInfo = new AuthenticationInfo();
93          authInfo.setPrivateKey( file.getAbsolutePath() );
94  
95          try
96          {
97              getWagon().connect( new Repository(), authInfo );
98              fail();
99          }
100         catch ( AuthenticationException e )
101         {
102             assertTrue( true );
103         }
104         finally
105         {
106             file.delete();
107         }
108     }
109 }