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      @Override
46      protected int getTestRepositoryPort() {
47          return 0;  // not used
48      }
49  
50      public String getTestRepositoryUrl()
51      {
52          return TestData.getTestRepositoryUrl(0);
53      }
54  
55      protected AuthenticationInfo getAuthInfo()
56      {
57          AuthenticationInfo authInfo = super.getAuthInfo();
58  
59          authInfo.setUserName( TestData.getUserName() );
60  
61          authInfo.setPassphrase( "" );
62  
63          return authInfo;
64      }
65  
66      protected long getExpectedLastModifiedOnGet( Repository repository, Resource resource )
67      {
68          return new File( repository.getBasedir(), resource.getName() ).lastModified();
69      }
70  
71      public void testMissingPrivateKey()
72          throws Exception
73      {
74          File file = File.createTempFile( "wagon", "tmp" );
75          file.delete();
76  
77          AuthenticationInfo authInfo = new AuthenticationInfo();
78          authInfo.setPrivateKey( file.getAbsolutePath() );
79  
80          try
81          {
82              getWagon().connect( new Repository(), authInfo );
83              fail();
84          }
85          catch ( AuthenticationException e )
86          {
87              assertTrue( true );
88          }
89      }
90  
91      public void testBadPrivateKey()
92          throws Exception
93      {
94          File file = File.createTempFile( "wagon", "tmp" );
95          file.deleteOnExit();
96  
97          AuthenticationInfo authInfo = new AuthenticationInfo();
98          authInfo.setPrivateKey( file.getAbsolutePath() );
99  
100         try
101         {
102             getWagon().connect( new Repository(), authInfo );
103             fail();
104         }
105         catch ( AuthenticationException e )
106         {
107             assertTrue( true );
108         }
109         finally
110         {
111             file.delete();
112         }
113     }
114 }