1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.server.kerberos.messages.value;
21  
22  
23  import java.util.Arrays;
24  
25  import junit.framework.TestCase;
26  
27  import org.apache.directory.server.kerberos.shared.messages.value.KdcOptions;
28  import org.apache.directory.server.kerberos.shared.messages.value.flags.TicketFlag;
29  import org.apache.directory.server.kerberos.shared.messages.value.flags.TicketFlags;
30  
31  
32  /**
33   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
34   * @version $Rev: 591019 $, $Date: 2007-11-01 15:16:34 +0100 (Do, 01 Nov 2007) $
35   */
36  public class OptionsTest extends TestCase
37  {
38      private byte[] fpriOptions =
39          { ( byte ) 0x50, ( byte ) 0x00, ( byte ) 0x00, ( byte ) 0x10 };
40  
41  
42      /**
43       * Tests converting the ticket flags to a descriptive String.
44       */
45      public void testToString()
46      {
47          TicketFlags flags = new TicketFlags();
48          flags.setFlag( TicketFlag.FORWARDABLE );
49          flags.setFlag( TicketFlag.PROXIABLE );
50          flags.setFlag( TicketFlag.RENEWABLE );
51          flags.setFlag( TicketFlag.INITIAL );
52          assertEquals( flags.toString(), "FORWARDABLE(1) PROXIABLE(3) RENEWABLE(8) INITIAL(9)" );
53      }
54  
55  
56      /**
57       * Tests that setting flags is idempotent.
58       */
59      public void testDuplicateSetting()
60      {
61          TicketFlags flags = new TicketFlags();
62          flags.setFlag( TicketFlag.MAY_POSTDATE );
63          flags.setFlag( TicketFlag.FORWARDABLE );
64          flags.setFlag( TicketFlag.PROXIABLE );
65          flags.setFlag( TicketFlag.MAY_POSTDATE );
66          flags.setFlag( TicketFlag.RENEWABLE );
67          assertEquals( flags.toString(), "FORWARDABLE(1) PROXIABLE(3) MAY_POSTDATE(5) RENEWABLE(8)" );
68      }
69  
70  
71      /**
72       * Tests the basic construction of the {@link KdcOptions}.
73       */
74      public void testConstruction()
75      {
76          KdcOptions options = new KdcOptions( fpriOptions );
77          assertTrue( Arrays.equals( options.getBytes(), fpriOptions ) );
78      }
79  }