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.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          // Note that this file contains global attributes, which the configuration-building
27          // process will ignore (MULE-5375)
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  }