@Test
    public void shouldFallbackWhenMultipleAliasesAvailable() throws CertificateException, IOException  {
        config.put(TLSOptions.TLS_TRUSTSTORE, getResourcePath("2waytest/aliased_keys/gateway_ts.jks"));
        config.put(TLSOptions.TLS_TRUSTSTOREPASSWORD, "changeme");
        config.put(TLSOptions.TLS_KEYSTORE, getResourcePath("2waytest/aliased_keys/gateway_ks.jks"));
        config.put(TLSOptions.TLS_KEYSTOREPASSWORD, "changeme");
        config.put(TLSOptions.TLS_KEYPASSWORD, "changeme");
        config.put(TLSOptions.TLS_ALLOWANYHOST, "true");
        config.put(TLSOptions.TLS_ALLOWSELFSIGNED, "true");
        // Only gateway2 is valid. `unrelated` is real but not trusted by API. others don't exist.
        config.put(TLSOptions.TLS_KEYALIASES, "unrelated, owt, or, nowt, gateway, sonorous, unrelated");

        X509Certificate expectedCert;
        try(InputStream inStream = new FileInputStream(getResourcePath("2waytest/aliased_keys/gateway.cer"))) {
            expectedCert = (X509Certificate) CertificateFactory.getInstance("X.509").generateCertificate(inStream);
        }

        HttpConnectorFactory factory = new HttpConnectorFactory(config);
        IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.MTLS, false, new ConnectorConfigImpl());
        IApiConnection connection = connector.connect(request,
            (IAsyncResult<IApiConnectionResponse> result) -> {
                if (result.isError())
                    throw new RuntimeException(result.getError());

                Assert.assertTrue(result.isSuccess());
                // Assert that the expected certificate (associated with the private key by virtue)
                // was the one used.
                Assert.assertEquals(expectedCert.getSerialNumber(), clientSerial);
            });

        connection.end();
    }
Scenario:
  - First alias invalid, second valid.
  - Mutual trust exists between gateway and API.
  - We must fall back to the valid alias.
@throws CertificateException the certificate exception
@throws IOException the IO exception
gateway/platforms/servlet/src/test/java/io/apiman/gateway/platforms/servlet/auth/tls/AliasedCertTest.java