001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Alexander V. Esin
020: * @version $Revision$
021: */package javax.security.auth.x500;
022:
023: import java.math.BigInteger;
024: import java.security.InvalidKeyException;
025: import java.security.NoSuchAlgorithmException;
026: import java.security.NoSuchProviderException;
027: import java.security.Principal;
028: import java.security.PrivateKey;
029: import java.security.PublicKey;
030: import java.security.SignatureException;
031: import java.security.cert.CertificateEncodingException;
032: import java.security.cert.CertificateException;
033: import java.security.cert.X509Certificate;
034: import java.util.Date;
035: import java.util.Set;
036:
037: import junit.framework.TestCase;
038:
039: /**
040: * Tests implementation of X500PrivateCredential class
041: */
042: @SuppressWarnings("serial")
043: public class X500PrivateCredentialTest extends TestCase {
044:
045: X509Certificate cert = new X509Certificate() {
046: @Override
047: public void checkValidity() {
048: }
049:
050: @Override
051: public void checkValidity(Date date) {
052: }
053:
054: @Override
055: public int getVersion() {
056: return 0;
057: }
058:
059: @Override
060: public BigInteger getSerialNumber() {
061: return null;
062: }
063:
064: @Override
065: public Principal getIssuerDN() {
066: return null;
067: }
068:
069: @Override
070: public Principal getSubjectDN() {
071: return null;
072: }
073:
074: @Override
075: public Date getNotBefore() {
076: return null;
077: }
078:
079: @Override
080: public Date getNotAfter() {
081: return null;
082: }
083:
084: @Override
085: public byte[] getTBSCertificate()
086: throws CertificateEncodingException {
087: return null;
088: }
089:
090: @Override
091: public byte[] getSignature() {
092: return null;
093: }
094:
095: @Override
096: public String getSigAlgName() {
097: return null;
098: }
099:
100: @Override
101: public String getSigAlgOID() {
102: return null;
103: }
104:
105: @Override
106: public byte[] getSigAlgParams() {
107: return null;
108: }
109:
110: @Override
111: public boolean[] getIssuerUniqueID() {
112: return null;
113: }
114:
115: @Override
116: public boolean[] getSubjectUniqueID() {
117: return null;
118: }
119:
120: @Override
121: public boolean[] getKeyUsage() {
122: return null;
123: }
124:
125: @Override
126: public int getBasicConstraints() {
127: return 0;
128: }
129:
130: @Override
131: public byte[] getEncoded() throws CertificateEncodingException {
132: return null;
133: }
134:
135: @Override
136: public void verify(PublicKey key) throws CertificateException,
137: NoSuchAlgorithmException, InvalidKeyException,
138: NoSuchProviderException, SignatureException {
139: }
140:
141: @Override
142: public void verify(PublicKey key, String sigProvider)
143: throws CertificateException, NoSuchAlgorithmException,
144: InvalidKeyException, NoSuchProviderException,
145: SignatureException {
146: }
147:
148: @Override
149: public String toString() {
150: return null;
151: }
152:
153: @Override
154: public PublicKey getPublicKey() {
155: return null;
156: }
157:
158: public Set<String> getCriticalExtensionOIDs() {
159: return null;
160: }
161:
162: public byte[] getExtensionValue(String oid) {
163: return null;
164: }
165:
166: public Set<String> getNonCriticalExtensionOIDs() {
167: return null;
168: }
169:
170: public boolean hasUnsupportedCriticalExtension() {
171: return false;
172: }
173: };
174:
175: PrivateKey key = new PrivateKey() {
176: public String getAlgorithm() {
177: return null;
178: }
179:
180: public String getFormat() {
181: return null;
182: }
183:
184: public byte[] getEncoded() {
185: return null;
186: }
187:
188: };
189:
190: public void testGetCert() {
191: X500PrivateCredential cred = new X500PrivateCredential(cert,
192: key);
193: X509Certificate c = cred.getCertificate();
194: assertNotNull(c);
195: }
196:
197: public void testGetKey() {
198: X500PrivateCredential cred = new X500PrivateCredential(cert,
199: key);
200: PrivateKey k = cred.getPrivateKey();
201: assertNotNull(k);
202: }
203:
204: public void testIsDestroyed() {
205: X500PrivateCredential cred = new X500PrivateCredential(cert,
206: key);
207: cred.destroy();
208: assertTrue(cred.isDestroyed());
209: }
210:
211: public void testDestroy() {
212: X500PrivateCredential cred = new X500PrivateCredential(cert,
213: key);
214: cred.destroy();
215: String al = cred.getAlias();
216: assertNull(al);
217: }
218:
219: public void testGetAlias() {
220: X500PrivateCredential cred = new X500PrivateCredential(cert,
221: key, "ALIAS");
222: String al = cred.getAlias();
223: assertEquals("ALIAS", al);
224: }
225:
226: public void testIllegalArg() {
227: try {
228: new X500PrivateCredential(cert, key, null);
229: fail("No IllegalArgumentException on null value");
230: } catch (IllegalArgumentException e) {
231: //ignore
232: }
233: }
234:
235: public void testIllegalArg_0() {
236: try {
237: new X500PrivateCredential(cert, null, null);
238: fail("No IllegalArgumentException on null value");
239: } catch (IllegalArgumentException e) {
240: //ignore
241: }
242: }
243:
244: public void testIllegalArg_1() {
245: try {
246: new X500PrivateCredential(null, key, "");
247: fail("No IllegalArgumentException on null value");
248: } catch (IllegalArgumentException e) {
249: //ignore
250: }
251: }
252: }
|