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.HostAddrType;
27
28 import junit.framework.TestCase;
29
30
31
32
33
34
35
36
37 public class HostAddressesTest extends TestCase
38 {
39 public void testEncodingHostAddressesIPOneAddresses() throws Exception
40 {
41 HostAddress[] ha = new HostAddress[]
42 { new HostAddress( HostAddrType.ADDRTYPE_INET, new byte[]
43 { 0x01, 0x02, 0x03, 0x04 } ), };
44
45 HostAddresses has = new HostAddresses( ha );
46
47 ByteBuffer encoded = ByteBuffer.allocate( has.computeLength() );
48
49 has.encode( encoded );
50
51 byte[] expectedResult = new byte[]
52 {
53 0x30, 0x0F,
54 0x30, 0x0d,
55 (byte)0xA0, 0x03,
56 0x02, 0x01, 0x02,
57 (byte)0xA1, 0x06,
58 0x04, 0x04,
59 0x01, 0x02, 0x03, 0x04
60 };
61
62 assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
63 }
64
65
66 public void testEncodingHostAddressesIP3Addresses() throws Exception
67 {
68 HostAddress[] ha = new HostAddress[]
69 { new HostAddress( HostAddrType.ADDRTYPE_INET, new byte[]
70 { 0x01, 0x02, 0x03, 0x04 } ), new HostAddress( HostAddrType.ADDRTYPE_INET, new byte[]
71 { 0x05, 0x06, 0x07, 0x08 } ), new HostAddress( HostAddrType.ADDRTYPE_INET, new byte[]
72 { 0x09, 0x0A, 0x0B, 0x0C } ) };
73
74 HostAddresses has = new HostAddresses( ha );
75
76 ByteBuffer encoded = ByteBuffer.allocate( has.computeLength() );
77
78 has.encode( encoded );
79
80 byte[] expectedResult = new byte[]
81 {
82 0x30, 0x2D,
83 0x30, 0x0d,
84 (byte)0xA0, 0x03,
85 0x02, 0x01, 0x02,
86 (byte)0xA1, 0x06,
87 0x04, 0x04,
88 0x01, 0x02, 0x03, 0x04,
89 0x30, 0x0d,
90 (byte)0xA0, 0x03,
91 0x02, 0x01, 0x02,
92 (byte)0xA1, 0x06,
93 0x04, 0x04,
94 0x05, 0x06, 0x07, 0x08,
95 0x30, 0x0d,
96 (byte)0xA0, 0x03,
97 0x02, 0x01, 0x02,
98 (byte)0xA1, 0x06,
99 0x04, 0x04,
100 0x09, 0x0A, 0x0B, 0x0C
101 };
102
103 assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
104 }
105
106
107 public void testEncodingHostAddressIPNullAddress() throws Exception
108 {
109 HostAddresses has = new HostAddresses( null );
110
111 ByteBuffer encoded = ByteBuffer.allocate( has.computeLength() );
112
113 has.encode( encoded );
114
115 byte[] expectedResult = new byte[]
116 { 0x30, 0x00 };
117
118 assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
119 }
120 }