use of java.security.InvalidParameterException in project robovm by robovm.
the class Security2Test method test_getProvidersLjava_lang_String.
/**
* java.security.Security#getProviders(java.lang.String)
*/
public void test_getProvidersLjava_lang_String() {
// Test for method void
// java.security.Security.getProviders(java.lang.String)
Map<String, Integer> allSupported = new HashMap<String, Integer>();
Provider[] allProviders = Security.getProviders();
// Add all non-alias entries to allSupported
for (Provider provider : allProviders) {
for (Object k : provider.keySet()) {
String key = (String) k;
// No aliases and no provider data
if (!isAlias(key) && !isProviderData(key)) {
addOrIncrementTable(allSupported, key);
}
}
// end while more entries
}
// entry that is being aliased.
for (Provider provider : allProviders) {
for (Map.Entry entry : provider.entrySet()) {
String key = (String) entry.getKey();
if (isAlias(key)) {
String aliasName = key.substring("ALG.ALIAS.".length()).toUpperCase();
String realName = aliasName.substring(0, aliasName.indexOf(".") + 1) + entry.getValue();
// aliased are identical. Such entries can occur.
if (!aliasName.equalsIgnoreCase(realName)) {
// Has a real entry been added for aliasName ?
if (allSupported.containsKey(aliasName)) {
// Add 1 to the provider count of the thing being aliased
addOrIncrementTable(allSupported, aliasName);
}
}
}
}
// end while more entries
}
for (String filterString : allSupported.keySet()) {
try {
Provider[] provTest = Security.getProviders(filterString);
int expected = allSupported.get(filterString);
assertEquals("Unexpected number of providers returned for filter " + filterString + ":\n" + allSupported, expected, provTest.length);
} catch (InvalidParameterException e) {
// NO OP
}
}
// exception
try {
Security.getProviders("Signature.SHA1withDSA :512");
fail("InvalidParameterException should be thrown <Signature.SHA1withDSA :512>");
} catch (InvalidParameterException e) {
// Expected
}
}
use of java.security.InvalidParameterException in project robovm by robovm.
the class SecurityTest method test_getProvidersLjava_util_Map.
/**
* java.security.Security#getProviders(java.util.Map)
*/
public void test_getProvidersLjava_util_Map() {
Map<String, String> m = new HashMap<String, String>();
Security.getProviders(m);
assertNull("Not null result on empty map", Security.getProviders(m));
try {
Security.getProviders((Map<String, String>) null);
fail("No expected NullPointerException");
} catch (NullPointerException e) {
}
// key has dot instead of space
m.put("AAA.BBB.CCC", "aaaa");
try {
Security.getProviders(m);
fail("No expected InvalidParameterException");
} catch (InvalidParameterException e) {
}
Provider p = new MyProvider();
try {
Security.addProvider(p);
m.clear();
m.put("MyService.MyAlgorithm", "");
m.put("MessageDigest.SHA-1", "");
assertTrue("MyService.MyAlgorithm", Arrays.equals(new Provider[] { p }, Security.getProviders(m)));
m.clear();
m.put("MyService.MyAlgorithm KeySize", "512");
m.put("MessageDigest.SHA-1", "");
assertTrue("MyService.MyAlgorithm KeySize:512", Arrays.equals(new Provider[] { p }, Security.getProviders(m)));
m.clear();
m.put("MyService.MyAlgorithm KeySize", "1025");
m.put("MessageDigest.SHA-1", "");
assertNull("MyService.MyAlgorithm KeySize:1025", Security.getProviders(m));
// attribute name and value are case insensitive
m.clear();
m.put("MyService.MyAlgorithm imPLementedIn", "softWARE");
assertTrue(Arrays.equals(new Provider[] { p }, Security.getProviders(m)));
m.clear();
m.put("MyService.MyAlgorithm ATTribute", "attributeVALUE");
assertTrue(Arrays.equals(new Provider[] { p }, Security.getProviders(m)));
// Regression for HARMONY-2761
m.clear();
m.put("MyService.NoKeySize KeySize", "512");
assertNull("No KeySize attribute", Security.getProviders(m));
m.clear();
m.put("MyService.NoImplementedIn ImplementedIn", "Software");
assertNull("No ImplementedIn attribute", Security.getProviders(m));
m.clear();
m.put("ABCService.NoAttribute Attribute", "ABC");
assertNull(Security.getProviders(m));
} finally {
// clean up
Security.removeProvider(p.getName());
}
}
use of java.security.InvalidParameterException in project robovm by robovm.
the class SignatureTest method testSetParameterStringObject.
/*
* Class under test for void setParameter(String, Object)
*/
@SuppressWarnings("deprecation")
public void testSetParameterStringObject() {
MySignature1 s = new MySignature1("ABC");
s.setParameter("aaa", new Object());
try {
Signature sig = getTestSignature();
sig.setParameter("TestParam", new Integer(42));
fail("expected InvalidParameterException");
} catch (InvalidParameterException e) {
// expected
} catch (NoSuchAlgorithmException e) {
fail("unexpected: " + e);
}
}
use of java.security.InvalidParameterException in project robovm by robovm.
the class Signature2Test method test_setParameterLjava_security_spec_AlgorithmParameterSpec.
/**
* java.security.Signature#setParameter(java.security.spec.AlgorithmParameterSpec)
*/
public void test_setParameterLjava_security_spec_AlgorithmParameterSpec() throws Exception {
Signature sig = Signature.getInstance("DSA");
try {
DSAParameterSpec spec = new DSAParameterSpec(BigInteger.ONE, BigInteger.ONE, BigInteger.ONE);
sig.setParameter(spec);
} catch (InvalidParameterException e) {
// Could be that it's an invalid param for the found algorithm
} catch (UnsupportedOperationException e) {
// Could be that the operation is not supported
}
}
use of java.security.InvalidParameterException in project robovm by robovm.
the class PKIXBuilderParametersTest method testSetMaxPathLength.
/**
* Test for <code>setMaxPathLength()</code>
*/
public final void testSetMaxPathLength() throws Exception {
KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
keyTest.load(null, null);
ByteArrayInputStream certArray = new ByteArrayInputStream(certificate.getBytes());
ByteArrayInputStream certArray2 = new ByteArrayInputStream(certificate2.getBytes());
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate[] cert = new X509Certificate[2];
cert[0] = (X509Certificate) cf.generateCertificate(certArray);
cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
keyTest.setCertificateEntry("alias1", cert[0]);
keyTest.setCertificateEntry("alias2", cert[0]);
keyTest.setCertificateEntry("alias3", cert[1]);
PKIXBuilderParameters p = new PKIXBuilderParameters(keyTest, new X509CertSelector());
assertEquals(5, p.getMaxPathLength());
p.setMaxPathLength(10);
assertEquals(10, p.getMaxPathLength());
p.setMaxPathLength(0);
assertEquals(0, p.getMaxPathLength());
p.setMaxPathLength(-1);
assertEquals(-1, p.getMaxPathLength());
int[] maxPathLength = { -2, -10, Integer.MIN_VALUE };
for (int i = 0; i < maxPathLength.length; i++) {
try {
p.setMaxPathLength(maxPathLength[i]);
fail("InvalidParameterException expected ");
} catch (InvalidParameterException e) {
// expected
}
}
}
Aggregations