Home | History | Annotate | Download | only in v5
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  */
     17 
     18 package org.apache.harmony.auth.tests.internal.kerberos.v5;
     19 
     20 import java.io.IOException;
     21 import java.util.Date;
     22 
     23 import junit.framework.TestCase;
     24 
     25 import org.apache.harmony.auth.internal.kerberos.v5.KerberosErrorMessage;
     26 import org.apache.harmony.auth.internal.kerberos.v5.PrincipalName;
     27 import org.apache.harmony.security.asn1.DerInputStream;
     28 
     29 public class KerberosErrorMessageTest extends TestCase {
     30 
     31     public void test_Ctor() throws IOException {
     32 
     33         KerberosErrorMessage message = KerberosErrorMessage
     34                 .decode(new DerInputStream(err_resp));
     35 
     36         assertEquals("ctime", new Date(1000), message.getCtime());
     37         assertEquals("cusec", 65536, message.getCusec());
     38 
     39         assertEquals("stime", new Date(0), message.getStime());
     40         assertEquals("susec", 65793, message.getSusec());
     41 
     42         assertEquals("error-code", 6, message.getErrorCode());
     43 
     44         assertEquals("crealm", "MY.REALM", message.getCrealm());
     45         assertEquals("cname", new PrincipalName(PrincipalName.NT_PRINCIPAL,
     46                 new String[] { "no_such_user" }), message.getCname());
     47 
     48         assertEquals("realm", "MY.REALM", message.getRealm());
     49         assertEquals("sname", new PrincipalName(PrincipalName.NT_UNKNOWN,
     50                 new String[] { "krbtgt", "MY.REALM" }), message.getSname());
     51 
     52         assertEquals("etext", "e_text_string", message.getEtext());
     53     }
     54 
     55     // testing array was created by hands according to RFC4120
     56     public static byte[] err_resp = new byte[] {
     57     // KRB-ERROR ::= [APPLICATION 30]
     58             (byte) 0x7e,
     59             (byte) 0x81,
     60             (byte) 0xA9,
     61 
     62             // SEQUENCE
     63             (byte) 0x30,
     64             (byte) 0x81,
     65             (byte) 0xA6,
     66 
     67             // pvno [0] INTEGER (5)
     68             (byte) 0xa0,
     69             (byte) 0x03,
     70             //
     71             (byte) 0x02,
     72             (byte) 0x01,
     73             (byte) 0x05,
     74 
     75             // msg-type [1] INTEGER (30)
     76             (byte) 0xA1,
     77             (byte) 0x03,
     78             //
     79             (byte) 0x02,
     80             (byte) 0x01,
     81             (byte) 0x1e,
     82 
     83             // ctime [2] KerberosTime OPTIONAL,
     84             (byte) 0xA2,
     85             (byte) 0x11,
     86             //
     87             (byte) 0x18,
     88             (byte) 0x0f,
     89             (byte) 0x31,
     90             (byte) 0x39,
     91             (byte) 0x37,
     92             (byte) 0x30,
     93             (byte) 0x30,
     94             (byte) 0x31,
     95             (byte) 0x30,
     96             (byte) 0x31,
     97             (byte) 0x30,
     98             (byte) 0x30,
     99             (byte) 0x30,
    100             (byte) 0x30,
    101             (byte) 0x30,
    102             (byte) 0x31,
    103             (byte) 0x5A,
    104 
    105             // cusec [3] Microseconds OPTIONAL,
    106             (byte) 0xA3,
    107             (byte) 0x05,
    108             //
    109             (byte) 0x02,
    110             (byte) 0x03,
    111             (byte) 0x01,
    112             (byte) 0x00,
    113             (byte) 0x00,
    114 
    115             // stime [4] KerberosTime,
    116             (byte) 0xA4,
    117             (byte) 0x11,
    118             //
    119             (byte) 0x18,
    120             (byte) 0x0f,
    121             (byte) 0x31,
    122             (byte) 0x39,
    123             (byte) 0x37,
    124             (byte) 0x30,
    125             (byte) 0x30,
    126             (byte) 0x31,
    127             (byte) 0x30,
    128             (byte) 0x31,
    129             (byte) 0x30,
    130             (byte) 0x30,
    131             (byte) 0x30,
    132             (byte) 0x30,
    133             (byte) 0x30,
    134             (byte) 0x30,
    135             (byte) 0x5A,
    136 
    137             // susec [5] Microseconds
    138             (byte) 0xa5,
    139             (byte) 0x05,
    140             //
    141             (byte) 0x02,
    142             (byte) 0x03,
    143             (byte) 0x01,
    144             (byte) 0x01,
    145             (byte) 0x01,
    146 
    147             // error-code [6] Int32
    148             (byte) 0xa6,
    149             (byte) 0x03,
    150             //
    151             (byte) 0x02,
    152             (byte) 0x01,
    153             (byte) 0x06,
    154 
    155             // crealm [7] Realm OPTIONAL
    156             (byte) 0xa7,
    157             (byte) 0x0a,
    158             //
    159             (byte) 0x1b,
    160             (byte) 0x08,
    161             (byte) 0x4d,
    162             (byte) 0x59,
    163             (byte) 0x2e,
    164             (byte) 0x52,
    165             (byte) 0x45,
    166             (byte) 0x41,
    167             (byte) 0x4c,
    168             (byte) 0x4d,
    169 
    170             // cname [8] PrincipalName OPTIONAL
    171             (byte) 0xa8,
    172             (byte) 0x19,
    173             // SEQUENCE
    174             (byte) 0x30,
    175             (byte) 0x17,
    176             // name-type
    177             (byte) 0xa0,
    178             (byte) 0x03,
    179             //
    180             (byte) 0x02,
    181             (byte) 0x01,
    182             (byte) 0x01,
    183             // name-string
    184             (byte) 0xa1,
    185             (byte) 0x10,
    186             // SEQUENCE OF
    187             (byte) 0x30,
    188             (byte) 0x0e,
    189             // 1-st string
    190             (byte) 0x1b,
    191             (byte) 0x0c,
    192             (byte) 0x6e,
    193             (byte) 0x6f,
    194             (byte) 0x5f,
    195             (byte) 0x73,
    196             (byte) 0x75,
    197             (byte) 0x63,
    198             (byte) 0x68,
    199             (byte) 0x5f,
    200             (byte) 0x75,
    201             (byte) 0x73,
    202             (byte) 0x65,
    203             (byte) 0x72,
    204 
    205             // realm [9] Realm -- service realm --,
    206             (byte) 0xa9,
    207             (byte) 0x0a,
    208             //
    209             (byte) 0x1b,
    210             (byte) 0x08,
    211             (byte) 0x4d,
    212             (byte) 0x59,
    213             (byte) 0x2e,
    214             (byte) 0x52,
    215             (byte) 0x45,
    216             (byte) 0x41,
    217             (byte) 0x4c,
    218             (byte) 0x4d,
    219 
    220             // sname [10] PrincipalName -- service name --,
    221             (byte) 0xaa,
    222             (byte) 0x1d,
    223             // SEQUENCE
    224             (byte) 0x30,
    225             (byte) 0x1b,
    226             // name-type
    227             (byte) 0xa0,
    228             (byte) 0x03,
    229             //
    230             (byte) 0x02,
    231             (byte) 0x01,
    232             (byte) 0x00,
    233             // name-string
    234             (byte) 0xa1,
    235             (byte) 0x14,
    236             // SEQUENCE OF
    237             (byte) 0x30,
    238             (byte) 0x12,
    239             // 1-st string
    240             (byte) 0x1b,
    241             (byte) 0x06,
    242             (byte) 0x6b,
    243             (byte) 0x72,
    244             (byte) 0x62,
    245             (byte) 0x74,
    246             (byte) 0x67,
    247             (byte) 0x74,
    248             // 2-nd string
    249             (byte) 0x1b,
    250             (byte) 0x08,
    251             (byte) 0x4d,
    252             (byte) 0x59,
    253             (byte) 0x2e,
    254             (byte) 0x52,
    255             (byte) 0x45,
    256             (byte) 0x41,
    257             (byte) 0x4c,
    258             (byte) 0x4d,
    259 
    260             // e-text [11] KerberosString OPTIONAL
    261             (byte) 0xab,
    262             (byte) 0x0f,
    263             (byte) 0x1b,
    264             (byte) 0x0d,
    265             (byte) 0x65,
    266             (byte) 0x5f,
    267             (byte) 0x74,
    268             (byte) 0x65,
    269             (byte) 0x78,
    270             (byte) 0x74,
    271             (byte) 0x5f,
    272             (byte) 0x73,
    273             (byte) 0x74,
    274             (byte) 0x72,
    275             (byte) 0x69,
    276             (byte) 0x6e,
    277             (byte) 0x67,
    278 
    279     // e-data [12] OCTET STRING OPTIONAL: TODO add me for testing
    280     };
    281 
    282 }
    283