Search in sources :

Example 1 with IdentityScopeSubclass

use of org.apache.harmony.security.tests.java.security.IdentityScope2Test.IdentityScopeSubclass in project robovm by robovm.

the class Identity2Test method test_certificates.

/**
     * java.security.Identity#certificates()
     */
public void test_certificates() throws Exception {
    IdentitySubclass sub = new IdentitySubclass("test", new IdentityScopeSubclass());
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    X509Certificate[] cert = new X509Certificate[1];
    cert[0] = (X509Certificate) cf.generateCertificate(certArray);
    sub.setPublicKey(cert[0].getPublicKey());
    CertificateImpl certImpl = new CertificateImpl(cert[0]);
    sub.addCertificate(certImpl);
    java.security.Certificate[] certs = sub.certificates();
    assertEquals("Certificate not contained in the identity", certs[0], certImpl);
}
Also used : IdentityScopeSubclass(org.apache.harmony.security.tests.java.security.IdentityScope2Test.IdentityScopeSubclass) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.Certificate)

Example 2 with IdentityScopeSubclass

use of org.apache.harmony.security.tests.java.security.IdentityScope2Test.IdentityScopeSubclass in project robovm by robovm.

the class Identity2Test method test_getPublicKey.

/**
     * java.security.Identity#getPublicKey()
     */
public void test_getPublicKey() throws Exception {
    IdentitySubclass sub = new IdentitySubclass("test", new IdentityScopeSubclass());
    sub.setPublicKey(getPubKey());
    PublicKey returnedPubKey = sub.getPublicKey();
    assertEquals("Wrong PublicKey returned", getPubKey(), returnedPubKey);
}
Also used : IdentityScopeSubclass(org.apache.harmony.security.tests.java.security.IdentityScope2Test.IdentityScopeSubclass) PublicKey(java.security.PublicKey)

Example 3 with IdentityScopeSubclass

use of org.apache.harmony.security.tests.java.security.IdentityScope2Test.IdentityScopeSubclass in project robovm by robovm.

the class Identity2Test method test_getScope.

/**
     * java.security.Identity#getScope()
     */
public void test_getScope() throws Exception {
    IdentityScope scope = new IdentityScopeSubclass();
    IdentitySubclass sub = new IdentitySubclass("test", scope);
    IdentityScope returnedScope = sub.getScope();
    assertEquals("Wrong Scope returned", scope, returnedScope);
}
Also used : IdentityScopeSubclass(org.apache.harmony.security.tests.java.security.IdentityScope2Test.IdentityScopeSubclass) IdentityScope(java.security.IdentityScope)

Example 4 with IdentityScopeSubclass

use of org.apache.harmony.security.tests.java.security.IdentityScope2Test.IdentityScopeSubclass in project robovm by robovm.

the class Identity2Test method testSetInfo.

/**
     * java.security.Identity#setInfo(String)
     */
public void testSetInfo() throws Exception {
    String[] info = { "This is the general information.", "test", "", null };
    IdentitySubclass sub = new IdentitySubclass("test", new IdentityScopeSubclass());
    for (int i = 0; i < info.length; i++) {
        try {
            sub.setInfo(info[i]);
            assertEquals("Wrong Info returned", info[i], sub.getInfo());
        } catch (Exception e) {
            fail("Unexpected exception for parameter " + info[i]);
        }
    }
}
Also used : IdentityScopeSubclass(org.apache.harmony.security.tests.java.security.IdentityScope2Test.IdentityScopeSubclass) KeyManagementException(java.security.KeyManagementException)

Example 5 with IdentityScopeSubclass

use of org.apache.harmony.security.tests.java.security.IdentityScope2Test.IdentityScopeSubclass in project robovm by robovm.

the class Identity2Test method test_ConstructorLjava_lang_StringLjava_security_IdentityScope.

/**
     * java.security.Identity#Identity(java.lang.String,
     *        java.security.IdentityScope)
     */
public void test_ConstructorLjava_lang_StringLjava_security_IdentityScope() throws Exception {
    String nameNull = null;
    String[] str = { "test", "", "!@#$%^&*()", "identity name" };
    IdentityScopeSubclass iss = new IdentityScopeSubclass("name");
    IdentitySubclass is;
    for (int i = 0; i < str.length; i++) {
        try {
            is = new IdentitySubclass(str[i], new IdentityScopeSubclass());
            assertNotNull(is);
            assertTrue(is instanceof Identity);
        } catch (Exception e) {
            System.out.println(e);
            fail("Unexpected exception for parameter " + str[i]);
        }
    }
    try {
        is = new IdentitySubclass(nameNull, new IdentityScopeSubclass());
    } catch (NullPointerException npe) {
    } catch (Exception e) {
        fail("Incorrect exception " + e + " was thrown");
    }
    try {
        is = new IdentitySubclass("test", iss);
        is = new IdentitySubclass("test", iss);
        fail("KeyManagementException was not thrown");
    } catch (KeyManagementException expected) {
    }
}
Also used : IdentityScopeSubclass(org.apache.harmony.security.tests.java.security.IdentityScope2Test.IdentityScopeSubclass) Identity(java.security.Identity) KeyManagementException(java.security.KeyManagementException) KeyManagementException(java.security.KeyManagementException)

Aggregations

IdentityScopeSubclass (org.apache.harmony.security.tests.java.security.IdentityScope2Test.IdentityScopeSubclass)10 KeyManagementException (java.security.KeyManagementException)3 CertificateFactory (java.security.cert.CertificateFactory)3 X509Certificate (java.security.cert.X509Certificate)3 PublicKey (java.security.PublicKey)2 AndroidOnly (dalvik.annotation.AndroidOnly)1 Certificate (java.security.Certificate)1 Identity (java.security.Identity)1 IdentityScope (java.security.IdentityScope)1