Author: markt Date: Tue Jun 18 13:17:07 2013 New Revision: 1494133 URL: http://svn.apache.org/r1494133 Log: Add a simple realm test in preparation for additional tests for Servlet 3.1 changes
Added: tomcat/trunk/test/org/apache/catalina/connector/TesterResponse.java (with props) tomcat/trunk/test/org/apache/catalina/realm/ tomcat/trunk/test/org/apache/catalina/realm/TestRealmBase.java (with props) Added: tomcat/trunk/test/org/apache/catalina/connector/TesterResponse.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/connector/TesterResponse.java?rev=1494133&view=auto ============================================================================== --- tomcat/trunk/test/org/apache/catalina/connector/TesterResponse.java (added) +++ tomcat/trunk/test/org/apache/catalina/connector/TesterResponse.java Tue Jun 18 13:17:07 2013 @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.connector; + +import java.io.IOException; + +/** + * Minimal changes to Response to enable tests that use this class to operate + * correctly. + */ +public class TesterResponse extends Response { + + @Override + public boolean isCommitted() { + return false; + } + + @Override + public void sendError(int status, String message) throws IOException { + System.out.println("TesterResponse.sendError(" + status + ", \"" + + message + "\")"); + } +} Propchange: tomcat/trunk/test/org/apache/catalina/connector/TesterResponse.java ------------------------------------------------------------------------------ svn:eol-style = native Added: tomcat/trunk/test/org/apache/catalina/realm/TestRealmBase.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/realm/TestRealmBase.java?rev=1494133&view=auto ============================================================================== --- tomcat/trunk/test/org/apache/catalina/realm/TestRealmBase.java (added) +++ tomcat/trunk/test/org/apache/catalina/realm/TestRealmBase.java Tue Jun 18 13:17:07 2013 @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.catalina.realm; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; + +import org.apache.catalina.connector.Request; +import org.apache.catalina.connector.Response; +import org.apache.catalina.connector.TesterResponse; +import org.apache.catalina.deploy.SecurityCollection; +import org.apache.catalina.deploy.SecurityConstraint; +import org.apache.catalina.startup.TesterMapRealm; + +public class TestRealmBase { + + private static final String USER1 = "user1"; + private static final String PWD1 = "password1"; + private static final String ROLE1 = "role1"; + + @Test + public void testSingleRole() throws Exception { + // Configure the users in the Realm + TesterMapRealm mapRealm = new TesterMapRealm(); + mapRealm.addUser("user", ROLE1); + + // Configure the security constraints for the resourc + SecurityConstraint constraint = new SecurityConstraint(); + constraint.addAuthRole(ROLE1); + SecurityCollection collection = new SecurityCollection(); + collection.addPattern("/*"); + SecurityConstraint[] constraints = + new SecurityConstraint[] {constraint}; + + // Set up the mock request and response + Request request = new Request(); + Response response = new TesterResponse(); + + // Set up an authenticated user + List<String> userRoles = new ArrayList<>(); + userRoles.add(ROLE1); + GenericPrincipal gp = new GenericPrincipal(USER1, PWD1, userRoles); + request.setUserPrincipal(gp); + + boolean result = mapRealm.hasResourcePermission( + request, response, constraints, null); + + Assert.assertTrue(result); + } +} Propchange: tomcat/trunk/test/org/apache/catalina/realm/TestRealmBase.java ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org