Search in sources :

Example 1 with Configuration

use of org.mockserver.configuration.Configuration in project mockserver by mock-server.

the class CustomKeyAndCertificateFactorySupplierTest method setServerModifier_shouldBeCalled.

@Test
public void setServerModifier_shouldBeCalled() {
    final AtomicBoolean customizerCallFlag = new AtomicBoolean(false);
    NettySslContextFactory.sslServerContextBuilderCustomizer = builder -> {
        customizerCallFlag.set(true);
        return builder;
    };
    new NettySslContextFactory(new Configuration(), mock(MockServerLogger.class), true).createServerSslContext();
    assertTrue(customizerCallFlag.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Configuration(org.mockserver.configuration.Configuration) Test(org.junit.Test)

Example 2 with Configuration

use of org.mockserver.configuration.Configuration in project mockserver by mock-server.

the class CustomKeyAndCertificateFactorySupplierTest method shouldReturnCustomFactory.

@Test
public void shouldReturnCustomFactory() {
    BiFunction<MockServerLogger, Boolean, KeyAndCertificateFactory> originalCustomKeyAndCertificateFactorySupplier = KeyAndCertificateFactoryFactory.getCustomKeyAndCertificateFactorySupplier();
    // given
    Configuration configuration = configuration();
    MockServerLogger mockServerLogger = new MockServerLogger();
    KeyAndCertificateFactory factoryInstance = new KeyAndCertificateFactory() {

        @Override
        public void buildAndSaveCertificateAuthorityPrivateKeyAndX509Certificate() {
        }

        @Override
        public void buildAndSavePrivateKeyAndX509Certificate() {
        }

        @Override
        public boolean certificateNotYetCreated() {
            return false;
        }

        @Override
        public PrivateKey privateKey() {
            return null;
        }

        @Override
        public X509Certificate x509Certificate() {
            return null;
        }

        @Override
        public X509Certificate certificateAuthorityX509Certificate() {
            return null;
        }

        @Override
        public List<X509Certificate> certificateChain() {
            return null;
        }
    };
    try {
        // when
        KeyAndCertificateFactoryFactory.setCustomKeyAndCertificateFactorySupplier((logger, isServer) -> factoryInstance);
        // then
        assertThat(KeyAndCertificateFactoryFactory.createKeyAndCertificateFactory(configuration, mockServerLogger), equalTo(factoryInstance));
    } finally {
        KeyAndCertificateFactoryFactory.setCustomKeyAndCertificateFactorySupplier(originalCustomKeyAndCertificateFactorySupplier);
    }
}
Also used : Configuration(org.mockserver.configuration.Configuration) MockServerLogger(org.mockserver.logging.MockServerLogger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) X509Certificate(java.security.cert.X509Certificate) Test(org.junit.Test)

Example 3 with Configuration

use of org.mockserver.configuration.Configuration in project mockserver by mock-server.

the class CustomKeyAndCertificateFactorySupplierTest method setClientModifier_shouldBeCalled.

@Test
public void setClientModifier_shouldBeCalled() {
    final AtomicBoolean customizerCallFlag = new AtomicBoolean(false);
    NettySslContextFactory.sslClientContextBuilderCustomizer = builder -> {
        customizerCallFlag.set(true);
        return builder;
    };
    new NettySslContextFactory(new Configuration(), mock(MockServerLogger.class), false).createClientSslContext(false);
    assertTrue(customizerCallFlag.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Configuration(org.mockserver.configuration.Configuration) Test(org.junit.Test)

Aggregations

AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 Test (org.junit.Test)3 Configuration (org.mockserver.configuration.Configuration)3 X509Certificate (java.security.cert.X509Certificate)1 MockServerLogger (org.mockserver.logging.MockServerLogger)1