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/** 19* @author Alexander V. Esin 20*/ 21 22package javax.security.auth.x500; 23 24import java.math.BigInteger; 25import java.security.InvalidKeyException; 26import java.security.NoSuchAlgorithmException; 27import java.security.NoSuchProviderException; 28import java.security.Principal; 29import java.security.PrivateKey; 30import java.security.PublicKey; 31import java.security.SignatureException; 32import java.security.cert.CertificateEncodingException; 33import java.security.cert.CertificateException; 34import java.security.cert.X509Certificate; 35import java.util.Date; 36import java.util.Set; 37 38import junit.framework.TestCase; 39/** 40 * Tests implementation of X500PrivateCredential class 41 */ 42@SuppressWarnings("serial") 43public class X500PrivateCredentialTest extends TestCase { 44 45 X509Certificate cert= new X509Certificate() { 46 @Override 47 public void checkValidity(){} 48 @Override 49 public void checkValidity(Date date){} 50 @Override 51 public int getVersion() { 52 return 0; 53 } 54 @Override 55 public BigInteger getSerialNumber() { 56 return null; 57 } 58 @Override 59 public Principal getIssuerDN() { 60 return null; 61 } 62 @Override 63 public Principal getSubjectDN() { 64 return null; 65 } 66 @Override 67 public Date getNotBefore() { 68 return null; 69 } 70 @Override 71 public Date getNotAfter() { 72 return null; 73 } 74 @Override 75 public byte[] getTBSCertificate() throws CertificateEncodingException { 76 return null; 77 } 78 @Override 79 public byte[] getSignature() { 80 return null; 81 } 82 @Override 83 public String getSigAlgName() { 84 return null; 85 } 86 @Override 87 public String getSigAlgOID() { 88 return null; 89 } 90 @Override 91 public byte[] getSigAlgParams() { 92 return null; 93 } 94 @Override 95 public boolean[] getIssuerUniqueID() { 96 return null; 97 } 98 @Override 99 public boolean[] getSubjectUniqueID() { 100 return null; 101 } 102 @Override 103 public boolean[] getKeyUsage() { 104 return null; 105 } 106 @Override 107 public int getBasicConstraints() { 108 return 0; 109 } 110 @Override 111 public byte[] getEncoded() throws CertificateEncodingException { 112 return null; 113 } 114 @Override 115 public void verify(PublicKey key) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException { 116 } 117 @Override 118 public void verify(PublicKey key, String sigProvider) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException { 119 } 120 @Override 121 public String toString() { 122 return null; 123 } 124 @Override 125 public PublicKey getPublicKey() { 126 return null; 127 } 128 public Set<String> getCriticalExtensionOIDs() { 129 return null; 130 } 131 public byte[] getExtensionValue(String oid) { 132 return null; 133 } 134 public Set<String> getNonCriticalExtensionOIDs() { 135 return null; 136 } 137 public boolean hasUnsupportedCriticalExtension() { 138 return false; 139 } 140 }; 141 142 PrivateKey key= new PrivateKey() { 143 public String getAlgorithm() { 144 return null; 145 } 146 147 public String getFormat() { 148 return null; 149 } 150 151 public byte[] getEncoded() { 152 return null; 153 } 154 155 }; 156 public void testGetCert() { 157 X500PrivateCredential cred= new X500PrivateCredential(cert, key); 158 X509Certificate c= cred.getCertificate(); 159 assertNotNull(c); 160 } 161 162 public void testGetKey() { 163 X500PrivateCredential cred= new X500PrivateCredential(cert, key); 164 PrivateKey k= cred.getPrivateKey(); 165 assertNotNull(k); 166 } 167 168 public void testIsDestroyed() { 169 X500PrivateCredential cred= new X500PrivateCredential(cert, key); 170 cred.destroy(); 171 assertTrue(cred.isDestroyed()); 172 } 173 174 public void testDestroy() { 175 X500PrivateCredential cred= new X500PrivateCredential(cert, key); 176 cred.destroy(); 177 String al= cred.getAlias(); 178 assertNull(al); 179 } 180 181 public void testGetAlias() { 182 X500PrivateCredential cred= new X500PrivateCredential(cert, key, "ALIAS"); 183 String al= cred.getAlias(); 184 assertEquals("ALIAS", al); 185 } 186 187 public void testIllegalArg() { 188 try { 189 new X500PrivateCredential(cert, key, null); 190 fail("No IllegalArgumentException on null value"); 191 } 192 catch(IllegalArgumentException e) { 193 //ignore 194 } 195 } 196 197 public void testIllegalArg_0() { 198 try { 199 new X500PrivateCredential(cert, null, null); 200 fail("No IllegalArgumentException on null value"); 201 } 202 catch(IllegalArgumentException e) { 203 //ignore 204 } 205 } 206 207 public void testIllegalArg_1() { 208 try { 209 new X500PrivateCredential(null, key, ""); 210 fail("No IllegalArgumentException on null value"); 211 } 212 catch(IllegalArgumentException e) { 213 //ignore 214 } 215 } 216} 217