001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.harmony.auth.tests.jgss.kerberos;
019:
020: import java.util.Arrays;
021:
022: import org.apache.harmony.auth.jgss.kerberos.KerberosName;
023: import org.ietf.jgss.GSSName;
024: import org.ietf.jgss.Oid;
025:
026: import junit.framework.TestCase;
027:
028: public class KerberosNameTest extends TestCase {
029:
030: public void testExport() throws Exception {
031: KerberosName kerberosName = new KerberosName(
032: "service@localhost", GSSName.NT_HOSTBASED_SERVICE);
033: byte[] exported = kerberosName.export();
034: byte[] expected = new byte[] { 4, 1, 0, 11, 6, 9, 42, -122, 72,
035: -122, -9, 18, 1, 2, 2, 0, 0, 0, 17, 115, 101, 114, 118,
036: 105, 99, 101, 47, 108, 111, 99, 97, 108, 104, 111, 115,
037: 116 };
038: assertTrue(Arrays.equals(expected, exported));
039: }
040:
041: public void testEquals() throws Exception {
042: KerberosName one = new KerberosName("service@localhost",
043: GSSName.NT_HOSTBASED_SERVICE);
044: KerberosName another = new KerberosName("service@localhost",
045: GSSName.NT_HOSTBASED_SERVICE);
046: assertEquals(one, another);
047:
048: one = new KerberosName("service@localhost",
049: GSSName.NT_HOSTBASED_SERVICE);
050: another = new KerberosName("service/localhost",
051: GSSName.NT_HOSTBASED_SERVICE);
052: assertEquals(one, another);
053:
054: one = new KerberosName("service@localhost",
055: GSSName.NT_USER_NAME);
056: another = new KerberosName("service@localhost",
057: GSSName.NT_USER_NAME);
058: assertEquals(one, another);
059:
060: one = new KerberosName("service@localhost",
061: GSSName.NT_USER_NAME);
062: another = new KerberosName("service/localhost",
063: GSSName.NT_USER_NAME);
064: assertFalse(one.equals(another));
065:
066: final Oid KRB5_PRINCIPAL_NAMETYPE = new Oid(
067: "1.2.840.113554.1.2.2.1");
068: one = new KerberosName("service@localhost",
069: KRB5_PRINCIPAL_NAMETYPE);
070: another = new KerberosName("service@localhost",
071: KRB5_PRINCIPAL_NAMETYPE);
072: assertEquals(one, another);
073:
074: one = new KerberosName("service@localhost",
075: KRB5_PRINCIPAL_NAMETYPE);
076: another = new KerberosName("service/localhost",
077: KRB5_PRINCIPAL_NAMETYPE);
078: assertFalse(one.equals(another));
079:
080: one = new KerberosName("service@localhost",
081: KRB5_PRINCIPAL_NAMETYPE);
082: another = new KerberosName("service@localhost",
083: GSSName.NT_USER_NAME);
084: assertEquals(one, another);
085:
086: one = new KerberosName("service@localhost",
087: KRB5_PRINCIPAL_NAMETYPE);
088: another = new KerberosName("service@localhost",
089: GSSName.NT_HOSTBASED_SERVICE);
090: assertFalse(one.equals(another));
091:
092: one = new KerberosName("service/localhost",
093: KRB5_PRINCIPAL_NAMETYPE);
094: another = new KerberosName("service@localhost",
095: GSSName.NT_HOSTBASED_SERVICE);
096: assertEquals(one, another);
097:
098: one = new KerberosName("service@localhost",
099: GSSName.NT_USER_NAME);
100: another = new KerberosName("service@localhost",
101: GSSName.NT_HOSTBASED_SERVICE);
102: assertFalse(one.equals(another));
103:
104: one = new KerberosName("service/localhost",
105: GSSName.NT_USER_NAME);
106: another = new KerberosName("service@localhost",
107: GSSName.NT_HOSTBASED_SERVICE);
108: assertFalse(one.equals(another));
109: }
110: }
|