View Javadoc

1   /*
2    * $Id: PlainTextFunctionalTestCase.java 22471 2011-07-20 10:36:17Z claude.mamo $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
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          // Note that this file contains global attributes, which the configuration-building
40          // process will ignore (MULE-5375)
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  }