use of java.security.cert.CertPath in project robovm by robovm.
the class CertPathValidatorExceptionTest method testCertPathValidatorException13.
/**
* Test for
* <code>CertPathValidatorException(String, Throwable, CertPath, int)</code>
* constructor Assertion: constructs CertPathValidatorException when
* <code>cause</code> not null <code>msg</code> not null
* <code>certPath</code> not null <code>index</code>< -1 || >=
* certPath.getCertificates().size() throws: IndexOutOfBoundsException
*/
public void testCertPathValidatorException13() {
myCertPath mcp = new myCertPath("X.509", "");
CertPath cp = mcp.get("X.509");
int[] indx = { -2, -100, 0, 1, 100, Integer.MAX_VALUE, Integer.MIN_VALUE };
for (int j = 0; j < indx.length; j++) {
for (int i = 0; i < msgs.length; i++) {
try {
new CertPathValidatorException(msgs[i], tCause, cp, indx[j]);
fail("IndexOutOfBoundsException was not thrown as expected. " + " msg: " + msgs[i] + ", certPath is null and index is " + indx[j]);
} catch (IndexOutOfBoundsException e) {
}
}
}
}
use of java.security.cert.CertPath in project robovm by robovm.
the class CertPathValidatorExceptionTest method testCertPathValidatorException16.
/**
* Test for <code>getIndex()</code>. Returns the index of the certificate
* in the certification path that caused the exception to be thrown. Note
* that the list of certificates in a CertPath is zero based. If no index
* has been set, -1 is returned.
*/
public void testCertPathValidatorException16() {
CertPathValidatorException tE = new CertPathValidatorException();
assertEquals("getIndex() must be equals -1", -1, tE.getIndex());
for (int i = 0; i < msgs.length; i++) {
tE = new CertPathValidatorException(msgs[i]);
assertEquals("getIndex() must be equals -1", -1, tE.getIndex());
}
Throwable cause = null;
tE = new CertPathValidatorException(cause);
assertEquals("getIndex() must be equals -1", -1, tE.getIndex());
tE = new CertPathValidatorException(tCause);
assertEquals("getIndex() must be equals -1", -1, tE.getIndex());
for (int i = 0; i < msgs.length; i++) {
tE = new CertPathValidatorException(msgs[i], tCause);
assertEquals("getIndex() must be equals -1", -1, tE.getIndex());
}
tE = new CertPathValidatorException(null, null, null, -1);
assertEquals("getIndex() must be equals -1", -1, tE.getIndex());
myCertPath mcp = new myCertPath("X.509", "");
CertPath cp = mcp.get("X.509");
for (int i = 0; i < msgs.length; i++) {
try {
tE = new CertPathValidatorException(msgs[i], tCause, cp, -1);
assertNotNull("getIndex() must not return null", tE.getCertPath());
assertEquals("getIndex() must return ".concat(cp.toString()), tE.getCertPath(), cp);
} catch (IndexOutOfBoundsException e) {
fail("Unexpected IndexOutOfBoundsException was thrown. " + e.getMessage());
}
}
}
use of java.security.cert.CertPath in project robovm by robovm.
the class CertPathValidatorSpiTest method testCertPathValidatorSpi01.
/**
* Test for <code>CertPathValidatorSpi</code> constructor Assertion:
* constructs CertPathValidatorSpi
*/
public void testCertPathValidatorSpi01() throws CertPathValidatorException, InvalidAlgorithmParameterException {
CertPathValidatorSpi certPathValid = new MyCertPathValidatorSpi();
CertPathParameters params = null;
CertPath certPath = null;
CertPathValidatorResult cpvResult = certPathValid.engineValidate(certPath, params);
assertNull("Not null CertPathValidatorResult", cpvResult);
try {
certPathValid.engineValidate(certPath, params);
fail("CertPathValidatorException must be thrown");
} catch (CertPathValidatorException e) {
}
try {
certPathValid.engineValidate(certPath, params);
fail("InvalidAlgorithmParameterException must be thrown");
} catch (InvalidAlgorithmParameterException e) {
}
}
use of java.security.cert.CertPath in project robovm by robovm.
the class myCertificateFactory method testCertificateFactory15.
/**
* Test for <code>generateCertPath(List certificates)</code> method
* Assertion: returns empty CertPath if certificates is empty
*/
public void testCertificateFactory15() throws CertificateException {
if (!X509Support) {
fail(NotSupportMsg);
return;
}
CertificateFactory[] certFs = initCertFs();
assertNotNull("CertificateFactory objects were not created", certFs);
List<Certificate> list = new Vector<Certificate>();
for (int i = 0; i < certFs.length; i++) {
CertPath cp = certFs[i].generateCertPath(list);
List<? extends Certificate> list1 = cp.getCertificates();
assertTrue("List should be empty", list1.isEmpty());
}
}
use of java.security.cert.CertPath in project robovm by robovm.
the class CertificateFactory2Test method checkResult.
private void checkResult(CertificateFactory certFactory, boolean mode) throws CertificateException, CRLException {
MyCertificateFactorySpi.putMode(mode);
ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]);
DataInputStream dis = new DataInputStream(bais);
try {
certFactory.generateCertPath(bais);
fail("CertificateException must be thrown");
} catch (CertificateException e) {
}
try {
certFactory.generateCertPath(dis);
if (!mode) {
fail("CertificateException must be thrown because encodings list is empty");
}
} catch (CertificateException e) {
if (mode) {
fail("Unexpected CertificateFactoryException was thrown");
}
}
try {
certFactory.generateCertPath(bais, "aa");
fail("CertificateException must be thrown");
} catch (CertificateException e) {
}
try {
certFactory.generateCertPath(dis, "");
if (mode) {
fail("IllegalArgumentException must be thrown");
}
} catch (IllegalArgumentException e) {
if (!mode) {
fail("Unexpected IllegalArgumentException was thrown");
}
}
certFactory.generateCertPath(dis, "ss");
try {
certFactory.generateCertificate(bais);
fail("CertificateException must be thrown");
} catch (CertificateException e) {
}
try {
certFactory.generateCertificates(null);
fail("CertificateException must be thrown");
} catch (CertificateException e) {
}
Certificate cert = certFactory.generateCertificate(dis);
assertNull("Result must be null", cert);
Collection<? extends Certificate> col = certFactory.generateCertificates(dis);
assertNull("Result must be null", col);
try {
certFactory.generateCRL(bais);
fail("CRLException must be thrown");
} catch (CRLException e) {
}
try {
certFactory.generateCRLs(null);
fail("CRLException must be thrown");
} catch (CRLException e) {
}
CRL crl = certFactory.generateCRL(dis);
assertNull("Result must be null", crl);
Collection<? extends CRL> colc = certFactory.generateCRLs(dis);
assertNull("Result must be null", colc);
List<Certificate> list = null;
CertPath cp;
try {
cp = certFactory.generateCertPath(list);
if (mode) {
fail("NullPointerException must be thrown");
} else {
assertNull("Must be null", cp);
}
} catch (NullPointerException e) {
if (!mode) {
fail("Unexpected NullPointerException was thrown");
}
}
Iterator<String> it = certFactory.getCertPathEncodings();
if (mode) {
assertTrue(it.hasNext());
} else {
assertFalse(it.hasNext());
}
}
Aggregations