1
2
3
4
5
6
7
8
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
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
54 initEndpointDirectory(INBOUND_ENDPOINT_NAME);
55 initEndpointDirectory(OUTBOUND_ENDPOINT_NAME);
56 }
57
58
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
69 remoteChmod(muleClient, sftpClient, OUTBOUND_ENDPOINT_NAME, 00500);
70
71
72
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 }