    1   /* Copyright 2004 Acegi Technology Pty Limited
    2    *
    3    * Licensed under the Apache License, Version 2.0 (the "License");
    4    * you may not use this file except in compliance with the License.
    5    * You may obtain a copy of the License at
    6    *
    7    *     http://www.apache.org/licenses/LICENSE-2.0
    8    *
    9    * Unless required by applicable law or agreed to in writing, software
    10   * distributed under the License is distributed on an "AS IS" BASIS,
    11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12   * See the License for the specific language governing permissions and
    13   * limitations under the License.
    14   */
    15
    16  package org.acegisecurity.providers.cas.proxy;
    17
    18  import java.util.List;
    19  import java.util.Vector;
    20
    21  import junit.framework.TestCase;
    22
    23  import org.acegisecurity.providers.cas.ProxyUntrustedException;
    24
    25
    26  /***
    27   * Tests {@link RejectProxyTickets}.
    28   *
    29   * @author Ben Alex
    30   * @version $Id: RejectProxyTicketsTests.java,v 1.4 2005/11/30 01:23:34 benalex Exp $
    31   */
    32  public class RejectProxyTicketsTests extends TestCase {
    33      //~ Constructors ===========================================================
    34
    35      public RejectProxyTicketsTests() {
    36          super();
    37      }
    38
    39      public RejectProxyTicketsTests(String arg0) {
    40          super(arg0);
    41      }
    42
    43      //~ Methods ================================================================
    44
    45      public final void setUp() throws Exception {
    46          super.setUp();
    47      }
    48
    49      public static void main(String[] args) {
    50          junit.textui.TestRunner.run(RejectProxyTicketsTests.class);
    51      }
    52
    53      public void testAcceptsIfNoProxiesInTicket() {
    54          RejectProxyTickets proxyDecider = new RejectProxyTickets();
    55          List proxyList = new Vector(); // no proxies in list
    56
    57          proxyDecider.confirmProxyListTrusted(proxyList);
    58          assertTrue(true);
    59      }
    60
    61      public void testDoesNotAcceptNull() {
    62          RejectProxyTickets proxyDecider = new RejectProxyTickets();
    63
    64          try {
    65              proxyDecider.confirmProxyListTrusted(null);
    66              fail("Should have thrown IllegalArgumentException");
    67          } catch (IllegalArgumentException expected) {
    68              assertEquals("proxyList cannot be null", expected.getMessage());
    69          }
    70      }
    71
    72      public void testRejectsIfAnyProxyInList() {
    73          RejectProxyTickets proxyDecider = new RejectProxyTickets();
    74          List proxyList = new Vector();
    75          proxyList.add("https://localhost/webApp/j_acegi_cas_security_check");
    76
    77          try {
    78              proxyDecider.confirmProxyListTrusted(proxyList);
    79              fail("Should have thrown ProxyUntrustedException");
    80          } catch (ProxyUntrustedException expected) {
    81              assertTrue(true);
    82          }
    83      }
    84  }