Search in sources :

Example 6 with IdentityScopeSubclass

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

the class Identity2Test method test_removeCertificateLjava_security_Certificate.

/**
     * java.security.Identity#removeCertificate(java.security.Certificate)
     */
@AndroidOnly("Spec says: Removing unknown certificates throw an exception. " + "The RI ignores unknown certificates.")
public void test_removeCertificateLjava_security_Certificate() 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);
    try {
        sub.removeCertificate(null);
        fail("Test 1: KeyManagementException expected.");
    } catch (KeyManagementException expected) {
    }
    assertEquals("Test 2: Certificate should not have been removed.", 1, sub.certificates().length);
    sub.removeCertificate(certImpl);
    assertEquals("Test 3: Certificate has not been removed.", 0, sub.certificates().length);
    // Removing the same certificate a second time should fail.
    try {
        sub.removeCertificate(certImpl);
        fail("Test 4: KeyManagementException expected.");
    } catch (KeyManagementException expected) {
    }
}
Also used : IdentityScopeSubclass(org.apache.harmony.security.tests.java.security.IdentityScope2Test.IdentityScopeSubclass) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate) KeyManagementException(java.security.KeyManagementException) AndroidOnly(dalvik.annotation.AndroidOnly)

Example 7 with IdentityScopeSubclass

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

the class Identity2Test method test_equalsLjava_lang_Object.

/**
     * java.security.Identity#equals(java.lang.Object)
     */
public void test_equalsLjava_lang_Object() 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);
    IdentitySubclass sub2 = new IdentitySubclass("test", new IdentityScopeSubclass());
    IdentitySubclass sub3 = new IdentitySubclass("identity name", new IdentityScopeSubclass());
    assertEquals("the two Identity objects are not equal", sub2, sub);
    assertEquals(sub, sub2);
    assertFalse(sub.equals(sub3));
}
Also used : IdentityScopeSubclass(org.apache.harmony.security.tests.java.security.IdentityScope2Test.IdentityScopeSubclass) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate)

Example 8 with IdentityScopeSubclass

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

the class Identity2Test method test_getName.

/**
     * java.security.Identity#getName()
     */
public void test_getName() throws Exception {
    String name = "test";
    IdentitySubclass sub = new IdentitySubclass(name, new IdentityScopeSubclass());
    assertEquals("Wrong Name returned", name, sub.getName());
}
Also used : IdentityScopeSubclass(org.apache.harmony.security.tests.java.security.IdentityScope2Test.IdentityScopeSubclass)

Example 9 with IdentityScopeSubclass

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

the class Identity2Test method test_getInfo.

/**
     * java.security.Identity#getInfo()
     */
public void test_getInfo() throws Exception {
    String info = "This is the general information.";
    IdentitySubclass sub = new IdentitySubclass("test", new IdentityScopeSubclass());
    sub.setInfo(info);
    assertEquals("Wrong Info returned", info, sub.getInfo());
}
Also used : IdentityScopeSubclass(org.apache.harmony.security.tests.java.security.IdentityScope2Test.IdentityScopeSubclass)

Example 10 with IdentityScopeSubclass

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

the class Identity2Test method testSetPublicKey.

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

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