Handle HTTPS from config

Change-Id: I48ea5ea2e35e62906b7b5ec5c5e624d06192172b
This commit is contained in:
Piotr Fus 2018-02-26 10:39:34 +01:00
parent 76a3ecacad
commit d070ea820b
2 changed files with 13 additions and 5 deletions

View file

@ -14,6 +14,7 @@ import pl.touk.mockserver.api.request.AddMock
import pl.touk.mockserver.client.RemoteMockServer import pl.touk.mockserver.client.RemoteMockServer
import pl.touk.mockserver.client.Util import pl.touk.mockserver.client.Util
import pl.touk.mockserver.server.HttpMockServer import pl.touk.mockserver.server.HttpMockServer
import spock.lang.AutoCleanup
import spock.lang.Shared import spock.lang.Shared
import spock.lang.Specification import spock.lang.Specification
@ -25,6 +26,7 @@ class MockServerHttpsTest extends Specification {
RemoteMockServer remoteMockServer = new RemoteMockServer('localhost', 19000) RemoteMockServer remoteMockServer = new RemoteMockServer('localhost', 19000)
@AutoCleanup('stop')
HttpMockServer httpMockServer = new HttpMockServer(19000) HttpMockServer httpMockServer = new HttpMockServer(19000)
@Shared @Shared
@ -44,10 +46,6 @@ class MockServerHttpsTest extends Specification {
.loadTrustMaterial(trustStore()) .loadTrustMaterial(trustStore())
.build() .build()
def cleanup() {
httpMockServer.stop()
}
def 'should handle HTTPS server' () { def 'should handle HTTPS server' () {
given: given:
remoteMockServer.addMock(new AddMock( remoteMockServer.addMock(new AddMock(

View file

@ -122,7 +122,7 @@ class HttpMockServer {
throw new RuntimeException('mock already registered') throw new RuntimeException('mock already registered')
} }
Mock mock = mockFromConfig(co) Mock mock = mockFromConfig(co)
HttpServerWrapper child = getOrCreateChildServer(mock.port, null) HttpServerWrapper child = getOrCreateChildServer(mock.port, mock.https)
child.addMock(mock) child.addMock(mock)
configuration.put(name, co) configuration.put(name, co)
mockNames << name mockNames << name
@ -172,6 +172,16 @@ class HttpMockServer {
mock.responseHeaders = co.responseHeaders ?: null mock.responseHeaders = co.responseHeaders ?: null
mock.schema = co.schema ?: null mock.schema = co.schema ?: null
mock.preserveHistory = co.preserveHistory != false mock.preserveHistory = co.preserveHistory != false
if (co.https) {
mock.https = new Https(
keystorePath: co.https.keystorePath ?: null,
keystorePassword: co.https.keystorePassword,
keyPassword: co.https.keyPassword,
truststorePath: co.https.truststorePath,
truststorePassword: co.https.truststorePassword,
requireClientAuth: co.https?.requireClientAuth?.asBoolean() ?: false
)
}
return mock return mock
} }