harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r485661 - in /harmony/enhanced/classlib/trunk/modules/auth/src: main/java/common/javax/security/auth/kerberos/ test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/ test/java/common/org/apache/harmony/auth/tests/javax...
Date Mon, 11 Dec 2006 13:40:20 GMT
Author: smishura
Date: Mon Dec 11 05:40:19 2006
New Revision: 485661

URL: http://svn.apache.org/viewvc?view=rev&rev=485661
Log:
Fix for KerberosTicket + regression test + serialization test

Added:
    harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosTicketTest.java
  (with props)
    harmony/enhanced/classlib/trunk/modules/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosTicketTest.golden.ser
  (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosTicket.java
    harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/KerberosTicketTest.java

Modified: harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosTicket.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosTicket.java?view=diff&rev=485661&r1=485660&r2=485661
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosTicket.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/auth/src/main/java/common/javax/security/auth/kerberos/KerberosTicket.java
Mon Dec 11 05:40:19 2006
@@ -57,8 +57,8 @@
     // INITIAL flag
     private static final int INITIAL = 9;
 
-    // UNUSED flag, 12 - 32 bit reserved
-    private static final int UNUSED = 31;
+    // number of flags used by Kerberos protocol
+    private static final int FLAGS_NUM = 32;
 
     // line feed 
     private static final String LF = "\n"; //$NON-NLS-1$
@@ -132,20 +132,16 @@
         this.sessionKey = new KeyImpl(keyBytes, keyType);
 
         if (flags == null) {
-            this.flags = new boolean[UNUSED];
-        } else if (flags.length > UNUSED) {
+            this.flags = new boolean[FLAGS_NUM];
+        } else if (flags.length > FLAGS_NUM) {
             this.flags = new boolean[flags.length];
-            //Arrays.fill(flags, UNUSED, flags.length, false);
             System.arraycopy(flags, 0, this.flags, 0, this.flags.length);
         } else {
-            this.flags = new boolean[flags.length];
-            //System.arraycopy(flags, 0, this.flags, 0, this.flags.length);
-            for (int i = 0; i < flags.length; i++) {
-                this.flags[i] = flags[i];
-            }
+            this.flags = new boolean[FLAGS_NUM];
+            System.arraycopy(flags, 0, this.flags, 0, flags.length);
         }
 
-        if (flags[RENEWABLE] && renewTill == null) {
+        if (this.flags[RENEWABLE] && renewTill == null) {
             throw new IllegalArgumentException(Messages.getString("auth.41")); //$NON-NLS-1$
         }
 

Modified: harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/KerberosTicketTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/KerberosTicketTest.java?view=diff&rev=485661&r1=485660&r2=485661
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/KerberosTicketTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/KerberosTicketTest.java
Mon Dec 11 05:40:19 2006
@@ -46,6 +46,9 @@
 
     private static final int KEY_TYPE = 1;
 
+    // number of flags used by Kerberos protocol
+    private static final int FLAGS_NUM = 32;
+    
     private static final boolean[] flags = { true, false, true, false, true,
             false, true, false, true, false, true, false, };
 
@@ -198,6 +201,86 @@
     }
 
     /**
+     * @tests javax.security.auth.kerberos.KerberosTicket#getFlags()
+     */
+    public void test_getFlags() {
+
+        boolean[] myFlags = new boolean[] { true, //reserved
+                true, // forwardable
+                true, // forwarded
+                true, // proxiable
+                true, // proxy
+                true, // may-postdate 
+                true, // postdated
+                true, // invalid
+                true, // renewable
+                true, // initial
+                true, // pre-authent
+                true // hw-authent 
+        };
+
+        KerberosTicket krbTicket = new KerberosTicket(ticket, pClient, pServer,
+                sessionKey, KEY_TYPE, myFlags, // <=== we test this
+                authTime, startTime, endTime, renewTill, addesses);
+
+        // test: returned value is copied
+        assertNotSame(krbTicket.getFlags(), krbTicket.getFlags());
+
+        // test: flags values
+        assertTrue(krbTicket.isForwardable());
+        assertTrue(krbTicket.isForwarded());
+        assertTrue(krbTicket.isInitial());
+        assertTrue(krbTicket.isPostdated());
+        assertTrue(krbTicket.isProxiable());
+        assertTrue(krbTicket.isProxy());
+        assertTrue(krbTicket.isRenewable());
+
+        //
+        // test: number of flags less the in Kerberos protocol (<32)
+        //
+        boolean[] ktFlags = krbTicket.getFlags();
+        assertEquals("flags length", FLAGS_NUM, ktFlags.length);
+        int index = 0;
+        // must match to initial array
+        for (; index < flags.length; index++) {
+            assertEquals("Index: " + index, myFlags[index], ktFlags[index]);
+        }
+        // the rest is expected to be false
+        for (; index < FLAGS_NUM; index++) {
+            assertEquals("Index: " + index, false, ktFlags[index]);
+        }
+
+        //
+        // test: flags array is greater then 32
+        //
+        myFlags = new boolean[50];
+
+        krbTicket = new KerberosTicket(ticket, pClient, pServer, sessionKey,
+                KEY_TYPE, myFlags, // <=== we test this 
+                authTime, startTime, endTime, renewTill, addesses);
+
+        ktFlags = krbTicket.getFlags();
+
+        assertEquals(myFlags.length, ktFlags.length);
+        for (index = 0; index < ktFlags.length; index++) {
+            assertEquals(false, ktFlags[index]);
+        }
+
+        // initial array is copied
+        assertFalse(krbTicket.isForwardable());
+        myFlags[1] = true;
+        assertFalse(krbTicket.isForwardable());
+
+        //
+        // test: Null value
+        //
+        krbTicket = new KerberosTicket(ticket, pClient, pServer, sessionKey,
+                KEY_TYPE, null, // <=== we test this
+                authTime, startTime, endTime, renewTill, addesses);
+        assertTrue(Arrays.equals(new boolean[FLAGS_NUM], krbTicket.getFlags()));
+    }
+
+    /**
      * @tests javax.security.auth.kerberos.KerberosTicket#getServer() 
      */
     public void test_getServer() throws Exception {
@@ -286,7 +369,7 @@
         assertEquals(authTime, krbTicket.getStartTime());
         assertNotSame(authTime, krbTicket.getStartTime());
     }
-    
+
     /**
      * @tests javax.security.auth.kerberos.KerberosTicket#destroy()
      * @tests javax.security.auth.kerberos.KerberosTicket#isDestroyed()

Added: harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosTicketTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosTicketTest.java?view=auto&rev=485661
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosTicketTest.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosTicketTest.java
Mon Dec 11 05:40:19 2006
@@ -0,0 +1,112 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.auth.tests.javax.security.auth.kerberos.serialization;
+
+import java.io.Serializable;
+import java.net.InetAddress;
+import java.util.Arrays;
+import java.util.Date;
+
+import javax.security.auth.kerberos.KerberosPrincipal;
+import javax.security.auth.kerberos.KerberosTicket;
+
+import junit.framework.TestCase;
+
+import org.apache.harmony.testframework.serialization.SerializationTest;
+import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
+
+public class KerberosTicketTest extends TestCase {
+
+    // ticket's ASN.1 encoding  
+    private static final byte[] ticket = { 0x01, 0x02, 0x03, 0x04 };
+
+    // client's principal 
+    private static final KerberosPrincipal pClient = new KerberosPrincipal(
+            "client@apache.org");
+
+    // server's principal 
+    private static final KerberosPrincipal pServer = new KerberosPrincipal(
+            "server@apache.org");
+
+    // session key
+    private static final byte[] sessionKey = { 0x01, 0x04, 0x03, 0x02 };
+
+    private static final int KEY_TYPE = 1;
+
+    private static final boolean[] flags = { true, false, true, false, true,
+            false, true, false, true, false, true, false, };
+
+    private static final Date authTime = new Date(0);
+
+    private static final Date startTime = new Date(1);
+
+    private static final Date endTime = new Date(2);
+
+    private static final Date renewTill = new Date(3);
+
+    private static final InetAddress[] addesses = null;
+
+    // comparator for KerberosKey objects
+    private static final SerializableAssert COMPARATOR = new SerializableAssert() {
+        public void assertDeserialized(Serializable initial,
+                Serializable deserialized) {
+
+            KerberosTicket init = (KerberosTicket) initial;
+            KerberosTicket desr = (KerberosTicket) deserialized;
+
+            assertTrue("Ticket", Arrays.equals(init.getEncoded(), desr
+                    .getEncoded()));
+
+            assertEquals("Client", init.getClient(), desr.getClient());
+            assertEquals("Server", init.getServer(), desr.getServer());
+
+            assertTrue("Key", Arrays.equals(init.getSessionKey().getEncoded(),
+                    desr.getSessionKey().getEncoded()));
+            assertEquals("KeyType", init.getSessionKeyType(), desr
+                    .getSessionKeyType());
+
+            assertTrue("Flags", Arrays.equals(init.getFlags(), desr.getFlags()));
+
+            assertEquals("AuthTime", init.getAuthTime(), desr.getAuthTime());
+            assertEquals("StartTime", init.getStartTime(), desr.getStartTime());
+            assertEquals("EndTime", init.getEndTime(), desr.getEndTime());
+            assertEquals("RenewTill", init.getRenewTill(), desr.getRenewTill());
+
+            assertNull("ClientAddresses", desr.getClientAddresses());
+        }
+    };
+
+    /**
+     * @tests serialization/deserialization compatibility.
+     */
+    public void testSerializationSelf() throws Exception {
+        SerializationTest.verifySelf(new KerberosTicket(ticket, pClient,
+                pServer, sessionKey, KEY_TYPE, flags, authTime, startTime,
+                endTime, renewTill, addesses), COMPARATOR);
+    }
+
+    /**
+     * @tests serialization/deserialization compatibility with RI.
+     */
+    public void testSerializationCompatibility() throws Exception {
+        SerializationTest.verifyGolden(this, new KerberosTicket(ticket,
+                pClient, pServer, sessionKey, KEY_TYPE, flags, authTime,
+                startTime, endTime, renewTill, addesses), COMPARATOR);
+
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/auth/src/test/java/common/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosTicketTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosTicketTest.golden.ser
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosTicketTest.golden.ser?view=auto&rev=485661
==============================================================================
Binary file - no diff available.

Propchange: harmony/enhanced/classlib/trunk/modules/auth/src/test/resources/serialization/org/apache/harmony/auth/tests/javax/security/auth/kerberos/serialization/KerberosTicketTest.golden.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message