### Question:
DefaultCAServer implements CertificateServer { @VisibleForTesting Consumer<SecurityConfig> processVerificationStatus( VerificationStatus status) { Consumer<SecurityConfig> consumer = null; switch (status) { case SUCCESS: consumer = (arg) -> LOG.info("CertificateServer validation is " + "successful"); break; case MISSING_KEYS: consumer = (arg) -> { LOG.error("We have found the Certificate for this CertificateServer, " + "but keys used by this CertificateServer is missing. This is a " + "non-recoverable error. Please restart the system after locating " + "the Keys used by the CertificateServer."); LOG.error("Exiting due to unrecoverable CertificateServer error."); throw new IllegalStateException("Missing Keys, cannot continue."); }; break; case MISSING_CERTIFICATE: consumer = (arg) -> { LOG.error("We found the keys, but the root certificate for this " + "CertificateServer is missing. Please restart SCM after locating " + "the " + "Certificates."); LOG.error("Exiting due to unrecoverable CertificateServer error."); throw new IllegalStateException("Missing Root Certs, cannot continue."); }; break; case INITIALIZE: consumer = (arg) -> { try { generateSelfSignedCA(arg); } catch (NoSuchProviderException | NoSuchAlgorithmException | IOException e) { LOG.error("Unable to initialize CertificateServer.", e); } VerificationStatus newStatus = verifySelfSignedCA(arg); if (newStatus != VerificationStatus.SUCCESS) { LOG.error("Unable to initialize CertificateServer, failed in " + "verification."); } }; break; default: break; } return consumer; } DefaultCAServer(String subject, String clusterID, String scmID,
                         CertificateStore certificateStore); @Override void init(SecurityConfig securityConfig, CAType type); @Override X509CertificateHolder getCACertificate(); @Override X509Certificate getCertificate(String certSerialId); @Override Future<X509CertificateHolder> requestCertificate(
      PKCS10CertificationRequest csr,
      CertificateApprover.ApprovalType approverType); @Override Future<X509CertificateHolder> requestCertificate(String csr,
      CertificateApprover.ApprovalType type); @Override Future<Boolean> revokeCertificate(X509Certificate certificate,
      CertificateApprover.ApprovalType approverType);  }### Answer:
@Test public void testMissingCertificate() { SecurityConfig securityConfig = new SecurityConfig(conf); CertificateServer testCA = new DefaultCAServer("testCA", RandomStringUtils.randomAlphabetic(4), RandomStringUtils.randomAlphabetic(4), caStore); Consumer<SecurityConfig> caInitializer = ((DefaultCAServer) testCA).processVerificationStatus( DefaultCAServer.VerificationStatus.MISSING_CERTIFICATE); try { caInitializer.accept(securityConfig); fail("code should not reach here, exception should have been thrown."); } catch (IllegalStateException e) { assertTrue(e.toString().contains("Missing Root Certs")); } }
@Test public void testMissingKey() { SecurityConfig securityConfig = new SecurityConfig(conf); CertificateServer testCA = new DefaultCAServer("testCA", RandomStringUtils.randomAlphabetic(4), RandomStringUtils.randomAlphabetic(4), caStore); Consumer<SecurityConfig> caInitializer = ((DefaultCAServer) testCA).processVerificationStatus( DefaultCAServer.VerificationStatus.MISSING_KEYS); try { caInitializer.accept(securityConfig); fail("code should not reach here, exception should have been thrown."); } catch (IllegalStateException e) { assertTrue(e.toString().contains("Missing Keys")); } }