tcp stream (und damit: tls passthrough) ist implementiert
This commit is contained in:
1 parent
6a5cb95f92
commit
fdcd06c93f
16 files changed
+1008
-75
No files matched your search
@@ -0,0 +1,78 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"sultan/pkg/docker"
|
||||
)
|
||||
|
||||
func caLabels() map[string]string {
|
||||
return map[string]string{
|
||||
"traefik.enable": "true",
|
||||
"traefik.tcp.routers.ca.rule": "HostSNI(`ca.lab.kunde.de`)",
|
||||
"traefik.tcp.routers.ca.tls.passthrough": "true",
|
||||
"traefik.tcp.services.ca.loadbalancer.server.port": "9000",
|
||||
}
|
||||
}
|
||||
|
||||
// TLS-Passthrough: Auch TCP-Services zeigen auf den veröffentlichten Host-Port.
|
||||
func TestWorkloads_TCPTranslatesPublishedPort(t *testing.T) {
|
||||
got, _, warnings := Workloads([]docker.Container{ctr("tinyca", caLabels(), pub(9000, 19000))}, "h")
|
||||
if len(warnings) != 0 || len(got) != 1 {
|
||||
t.Fatalf("got=%+v warnings=%v", got, warnings)
|
||||
}
|
||||
if p := got[0].Labels["traefik.tcp.services.ca.loadbalancer.server.port"]; p != "19000" {
|
||||
t.Errorf("Port = %q", p)
|
||||
}
|
||||
|
||||
_, _, warnings = Workloads([]docker.Container{ctr("tinyca", caLabels(), pub(80, 8080))}, "h")
|
||||
if len(warnings) != 1 {
|
||||
t.Errorf("unerreichbarer TCP-Port: Warnungen = %v", warnings)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorkloads_TCPDefaultService(t *testing.T) {
|
||||
labels := map[string]string{"traefik.enable": "true", "traefik.tcp.routers.ca.rule": "HostSNI(`ca.lab.kunde.de`)"}
|
||||
got, _, warnings := Workloads([]docker.Container{ctr("tiny.ca", labels, pub(9000, 19000))}, "h")
|
||||
if len(warnings) != 0 || len(got) != 1 {
|
||||
t.Fatalf("got=%+v warnings=%v", got, warnings)
|
||||
}
|
||||
if got[0].Labels["traefik.tcp.services.tiny-ca.loadbalancer.server.port"] != "19000" {
|
||||
t.Errorf("Default-Service fehlt: %v", got[0].Labels)
|
||||
}
|
||||
if _, ok := got[0].Labels["traefik.http.services.tiny-ca.loadbalancer.server.port"]; ok {
|
||||
t.Error("ohne HTTP-Router kein HTTP-Service")
|
||||
}
|
||||
}
|
||||
|
||||
// HTTP (z. B. Redirect auf :80) und TCP im selben Container.
|
||||
func TestWorkloads_HTTPAndTCP(t *testing.T) {
|
||||
labels := caLabels()
|
||||
labels["traefik.http.routers.ca-http.rule"] = "Host(`ca.lab.kunde.de`)"
|
||||
labels["traefik.http.services.ca-http.loadbalancer.server.port"] = "80"
|
||||
got, _, warnings := Workloads([]docker.Container{ctr("tinyca", labels, pub(80, 8080), pub(9000, 19000))}, "h")
|
||||
if len(warnings) != 0 || len(got) != 1 {
|
||||
t.Fatalf("got=%+v warnings=%v", got, warnings)
|
||||
}
|
||||
l := got[0].Labels
|
||||
if l["traefik.http.services.ca-http.loadbalancer.server.port"] != "8080" || l["traefik.tcp.services.ca.loadbalancer.server.port"] != "19000" {
|
||||
t.Errorf("Labels = %v", l)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorkloads_TCPStoppedIsDown(t *testing.T) {
|
||||
_, down, _ := Workloads([]docker.Container{stopped(ctr("tinyca", caLabels(), pub(9000, 19000)), "exited")}, "h")
|
||||
if !reflect.DeepEqual(down, []string{"ca"}) {
|
||||
t.Errorf("down = %v", down)
|
||||
}
|
||||
|
||||
// Ein laufender Container mit demselben TCP-Router verdrängt den gestoppten.
|
||||
got, down, _ := Workloads([]docker.Container{
|
||||
stopped(ctr("a-alt", caLabels(), pub(9000, 19001)), "exited"),
|
||||
ctr("b-neu", caLabels(), pub(9000, 19000)),
|
||||
}, "h")
|
||||
if len(got) != 1 || got[0].Name != "b-neu" || len(down) != 0 {
|
||||
t.Errorf("got=%+v down=%v", got, down)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user