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;
21
22 import java.util.List;
23
24 import javax.security.auth.kerberos.KerberosPrincipal;
25
26 import org.apache.directory.server.kerberos.shared.KerberosUtils;
27
28 import junit.framework.TestCase;
29
30 /**
31 * Test the KerberosUtils class
32 *
33 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
34 */
35 public class KerberosUtilsTest extends TestCase
36 {
37 public void setUp()
38 {
39 // First setup a default realm
40 System.setProperty( "java.security.krb5.realm", "APACHE.ORG" );
41 System.setProperty( "java.security.krb5.kdc", "localhost" );
42 }
43
44
45 public void testKerberosNameSimple() throws Exception
46 {
47 KerberosPrincipal kp = new KerberosPrincipal( "abc" );
48 List<String> names = KerberosUtils.getNames( kp );
49
50 assertEquals( 1, names.size() );
51 assertEquals( "abc", names.get( 0 ) );
52 }
53
54
55 /**
56 public void testKerberosNameEscaped() throws Exception
57 {
58 KerberosPrincipal kp = new KerberosPrincipal( "abc\\//d\\@f/g\\\\hi" );
59 List<String> names = KerberosUtils.getNames( kp );
60
61 assertEquals( 3, names.size() );
62 assertEquals( "abc\\/", names.get( 0 ) );
63 assertEquals( "d\\@g", names.get( 1 ) );
64 assertEquals( "g\\\\hi", names.get( 2 ) );
65 }
66 */
67
68
69 public void testKerberosNameSimpleWithRealm() throws Exception
70 {
71 KerberosPrincipal kp = new KerberosPrincipal( "abc@APACHE.ORG" );
72 List<String> names = KerberosUtils.getNames( kp );
73
74 assertEquals( 1, names.size() );
75 assertEquals( "abc", names.get( 0 ) );
76 }
77
78 public void testKerberosNameThree() throws Exception
79 {
80 KerberosPrincipal kp = new KerberosPrincipal( "abc/def/ghi" );
81 List<String> names = KerberosUtils.getNames( kp );
82
83 assertEquals( 3, names.size() );
84 assertEquals( "abc", names.get( 0 ) );
85 assertEquals( "def", names.get( 1 ) );
86 assertEquals( "ghi", names.get( 2 ) );
87 }
88
89 public void testKerberosNameThreeWithRealm() throws Exception
90 {
91 KerberosPrincipal kp = new KerberosPrincipal( "abc/def/ghi@APACHE.ORG" );
92 List<String> names = KerberosUtils.getNames( kp );
93
94 assertEquals( 3, names.size() );
95 assertEquals( "abc", names.get( 0 ) );
96 assertEquals( "def", names.get( 1 ) );
97 assertEquals( "ghi", names.get( 2 ) );
98 }
99
100
101
102 /*
103 public void testKerberosEndingSlash()
104 {
105 try
106 {
107 KerberosPrincipal kp = new KerberosPrincipal( "abc/def/ghi/" );
108 KerberosUtils.getNames( kp );
109
110 // Should not reach this point
111 fail();
112 }
113 catch ( ParseException pe )
114 {
115 assertTrue( true );
116 }
117 }
118 */
119
120
121 /*
122 public void testKerberosEndingSlashWithRealm()
123 {
124 try
125 {
126 KerberosPrincipal kp = new KerberosPrincipal( "abc/def/ghi/@APACHE.ORG" );
127 KerberosUtils.getNames( kp );
128
129 // Should not reach this point
130 fail();
131 }
132 catch ( ParseException pe )
133 {
134 assertTrue( true );
135 }
136 }
137 */
138 }