1
2
3
4
5
6
7
8
9
10
11 package org.mule.module.spring.security;
12
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertNotNull;
15
16 import org.mule.api.MuleMessage;
17 import org.mule.module.client.MuleClient;
18 import org.mule.tck.AbstractServiceAndFlowTestCase;
19 import org.mule.tck.AbstractServiceAndFlowTestCase.ConfigVariant;
20 import org.mule.transport.http.HttpConnector;
21 import org.mule.transport.http.HttpConstants;
22
23 import java.util.Arrays;
24 import java.util.Collection;
25
26 import org.junit.Test;
27 import org.junit.runners.Parameterized.Parameters;
28
29 public class PlainTextFunctionalTestCase extends AbstractServiceAndFlowTestCase
30 {
31 public PlainTextFunctionalTestCase(ConfigVariant variant, String configResources)
32 {
33 super(variant, configResources);
34 }
35
36 @Parameters
37 public static Collection<Object[]> parameters()
38 {
39
40
41 return Arrays.asList(new Object[][]{
42 {ConfigVariant.SERVICE, "encryption-test-service.xml"},
43 {ConfigVariant.FLOW, "encryption-test-flow.xml"}
44 });
45 }
46
47 @Test
48 public void testAuthenticationFailureNoContext() throws Exception
49 {
50 MuleClient client = new MuleClient(muleContext);
51 MuleMessage m = client.send("http://localhost:4567/index.html", "", null);
52 assertNotNull(m);
53 int status = m.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, -1);
54 assertEquals(HttpConstants.SC_UNAUTHORIZED, status);
55 }
56
57 @Test
58 public void testAuthenticationFailureBadCredentials() throws Exception
59 {
60 MuleClient client = new MuleClient("anonX", "anonX");
61 MuleMessage m = client.send("http://localhost:4567/index.html", "", null);
62 assertNotNull(m);
63 int status = m.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, -1);
64 assertEquals(HttpConstants.SC_UNAUTHORIZED, status);
65 }
66
67 @Test
68 public void testAuthenticationAuthorised() throws Exception
69 {
70 MuleClient client = new MuleClient("anon", "anon");
71 MuleMessage m = client.send("http://localhost:4567/index.html", "", null);
72 assertNotNull(m);
73 int status = m.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, -1);
74 assertEquals(HttpConstants.SC_OK, status);
75 }
76
77 }