@Test
  public void securityCheckerTest() throws Exception {

    GeneralNames subjectAltNames = new GeneralNames(new GeneralName[]{
        new GeneralName(GeneralName.uniformResourceIdentifier,
            "urn:li:servicePrincipal(foo-name;foo-tag;i001)"),
        new GeneralName(GeneralName.dNSName, "ca-00001.foo.com"),
        new GeneralName(GeneralName.iPAddress, "1.1.1.1")});

    //certificate validation success case, channel should not be closed.
    Http2ClientMetrics metrics = new Http2ClientMetrics(new MetricRegistry());
    EmbeddedChannel channel = createChannelSsl(subjectAltNames, "urn:li:servicePrincipal\\(foo-name;foo-tag;.*\\) ?", metrics);
    SslHandler sslHandler = channel.pipeline().get(SslHandler.class);
    Promise<Channel> promise = (Promise<Channel>) sslHandler.handshakeFuture();
    promise.setSuccess(channel);
    assertTrue("channel should not be closed", channel.isActive());
    assertEquals("validation success counter mismatch", 0,
        metrics.http2ServerCertificateValidationFailureCount.getCount());

    //certificate validation is disabled with empty regex, channel should not be closed.
    channel = createChannelSsl(subjectAltNames, "", metrics);
    sslHandler = channel.pipeline().get(SslHandler.class);
    promise = (Promise<Channel>) sslHandler.handshakeFuture();
    promise.setSuccess(channel);
    assertTrue("channel should not be closed", channel.isActive());
    assertEquals("validation success counter mismatch", 0,
        metrics.http2ServerCertificateValidationFailureCount.getCount());

    //certificate validation is disabled with empty regex, channel should not be closed.
    channel = createChannelSsl(subjectAltNames, " ", metrics);
    sslHandler = channel.pipeline().get(SslHandler.class);
    promise = (Promise<Channel>) sslHandler.handshakeFuture();
    promise.setSuccess(channel);
    assertTrue("channel should not be closed", channel.isActive());
    assertEquals("validation success counter mismatch", 0,
        metrics.http2ServerCertificateValidationFailureCount.getCount());

    //security validation failure case (service closed), channel should be closed.
    channel = createChannelSsl(subjectAltNames, "invalid.*", metrics);
    sslHandler = channel.pipeline().get(SslHandler.class);
    promise = (Promise<Channel>) sslHandler.handshakeFuture();
    promise.setSuccess(channel);
    assertTrue("channel should be closed", !channel.isActive());
    assertEquals("validation success counter mismatch", 1,
        metrics.http2ServerCertificateValidationFailureCount.getCount());
  }
Test the code flow where {@link Http2PeerCertificateValidator} waits for the SSL handshake complete event and
apply security policy from channelActive method.
@throws Exception
ambry-network/src/test/java/com/github/ambry/network/http2/Http2PeerCertificateValidatorTest.java