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.shared.messages.value;
21  
22  
23  import java.nio.ByteBuffer;
24  import java.util.Arrays;
25  
26  import org.apache.directory.server.kerberos.shared.messages.value.types.AuthorizationType;
27  
28  import junit.framework.TestCase;
29  
30  
31  /**
32   * Test the AuthorizationData encoding and decoding
33   * 
34   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
35   * @version $Rev: 542147 $, $Date: 2007-05-28 10:14:21 +0200 (Mon, 28 May 2007) $
36   */
37  public class AuthorizationDataTest extends TestCase
38  {
39      public void testAuthorizationDataOneAD() throws Exception
40      {
41          AuthorizationData ad = new AuthorizationData();
42          ad.add( new AuthorizationDataEntry( AuthorizationType.AD_KDC_ISSUED, new byte[]
43              { 0x01, 0x02, 0x03, 0x04 } ) );
44  
45          ByteBuffer encoded = ByteBuffer.allocate( ad.computeLength() );
46  
47          ad.encode( encoded );
48  
49          byte[] expectedResult = new byte[]
50              { 
51                0x30, 0x0F, 
52                  0x30, 0x0d, 
53                    ( byte ) 0xA0, 0x03, 
54                      0x02, 0x01, 0x04, 
55                    ( byte ) 0xA1, 0x06, 
56                      0x04, 0x04, 0x01, 0x02, 0x03, 0x04 
57              };
58  
59          assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
60      }
61  
62  
63      public void testAuthorizationDataThreeAD() throws Exception
64      {
65          AuthorizationData ad = new AuthorizationData();
66          ad.add( new AuthorizationDataEntry( AuthorizationType.AD_KDC_ISSUED, new byte[]
67              { 0x01, 0x02, 0x03, 0x04 } ) );
68          ad.add( new AuthorizationDataEntry( AuthorizationType.AD_IF_RELEVANT, new byte[]
69              { 0x05, 0x06, 0x07, 0x08 } ) );
70          ad.add( new AuthorizationDataEntry( AuthorizationType.AD_MANDATORY_TICKET_EXTENSIONS, new byte[]
71              { 0x09, 0x0A, 0x0B, 0x0C } ) );
72  
73          ByteBuffer encoded = ByteBuffer.allocate( ad.computeLength() );
74  
75          ad.encode( encoded );
76  
77          byte[] expectedResult = new byte[]
78              { 
79                0x30, 0x2D, 
80                  0x30, 0x0d, 
81                    ( byte ) 0xA0, 0x03, 
82                      0x02, 0x01, 0x04, 
83                    ( byte ) 0xA1, 0x06, 
84                      0x04, 0x04, 
85                        0x01, 0x02, 0x03, 0x04, 
86                  0x30, 0x0d, 
87                    ( byte ) 0xA0, 0x03, 
88                      0x02, 0x01, 0x01, 
89                    ( byte ) 0xA1, 0x06, 
90                      0x04, 0x04,
91                        0x05, 0x06, 0x07, 0x08, 
92                  0x30, 0x0d, 
93                    ( byte ) 0xA0, 0x03, 
94                      0x02, 0x01, 0x06, 
95                    ( byte ) 0xA1, 0x06, 
96                      0x04, 0x04, 
97                        0x09, 0x0A, 0x0B, 0x0C 
98              };
99  
100         assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
101     }
102 }