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
25 import org.apache.directory.server.kerberos.shared.messages.value.types.PrincipalNameType;
26 import org.apache.directory.shared.ldap.util.StringTools;
27
28 import junit.framework.TestCase;
29
30
31
32
33
34
35
36
37 public class PrincipalNameTest extends TestCase
38 {
39 public void testEncodingPrincipalNameOneName() throws Exception
40 {
41 PrincipalName principal = new PrincipalName( "Test@APACHE", PrincipalNameType.KRB_NT_PRINCIPAL );
42
43 ByteBuffer encoded = ByteBuffer.allocate( principal.computeLength() );
44
45 principal.encode( encoded );
46
47 byte[] expectedResult = new byte[]
48 {
49 0x30, 0x0F,
50 (byte) 0xA0, 0x03,
51 0x02, 0x01, 0x01,
52 (byte) 0xA1, 0x08,
53 0x30, 0x06,
54 0x1B, 0x04,
55 'T', 'e', 's', 't'
56 };
57
58 assertEquals( StringTools.dumpBytes( expectedResult ), StringTools.dumpBytes( encoded.array() ) );
59 }
60
61
62 public void testEncodingPrincipalName3names() throws Exception
63 {
64 PrincipalName principal = new PrincipalName( "Test1@APACHE", PrincipalNameType.KRB_NT_PRINCIPAL );
65 principal.addName( "Test2" );
66 principal.addName( "Test3" );
67
68 ByteBuffer encoded = ByteBuffer.allocate( principal.computeLength() );
69
70 principal.encode( encoded );
71
72 byte[] expectedResult = new byte[]
73 {
74 0x30, 0x1e,
75 (byte) 0xA0, 0x03,
76 0x02, 0x01, 0x01,
77 (byte) 0xA1, 0x17,
78 0x30, 0x15,
79 0x1B, 0x05,
80 'T', 'e', 's', 't', '1',
81 0x1B, 0x05,
82 'T', 'e', 's', 't', '2',
83 0x1B, 0x05,
84 'T', 'e', 's', 't', '3'
85 };
86
87 assertEquals( StringTools.dumpBytes( expectedResult ), StringTools.dumpBytes( encoded.array() ) );
88 }
89
90
91 public void testEncodingPrincipalNameNullName() throws Exception
92 {
93 PrincipalName principal = new PrincipalName( null, PrincipalNameType.KRB_NT_PRINCIPAL );
94
95 ByteBuffer encoded = ByteBuffer.allocate( principal.computeLength() );
96
97 principal.encode( encoded );
98
99 byte[] expectedResult = new byte[]
100 {
101 0x30, 0x09,
102 ( byte ) 0xA0, 0x03,
103 0x02, 0x01, 0x01,
104 ( byte ) 0xA1, 0x02,
105 0x30, 0x00
106 };
107
108 assertEquals( StringTools.dumpBytes( expectedResult ), StringTools.dumpBytes( encoded.array() ) );
109 }
110 }