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.PaDataType;
27
28 import junit.framework.TestCase;
29
30
31 /**
32 * Test the PaData 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 PaDataTest extends TestCase
38 {
39 public void testEncodingPreAuthenticationData() throws Exception
40 {
41 PaData pad = new PaData( PaDataType.PA_ASF3_SALT, new byte[]
42 { 0x01, 0x02, 0x03 } );
43
44 ByteBuffer encoded = ByteBuffer.allocate( pad.computeLength() );
45
46 pad.encode( encoded );
47
48 byte[] expectedResult = new byte[]
49 {
50 0x30, 0x0c,
51 ( byte ) 0xA1, 0x03,
52 0x02, 0x01, 0x0A,
53 ( byte ) 0xA2, 0x05,
54 0x04, 0x03,
55 0x01, 0x02, 0x03
56 };
57
58 assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
59 }
60
61
62 public void testEncodingNullPreAuthenticationData() throws Exception
63 {
64 PaData pad = new PaData( PaDataType.PA_ASF3_SALT, null );
65
66 ByteBuffer encoded = ByteBuffer.allocate( pad.computeLength() );
67
68 pad.encode( encoded );
69
70 byte[] expectedResult = new byte[]
71 {
72 0x30, 0x09,
73 ( byte ) 0xA1, 0x03,
74 0x02, 0x01, 0x0A,
75 ( byte ) 0xA2, 0x02,
76 0x04, 0x00
77 };
78
79 assertTrue( Arrays.equals( expectedResult, encoded.array() ) );
80 }
81 }