|
| 1 | +/* |
| 2 | + * Copyright 2011 <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a> |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.ocpsoft.rewrite.servlet.container; |
| 17 | + |
| 18 | +import junit.framework.Assert; |
| 19 | + |
| 20 | +import org.apache.http.client.methods.HttpGet; |
| 21 | +import org.jboss.arquillian.container.test.api.Deployment; |
| 22 | +import org.jboss.arquillian.junit.Arquillian; |
| 23 | +import org.jboss.shrinkwrap.api.spec.WebArchive; |
| 24 | +import org.junit.Test; |
| 25 | +import org.junit.runner.RunWith; |
| 26 | +import org.ocpsoft.rewrite.config.ConfigurationProvider; |
| 27 | +import org.ocpsoft.rewrite.servlet.ServletRoot; |
| 28 | +import org.ocpsoft.rewrite.test.HttpAction; |
| 29 | +import org.ocpsoft.rewrite.test.RewriteTest; |
| 30 | + |
| 31 | +/** |
| 32 | + * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a> |
| 33 | + */ |
| 34 | +@RunWith(Arquillian.class) |
| 35 | +public class ContainerSecurityTest extends RewriteTest |
| 36 | +{ |
| 37 | + @Deployment(testable = false) |
| 38 | + public static WebArchive getDeployment() |
| 39 | + { |
| 40 | + WebArchive deployment = RewriteTest.getDeployment() |
| 41 | + .addPackages(true, ServletRoot.class.getPackage()) |
| 42 | + .addAsWebInfResource("org/ocpsoft/rewrite/servlet/container/web.xml") |
| 43 | + .addAsWebResource("org/ocpsoft/rewrite/servlet/container/login.html") |
| 44 | + .addAsWebResource("org/ocpsoft/rewrite/servlet/container/login-fail.html") |
| 45 | + .addAsWebResource("org/ocpsoft/rewrite/servlet/container/home.html", "/user/home.html") |
| 46 | + .addAsServiceProvider(ConfigurationProvider.class, ContainerSecurityTestProvider.class); |
| 47 | + |
| 48 | + System.out.println(deployment.toString(true)); |
| 49 | + |
| 50 | + return deployment; |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + public void testContainerSecurityFunctionsWithRewriteJoin() throws Exception |
| 55 | + { |
| 56 | + HttpAction<HttpGet> action = get("/user/home"); |
| 57 | + Assert.assertEquals(200, action.getResponse().getStatusLine().getStatusCode()); |
| 58 | + Assert.assertTrue(action.getResponseContent().contains("LOGIN PAGE")); |
| 59 | + } |
| 60 | + |
| 61 | + @Test |
| 62 | + public void testContainerSecurityFunctionsWithRewriteUnHandled() throws Exception |
| 63 | + { |
| 64 | + HttpAction<HttpGet> action = get("/user/x"); |
| 65 | + Assert.assertEquals(200, action.getResponse().getStatusLine().getStatusCode()); |
| 66 | + Assert.assertTrue(action.getResponseContent().contains("LOGIN PAGE")); |
| 67 | + } |
| 68 | +} |
0 commit comments