directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1034785 - /directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/TicketDecoderTest.java
Date Sat, 13 Nov 2010 15:56:50 GMT
Author: elecharny
Date: Sat Nov 13 15:56:49 2010
New Revision: 1034785

URL: http://svn.apache.org/viewvc?rev=1034785&view=rev
Log:
Added tests for corner-cases. The last test is currently failing, because we expect one more
element but the way it's handled by the encapsulated decoder force the decoding to stop. One
more ugly hack to find ...

Modified:
    directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/TicketDecoderTest.java

Modified: directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/TicketDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/TicketDecoderTest.java?rev=1034785&r1=1034784&r2=1034785&view=diff
==============================================================================
--- directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/TicketDecoderTest.java
(original)
+++ directory/apacheds/trunk/kerberos-codec/src/test/java/org/apache/directory/shared/kerberos/codec/TicketDecoderTest.java
Sat Nov 13 15:56:49 2010
@@ -141,4 +141,400 @@ public class TicketDecoderTest
             fail( ee.getMessage() );
         }
     }
+
+
+    /**
+     * Test the decoding of an empty Ticket message
+     */
+    @Test( expected=DecoderException.class)
+    public void testDecodeTicketEmpty() throws Exception
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x02 );
+        
+        stream.put( new byte[]
+            { 0x61, 0x00 });
+
+        stream.flip();
+
+        // Allocate a Ticket Container
+        Asn1Container ticketContainer = new TicketContainer();
+        ticketContainer.setStream( stream );
+
+        // Decode the Ticket PDU
+        kerberosDecoder.decode( stream, ticketContainer );
+    }
+
+
+    /**
+     * Test the decoding of an empty Ticket sequence
+     */
+    @Test( expected=DecoderException.class)
+    public void testDecodeTicketEmptySEQ() throws Exception
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x04 );
+        
+        stream.put( new byte[]
+            { 
+                0x61, 0x02,
+                  0x30, 0x00
+            });
+
+        stream.flip();
+
+        // Allocate a Ticket Container
+        Asn1Container ticketContainer = new TicketContainer();
+        ticketContainer.setStream( stream );
+
+        // Decode the Ticket PDU
+        kerberosDecoder.decode( stream, ticketContainer );
+    }
+
+
+    /**
+     * Test the decoding of an empty tktvno tag
+     */
+    @Test( expected=DecoderException.class)
+    public void testDecodeTicketEmptyTktVnoTag() throws Exception
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x06 );
+        
+        stream.put( new byte[]
+            { 
+                0x61, 0x04,
+                  0x30, 0x02,
+                    (byte)0xA0, 0x00
+            });
+
+        stream.flip();
+
+        // Allocate a Ticket Container
+        Asn1Container ticketContainer = new TicketContainer();
+        ticketContainer.setStream( stream );
+
+        // Decode the Ticket PDU
+        kerberosDecoder.decode( stream, ticketContainer );
+    }
+
+
+    /**
+     * Test the decoding of an empty tktvno value
+     */
+    @Test( expected=DecoderException.class)
+    public void testDecodeTicketEmptyTktVnoValue() throws Exception
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x08 );
+        
+        stream.put( new byte[]
+            { 
+                0x61, 0x06,
+                  0x30, 0x04,
+                    (byte)0xA0, 0x02,
+                      0x02, 0x00
+            });
+
+        stream.flip();
+
+        // Allocate a Ticket Container
+        Asn1Container ticketContainer = new TicketContainer();
+        ticketContainer.setStream( stream );
+
+        // Decode the Ticket PDU
+        kerberosDecoder.decode( stream, ticketContainer );
+    }
+
+
+    /**
+     * Test the decoding of an bad tktvno value
+     */
+    @Test( expected=DecoderException.class)
+    public void testDecodeTicketBadTktVnoValue() throws Exception
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x09 );
+        
+        stream.put( new byte[]
+            { 
+                0x61, 0x07,
+                  0x30, 0x05,
+                    (byte)0xA0, 0x03,
+                      0x02, 0x01, 0x02
+            });
+
+        stream.flip();
+
+        // Allocate a Ticket Container
+        Asn1Container ticketContainer = new TicketContainer();
+        ticketContainer.setStream( stream );
+
+        // Decode the Ticket PDU
+        kerberosDecoder.decode( stream, ticketContainer );
+    }
+
+
+    /**
+     * Test the decoding of a ticket with no realm
+     */
+    @Test( expected=DecoderException.class)
+    public void testDecodeTicketNoRealm() throws Exception
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x09 );
+        
+        stream.put( new byte[]
+            { 
+                0x61, 0x07,
+                  0x30, 0x05,
+                    (byte)0xA0, 0x03,
+                      0x02, 0x01, 0x05
+            });
+
+        stream.flip();
+
+        // Allocate a Ticket Container
+        Asn1Container ticketContainer = new TicketContainer();
+        ticketContainer.setStream( stream );
+
+        // Decode the Ticket PDU
+        kerberosDecoder.decode( stream, ticketContainer );
+    }
+
+
+    /**
+     * Test the decoding of an empty realm tag
+     */
+    @Test( expected=DecoderException.class)
+    public void testDecodeTicketEmptyRealmTag() throws Exception
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x0B );
+        
+        stream.put( new byte[]
+            { 
+                0x61, 0x09,
+                  0x30, 0x07,
+                    (byte)0xA0, 0x03,
+                      0x02, 0x01, 0x05,
+                    (byte)0xA1, 0x00
+            });
+
+        stream.flip();
+
+        // Allocate a Ticket Container
+        Asn1Container ticketContainer = new TicketContainer();
+        ticketContainer.setStream( stream );
+
+        // Decode the Ticket PDU
+        kerberosDecoder.decode( stream, ticketContainer );
+    }
+
+
+    /**
+     * Test the decoding of an empty realm value
+     */
+    @Test( expected=DecoderException.class)
+    public void testDecodeTicketEmptyRealmValue() throws Exception
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x0D );
+        
+        stream.put( new byte[]
+            { 
+                0x61, 0x0B,
+                  0x30, 0x09,
+                    (byte)0xA0, 0x03,
+                      0x02, 0x01, 0x05,
+                    (byte)0xA1, 0x02,
+                      0x1B, 0x00
+            });
+
+        stream.flip();
+
+        // Allocate a Ticket Container
+        Asn1Container ticketContainer = new TicketContainer();
+        ticketContainer.setStream( stream );
+
+        // Decode the Ticket PDU
+        kerberosDecoder.decode( stream, ticketContainer );
+    }
+
+
+    /**
+     * Test the decoding of a ticket with no sname
+     */
+    @Test( expected=DecoderException.class)
+    public void testDecodeTicketNoSname() throws Exception
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x18 );
+        
+        stream.put( new byte[]
+            { 
+                0x61, 0x16,
+                  0x30, 0x14,
+                    (byte)0xA0, 0x03,
+                      0x02, 0x01, 0x05,
+                    (byte)0xA1, 0x0D,
+                      0x1B, 0x0B, 'E', 'X', 'A', 'M', 'P', 'L', 'E', '.', 'C', 'O', 'M',
+            });
+
+        stream.flip();
+
+        // Allocate a Ticket Container
+        Asn1Container ticketContainer = new TicketContainer();
+        ticketContainer.setStream( stream );
+
+        // Decode the Ticket PDU
+        kerberosDecoder.decode( stream, ticketContainer );
+    }
+
+
+    /**
+     * Test the decoding of a ticket with an empty sname tag
+     */
+    @Test( expected=DecoderException.class)
+    public void testDecodeTicketEmptySnameTag() throws Exception
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x1A );
+        
+        stream.put( new byte[]
+            { 
+                0x61, 0x18,
+                  0x30, 0x16,
+                    (byte)0xA0, 0x03,
+                      0x02, 0x01, 0x05,
+                    (byte)0xA1, 0x0D,
+                      0x1B, 0x0B, 'E', 'X', 'A', 'M', 'P', 'L', 'E', '.', 'C', 'O', 'M',
+                    (byte)0xA2, 0x00
+            });
+
+        stream.flip();
+
+        // Allocate a Ticket Container
+        Asn1Container ticketContainer = new TicketContainer();
+        ticketContainer.setStream( stream );
+
+        // Decode the Ticket PDU
+        kerberosDecoder.decode( stream, ticketContainer );
+    }
+
+
+    /**
+     * Test the decoding of a ticket with an empty sname value
+     */
+    @Test( expected=DecoderException.class)
+    public void testDecodeTicketEmptySnameValue() throws Exception
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x1C );
+        
+        stream.put( new byte[]
+            { 
+                0x61, 0x1A,
+                  0x30, 0x18,
+                    (byte)0xA0, 0x03,
+                      0x02, 0x01, 0x05,
+                    (byte)0xA1, 0x0D,
+                      0x1B, 0x0B, 'E', 'X', 'A', 'M', 'P', 'L', 'E', '.', 'C', 'O', 'M',
+                    (byte)0xA2, 0x02,
+                      0x30, 0x00
+            });
+
+        stream.flip();
+
+        // Allocate a Ticket Container
+        Asn1Container ticketContainer = new TicketContainer();
+        ticketContainer.setStream( stream );
+
+        // Decode the Ticket PDU
+        kerberosDecoder.decode( stream, ticketContainer );
+    }
+
+
+    /**
+     * Test the decoding of a ticket with a bad principalName
+     */
+    @Test( expected=DecoderException.class)
+    public void testDecodeTicketBadSName() throws Exception
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x20 );
+        
+        stream.put( new byte[]
+            { 
+              0x61, 0x1E,                               // Ticket
+                0x30, 0x1C,
+                  (byte)0xA0, 0x03,                     // tkt-vno
+                    0x02, 0x01, 0x05,
+                  (byte)0xA1, 0x0D,                     // realm
+                    0x1B, 0x0B, 'E', 'X', 'A', 'M', 'P', 'L', 'E', '.', 'C', 'O', 'M',
+                  (byte)0xA2, 0x06,                     // sname
+                    0x30, 0x04,
+                      (byte)0xA0, 0x02,                 // name-type
+                        0x02, 0x00
+            });
+
+        stream.flip();
+
+        // Allocate a Ticket Container
+        Asn1Container ticketContainer = new TicketContainer();
+        ticketContainer.setStream( stream );
+
+        // Decode the Ticket PDU
+        kerberosDecoder.decode( stream, ticketContainer );
+    }
+
+
+    /**
+     * Test the decoding of a ticket with no enc-part
+     */
+    @Test( expected=DecoderException.class)
+    public void testDecodeTicketNoEncPart() throws Exception
+    {
+        Asn1Decoder kerberosDecoder = new Asn1Decoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x2E );
+        
+        stream.put( new byte[]
+            { 
+              0x61, 0x2C,                               // Ticket
+                0x30, 0x2A,
+                  (byte)0xA0, 0x03,                     // tkt-vno
+                    0x02, 0x01, 0x05,
+                  (byte)0xA1, 0x0D,                     // realm
+                    0x1B, 0x0B, 'E', 'X', 'A', 'M', 'P', 'L', 'E', '.', 'C', 'O', 'M',
+                  (byte)0xA2, 0x14,                     // sname
+                    0x30, 0x12,
+                      (byte)0xA0, 0x03,                 // name-type
+                        0x02, 0x01, 0x01,
+                      (byte)0xA1, 0x0B,                 // name-string
+                        0x30, 0x09,
+                          0x1B, 0x07, 'h', 'n', 'e', 'l', 's', 'o', 'n',
+            });
+
+        stream.flip();
+
+        // Allocate a Ticket Container
+        Asn1Container ticketContainer = new TicketContainer();
+        ticketContainer.setStream( stream );
+
+        // Decode the Ticket PDU
+        kerberosDecoder.decode( stream, ticketContainer );
+    }
 }



Mime
View raw message