solution: test ProxyServer

This commit is contained in:
Igor Artamonov
2021-10-27 21:19:32 -04:00
parent 89eec9958a
commit 92657cf635
2 changed files with 106 additions and 6 deletions

View File

@@ -0,0 +1,92 @@
package io.emeraldpay.dshackle.proxy
import io.emeraldpay.dshackle.TlsSetup
import io.emeraldpay.dshackle.config.AuthConfig
import io.emeraldpay.dshackle.config.ProxyConfig
import io.emeraldpay.dshackle.monitoring.accesslog.AccessHandlerHttp
import io.emeraldpay.dshackle.rpc.NativeCall
import io.emeraldpay.dshackle.rpc.NativeSubscribe
import io.emeraldpay.grpc.Chain
import reactor.netty.http.server.HttpServerRoutes
import spock.lang.Specification
class ProxyServerSpec extends Specification {
def "Setup routes"() {
setup:
def config1 = new ProxyConfig()
config1.routes = [
new ProxyConfig.Route("test", Chain.ETHEREUM)
]
def proxyServer = new ProxyServer(
config1,
new ReadRpcJson(), new WriteRpcJson(),
Stub(NativeCall), Stub(NativeSubscribe),
Stub(TlsSetup), new AccessHandlerHttp.NoOpFactory()
)
def routes = Mock(HttpServerRoutes)
when:
proxyServer.setupRoutes(routes)
then:
1 * routes.post("/test", _)
1 * routes.ws("/test", _)
}
def "Setup routes when WS is disabled"() {
setup:
def config1 = new ProxyConfig()
config1.websocketEnabled = false
config1.routes = [
new ProxyConfig.Route("test", Chain.ETHEREUM)
]
def proxyServer = new ProxyServer(
config1,
new ReadRpcJson(), new WriteRpcJson(),
Stub(NativeCall), Stub(NativeSubscribe),
Stub(TlsSetup), new AccessHandlerHttp.NoOpFactory()
)
def routes = Mock(HttpServerRoutes)
when:
proxyServer.setupRoutes(routes)
then:
1 * routes.post("/test", _)
0 * routes.ws(_, _)
}
def "Generate Connect Address"() {
def config1 = new ProxyConfig()
config1.host = "192.168.0.1"
config1.port = 1000
def proxyServer = new ProxyServer(
config1,
new ReadRpcJson(), new WriteRpcJson(),
Stub(NativeCall), Stub(NativeSubscribe),
Stub(TlsSetup), new AccessHandlerHttp.NoOpFactory()
)
when:
def act = proxyServer.connectAddress("http")
then:
act == "http://192.168.0.1:1000"
}
def "Generate Connect Address with TLS"() {
def config1 = new ProxyConfig()
config1.host = "192.168.0.1"
config1.port = 1000
config1.tls = new AuthConfig.ServerTlsAuth()
def proxyServer = new ProxyServer(
config1,
new ReadRpcJson(), new WriteRpcJson(),
Stub(NativeCall), Stub(NativeSubscribe),
Stub(TlsSetup), new AccessHandlerHttp.NoOpFactory()
)
when:
def act = proxyServer.connectAddress("ws")
then:
act == "wss://192.168.0.1:1000"
}
}