View Javadoc

1   /*
2    * $Id: SftpNoWriteAccessToOutboundDirectoryTestCase.java 22475 2011-07-20 14:30:04Z justin.calleja $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transport.sftp.dataintegrity;
12  
13  import static org.junit.Assert.assertEquals;
14  import static org.junit.Assert.assertNotNull;
15  import static org.junit.Assert.assertTrue;
16  
17  import java.io.IOException;
18  import java.util.Arrays;
19  import java.util.Collection;
20  
21  import org.junit.Test;
22  import org.junit.runners.Parameterized.Parameters;
23  import org.mule.api.transport.DispatchException;
24  import org.mule.module.client.MuleClient;
25  import org.mule.transport.sftp.SftpClient;
26  
27  /**
28   * Verify that the original file is not lost if the outbound directory doesn't exist
29   */
30  public class SftpNoWriteAccessToOutboundDirectoryTestCase extends AbstractSftpDataIntegrityTestCase
31  {
32      private static final String OUTBOUND_ENDPOINT_NAME = "outboundEndpoint";
33      private static final String INBOUND_ENDPOINT_NAME = "inboundEndpoint";
34  
35      public SftpNoWriteAccessToOutboundDirectoryTestCase(ConfigVariant variant, String configResources)
36      {
37          super(variant, configResources);
38      }
39  
40      @Parameters
41      public static Collection<Object[]> parameters()
42      {
43          return Arrays.asList(new Object[][]{
44              {ConfigVariant.SERVICE, "dataintegrity/sftp-dataintegrity-common-config-service.xml"},
45              {ConfigVariant.FLOW, "dataintegrity/sftp-dataintegrity-common-config-flow.xml"}});
46      }
47  
48      @Override
49      protected void doSetUp() throws Exception
50      {
51          super.doSetUp();
52  
53          // Delete the in & outbound directories
54          initEndpointDirectory(INBOUND_ENDPOINT_NAME);
55          initEndpointDirectory(OUTBOUND_ENDPOINT_NAME);
56      }
57  
58      /** No write access on the outbound directory. The source file should still exist */
59      @Test
60      public void testNoWriteAccessToOutboundDirectory() throws Exception
61      {
62          MuleClient muleClient = new MuleClient(muleContext);
63  
64          SftpClient sftpClient = getSftpClient(muleClient, OUTBOUND_ENDPOINT_NAME);
65  
66          try
67          {
68              // change the chmod to "dr-x------" on the outbound-directory
69              remoteChmod(muleClient, sftpClient, OUTBOUND_ENDPOINT_NAME, 00500);
70  
71              // Send an file to the SFTP server, which the inbound-outboundEndpoint
72              // then can pick up
73              Exception exception = dispatchAndWaitForException(new DispatchParameters(INBOUND_ENDPOINT_NAME,
74                  OUTBOUND_ENDPOINT_NAME), "sftp", "service");
75              assertNotNull(exception);
76              assertTrue("expected DispatchException, but got : " + exception.getClass().toString(),
77                  exception instanceof DispatchException);
78              assertTrue("expected IOException, but got : " + exception.getCause().getClass().toString(),
79                  exception.getCause() instanceof IOException);
80              assertEquals("Permission denied", exception.getCause().getMessage());
81  
82              verifyInAndOutFiles(muleClient, INBOUND_ENDPOINT_NAME, OUTBOUND_ENDPOINT_NAME, true, false);
83          }
84          finally
85          {
86              sftpClient.disconnect();
87          }
88      }
89  
90  }