1
2
3
4
5
6
7 package org.mule.transport.sftp.dataintegrity;
8
9 import org.mule.api.transport.DispatchException;
10 import org.mule.module.client.MuleClient;
11 import org.mule.transport.sftp.SftpClient;
12
13 import java.io.IOException;
14
15 import org.junit.Test;
16
17 import static org.junit.Assert.assertEquals;
18 import static org.junit.Assert.assertNotNull;
19 import static org.junit.Assert.assertTrue;
20
21
22
23
24 public class SftpNoWriteAccessToOutboundDirectoryTestCase extends AbstractSftpDataIntegrityTestCase
25 {
26 private static final String OUTBOUND_ENDPOINT_NAME = "outboundEndpoint";
27 private static final String INBOUND_ENDPOINT_NAME = "inboundEndpoint";
28
29 @Override
30 protected String getConfigResources()
31 {
32 return "dataintegrity/sftp-dataintegrity-common-config.xml";
33 }
34
35 @Override
36 protected void doSetUp() throws Exception
37 {
38 super.doSetUp();
39
40
41 initEndpointDirectory(INBOUND_ENDPOINT_NAME);
42 initEndpointDirectory(OUTBOUND_ENDPOINT_NAME);
43 }
44
45
46 @Test
47 public void testNoWriteAccessToOutboundDirectory() throws Exception
48 {
49 MuleClient muleClient = new MuleClient(muleContext);
50
51 SftpClient sftpClient = getSftpClient(muleClient, OUTBOUND_ENDPOINT_NAME);
52
53 try
54 {
55
56 remoteChmod(muleClient, sftpClient, OUTBOUND_ENDPOINT_NAME, 00500);
57
58
59
60 Exception exception = dispatchAndWaitForException(new DispatchParameters(INBOUND_ENDPOINT_NAME,
61 OUTBOUND_ENDPOINT_NAME), "sftp", "service");
62 assertNotNull(exception);
63 assertTrue("expected DispatchException, but got : " + exception.getClass().toString(),
64 exception instanceof DispatchException);
65 assertTrue("expected IOException, but got : " + exception.getCause().getClass().toString(),
66 exception.getCause() instanceof IOException);
67 assertEquals("Permission denied", exception.getCause().getMessage());
68
69 verifyInAndOutFiles(muleClient, INBOUND_ENDPOINT_NAME, OUTBOUND_ENDPOINT_NAME, true, false);
70 }
71 finally
72 {
73 sftpClient.disconnect();
74 }
75 }
76
77 }