NameTest.java revision e98fbf8686c5289bf03fe5c3de7ff82d3a77104d
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* @author Stepan M. Mishura 19*/ 20 21package org.apache.harmony.security.tests.x501; 22 23import java.io.ByteArrayInputStream; 24 25import org.apache.harmony.security.x501.Name; 26 27 28import junit.framework.TestCase; 29 30/** 31 * Test Name class 32 * 33 * @see http://www.ietf.org/rfc/rfc1779.txt 34 * @see http://www.ietf.org/rfc/rfc2253.txt 35 */ 36public class NameTest extends TestCase { 37 38 private static final byte [] mess = { 39 0x30, //0 seq of 40 (byte) 0x81,(byte) 0x9A, //1 len = 154 41 0x31, 0x0A, //3,4 42 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x5A, 43 0x31, 0x0A, //15,16 44 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x01, 0x45, 45 0x31, 0x0A, 46 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x01, 0x44, 47 0x31, 0x0A, 48 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x01, 0x43, 49 0x31, 0x0A, 50 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x13, 0x01, 0x42, 51 0x31, 0x15, 52 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 53 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41, 54 0x31, 0x0A, 55 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x01, 0x45, 56 0x31, 0x0A, 57 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x01, 0x44, 58 0x31, 0x0A, 59 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x01, 0x43, 60 0x31, 0x0A, 61 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x13, 0x01, 0x42, 62 0x31, 0x15, 63 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 64 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41 65 }; 66 67 public void testGetName1779() throws Exception { 68 69 Name principal = (Name) Name.ASN1.decode(mess); 70 71 String s = principal.getName("RFC1779"); 72 73 assertEquals( 74 "CN=A + ST=CA, O=B, L=C, C=D, OU=E, CN=A + ST=CA, O=B, L=C, C=D, OU=E, CN=Z", 75 s); 76 } 77 78 public void testStreamGetName1779() throws Exception { 79 ByteArrayInputStream is = new ByteArrayInputStream(mess); 80 81 Name principal = (Name) Name.ASN1.decode(is); 82 83 String s = principal.getName("RFC1779"); 84 85 assertEquals( 86 "CN=A + ST=CA, O=B, L=C, C=D, OU=E, CN=A + ST=CA, O=B, L=C, C=D, OU=E, CN=Z", 87 s); 88 } 89} 90