View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
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  }