Search in sources :

Example 1 with FiVRKSignCertificateProfileInfo

use of ee.ria.xroad.common.certificateprofile.impl.FiVRKSignCertificateProfileInfo in project X-Road by nordic-institute.

the class CertificateAuthorityServiceTest method getCertificateProfile.

@Test
public void getCertificateProfile() throws Exception {
    ClientType client = new ClientType();
    client.setIdentifier(COMMON_OWNER_ID);
    when(clientRepository.getAllLocalClients()).thenReturn(Collections.singletonList(client));
    // test handling of profile info parameters:
    // private final SecurityServerId serverId;
    // private final ClientId clientId; (sign only)
    // private final String memberName;
    CertificateProfileInfo profile = certificateAuthorityService.getCertificateProfile("fi-not-auth-only", KeyUsageInfo.SIGNING, COMMON_OWNER_ID, false);
    assertTrue(profile instanceof FiVRKSignCertificateProfileInfo);
    assertEquals("FI/SS1/GOV", profile.getSubjectFields()[2].getDefaultValue());
    assertEquals("M1", profile.getSubjectFields()[3].getDefaultValue());
    assertTrue(profile.getSubjectFields()[3].isReadOnly());
    profile = certificateAuthorityService.getCertificateProfile("fi-not-auth-only", KeyUsageInfo.AUTHENTICATION, COMMON_OWNER_ID, false);
    assertTrue(profile instanceof FiVRKAuthCertificateProfileInfo);
    assertEquals("FI/SS1/GOV", profile.getSubjectFields()[2].getDefaultValue());
    assertEquals("", profile.getSubjectFields()[3].getDefaultValue());
    assertFalse(profile.getSubjectFields()[3].isReadOnly());
    profile = certificateAuthorityService.getCertificateProfile("est-auth-only", KeyUsageInfo.AUTHENTICATION, COMMON_OWNER_ID, false);
    assertTrue(profile instanceof AuthCertificateProfileInfo);
    assertEquals(0, profile.getSubjectFields().length);
    // exceptions
    try {
        certificateAuthorityService.getCertificateProfile("est-auth-only", KeyUsageInfo.SIGNING, COMMON_OWNER_ID, false);
        fail("should have thrown exception");
    } catch (WrongKeyUsageException expected) {
    }
    try {
        certificateAuthorityService.getCertificateProfile("this-does-not-exist", KeyUsageInfo.SIGNING, COMMON_OWNER_ID, false);
        fail("should have thrown exception");
    } catch (CertificateAuthorityNotFoundException expected) {
    }
    // cant instantiate
    List<ApprovedCAInfo> approvedCAInfos = new ArrayList<>();
    approvedCAInfos.add(new ApprovedCAInfo("provider-class-does-not-exist", false, "ee.ria.xroad.common.certificateprofile.impl.NonExistentProvider"));
    when(globalConfFacade.getApprovedCAs(any())).thenReturn(approvedCAInfos);
    try {
        certificateAuthorityService.getCertificateProfile("provider-class-does-not-exist", KeyUsageInfo.SIGNING, COMMON_OWNER_ID, false);
        fail("should have thrown exception");
    } catch (CertificateProfileInstantiationException expected) {
    }
}
Also used : ClientType(ee.ria.xroad.common.conf.serverconf.model.ClientType) ApprovedCAInfo(ee.ria.xroad.common.conf.globalconf.ApprovedCAInfo) ArrayList(java.util.ArrayList) AuthCertificateProfileInfo(ee.ria.xroad.common.certificateprofile.AuthCertificateProfileInfo) FiVRKSignCertificateProfileInfo(ee.ria.xroad.common.certificateprofile.impl.FiVRKSignCertificateProfileInfo) CertificateProfileInfo(ee.ria.xroad.common.certificateprofile.CertificateProfileInfo) FiVRKAuthCertificateProfileInfo(ee.ria.xroad.common.certificateprofile.impl.FiVRKAuthCertificateProfileInfo) FiVRKSignCertificateProfileInfo(ee.ria.xroad.common.certificateprofile.impl.FiVRKSignCertificateProfileInfo) FiVRKAuthCertificateProfileInfo(ee.ria.xroad.common.certificateprofile.impl.FiVRKAuthCertificateProfileInfo) AuthCertificateProfileInfo(ee.ria.xroad.common.certificateprofile.AuthCertificateProfileInfo) FiVRKAuthCertificateProfileInfo(ee.ria.xroad.common.certificateprofile.impl.FiVRKAuthCertificateProfileInfo) Test(org.junit.Test)

Aggregations

AuthCertificateProfileInfo (ee.ria.xroad.common.certificateprofile.AuthCertificateProfileInfo)1 CertificateProfileInfo (ee.ria.xroad.common.certificateprofile.CertificateProfileInfo)1 FiVRKAuthCertificateProfileInfo (ee.ria.xroad.common.certificateprofile.impl.FiVRKAuthCertificateProfileInfo)1 FiVRKSignCertificateProfileInfo (ee.ria.xroad.common.certificateprofile.impl.FiVRKSignCertificateProfileInfo)1 ApprovedCAInfo (ee.ria.xroad.common.conf.globalconf.ApprovedCAInfo)1 ClientType (ee.ria.xroad.common.conf.serverconf.model.ClientType)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1