1
2
3
4
5
6
7 package org.mule.module.acegi;
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 return "encryption-test.xml";
27 }
28
29 @Test
30 public void testAuthenticationFailureNoContext() throws Exception
31 {
32 MuleClient client = new MuleClient(muleContext);
33 MuleMessage m = client.send("http://localhost:4567/index.html", "", null);
34 assertNotNull(m);
35 int status = m.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, -1);
36 assertEquals(HttpConstants.SC_UNAUTHORIZED, status);
37 }
38
39 @Test
40 public void testAuthenticationFailureBadCredentials() throws Exception
41 {
42 MuleClient client = new MuleClient("anonX", "anonX");
43 MuleMessage m = client.send("http://localhost:4567/index.html", "", null);
44 assertNotNull(m);
45 int status = m.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, -1);
46 assertEquals(HttpConstants.SC_UNAUTHORIZED, status);
47 }
48
49 @Test
50 public void testAuthenticationAuthorised() throws Exception
51 {
52 MuleClient client = new MuleClient("anon", "anon");
53 MuleMessage m = client.send("http://localhost:4567/index.html", "", null);
54 assertNotNull(m);
55 int status = m.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, -1);
56 assertEquals(HttpConstants.SC_OK, status);
57 }
58
59 }