1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
33
34
35
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 }