1
2
3
4
5
6
7 package org.mule.module.spring.security;
8
9 import org.mule.api.MuleMessage;
10 import org.mule.module.client.MuleClient;
11 import org.mule.tck.junit4.FunctionalTestCase;
12 import org.mule.transport.http.HttpConnector;
13 import org.mule.transport.http.HttpConstants;
14
15 import org.junit.Test;
16
17 import static org.junit.Assert.assertEquals;
18 import static org.junit.Assert.assertNotNull;
19
20 public class PlainTextFunctionalTestCase extends FunctionalTestCase
21 {
22
23 @Override
24 protected String getConfigResources()
25 {
26
27
28 return "encryption-test.xml";
29 }
30
31 @Test
32 public void testAuthenticationFailureNoContext() throws Exception
33 {
34 MuleClient client = new MuleClient(muleContext);
35 MuleMessage m = client.send("http://localhost:4567/index.html", "", null);
36 assertNotNull(m);
37 int status = m.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, -1);
38 assertEquals(HttpConstants.SC_UNAUTHORIZED, status);
39 }
40
41 @Test
42 public void testAuthenticationFailureBadCredentials() throws Exception
43 {
44 MuleClient client = new MuleClient("anonX", "anonX");
45 MuleMessage m = client.send("http://localhost:4567/index.html", "", null);
46 assertNotNull(m);
47 int status = m.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, -1);
48 assertEquals(HttpConstants.SC_UNAUTHORIZED, status);
49 }
50
51 @Test
52 public void testAuthenticationAuthorised() throws Exception
53 {
54 MuleClient client = new MuleClient("anon", "anon");
55 MuleMessage m = client.send("http://localhost:4567/index.html", "", null);
56 assertNotNull(m);
57 int status = m.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, -1);
58 assertEquals(HttpConstants.SC_OK, status);
59 }
60
61 }