001: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
002: *
003: * Licensed under the Apache License, Version 2.0 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at
006: *
007: * http://www.apache.org/licenses/LICENSE-2.0
008: *
009: * Unless required by applicable law or agreed to in writing, software
010: * distributed under the License is distributed on an "AS IS" BASIS,
011: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: * See the License for the specific language governing permissions and
013: * limitations under the License.
014: */
015:
016: package org.acegisecurity.providers.cas.proxy;
017:
018: import junit.framework.TestCase;
019:
020: import org.acegisecurity.providers.cas.ProxyUntrustedException;
021:
022: import java.util.List;
023: import java.util.Vector;
024:
025: /**
026: * Tests {@link NamedCasProxyDecider}.
027: */
028: public class NamedCasProxyDeciderTests extends TestCase {
029: //~ Constructors ===================================================================================================
030:
031: public NamedCasProxyDeciderTests() {
032: super ();
033: }
034:
035: public NamedCasProxyDeciderTests(String arg0) {
036: super (arg0);
037: }
038:
039: //~ Methods ========================================================================================================
040:
041: public static void main(String[] args) {
042: junit.textui.TestRunner.run(NamedCasProxyDeciderTests.class);
043: }
044:
045: public final void setUp() throws Exception {
046: super .setUp();
047: }
048:
049: public void testAcceptsIfNearestProxyIsAuthorized()
050: throws Exception {
051: NamedCasProxyDecider proxyDecider = new NamedCasProxyDecider();
052:
053: // Build the ticket returned from CAS
054: List proxyList = new Vector();
055: proxyList
056: .add("https://localhost/newPortal/j_acegi_cas_security_check");
057:
058: // Build the list of valid nearest proxies
059: List validProxies = new Vector();
060: validProxies
061: .add("https://localhost/portal/j_acegi_cas_security_check");
062: validProxies
063: .add("https://localhost/newPortal/j_acegi_cas_security_check");
064: proxyDecider.setValidProxies(validProxies);
065: proxyDecider.afterPropertiesSet();
066:
067: proxyDecider.confirmProxyListTrusted(proxyList);
068: assertTrue(true);
069: }
070:
071: public void testAcceptsIfNoProxiesInTicket() {
072: NamedCasProxyDecider proxyDecider = new NamedCasProxyDecider();
073:
074: List proxyList = new Vector(); // no proxies in list
075:
076: proxyDecider.confirmProxyListTrusted(proxyList);
077: assertTrue(true);
078: }
079:
080: public void testDetectsMissingValidProxiesList() throws Exception {
081: NamedCasProxyDecider proxyDecider = new NamedCasProxyDecider();
082:
083: try {
084: proxyDecider.afterPropertiesSet();
085: fail("Should have thrown IllegalArgumentException");
086: } catch (IllegalArgumentException expected) {
087: assertEquals("A validProxies list must be set", expected
088: .getMessage());
089: }
090: }
091:
092: public void testDoesNotAcceptNull() {
093: NamedCasProxyDecider proxyDecider = new NamedCasProxyDecider();
094:
095: try {
096: proxyDecider.confirmProxyListTrusted(null);
097: fail("Should have thrown IllegalArgumentException");
098: } catch (IllegalArgumentException expected) {
099: assertEquals("proxyList cannot be null", expected
100: .getMessage());
101: }
102: }
103:
104: public void testGettersSetters() {
105: NamedCasProxyDecider proxyDecider = new NamedCasProxyDecider();
106:
107: // Build the list of valid nearest proxies
108: List validProxies = new Vector();
109: validProxies
110: .add("https://localhost/portal/j_acegi_cas_security_check");
111: validProxies
112: .add("https://localhost/newPortal/j_acegi_cas_security_check");
113: proxyDecider.setValidProxies(validProxies);
114:
115: assertEquals(validProxies, proxyDecider.getValidProxies());
116: }
117:
118: public void testRejectsIfNearestProxyIsNotAuthorized()
119: throws Exception {
120: NamedCasProxyDecider proxyDecider = new NamedCasProxyDecider();
121:
122: // Build the ticket returned from CAS
123: List proxyList = new Vector();
124: proxyList
125: .add("https://localhost/untrustedWebApp/j_acegi_cas_security_check");
126:
127: // Build the list of valid nearest proxies
128: List validProxies = new Vector();
129: validProxies
130: .add("https://localhost/portal/j_acegi_cas_security_check");
131: validProxies
132: .add("https://localhost/newPortal/j_acegi_cas_security_check");
133: proxyDecider.setValidProxies(validProxies);
134: proxyDecider.afterPropertiesSet();
135:
136: try {
137: proxyDecider.confirmProxyListTrusted(proxyList);
138: fail("Should have thrown ProxyUntrustedException");
139: } catch (ProxyUntrustedException expected) {
140: assertTrue(true);
141: }
142: }
143: }
|