Skip to content

Commit

Permalink
Merge f138671 into 1610e29
Browse files Browse the repository at this point in the history
  • Loading branch information
elyscape committed Apr 29, 2016
2 parents 1610e29 + f138671 commit 30e2fb5
Showing 1 changed file with 131 additions and 48 deletions.
179 changes: 131 additions & 48 deletions test/integration/router_test.go
Expand Up @@ -422,6 +422,28 @@ func TestRouterPathSpecificity(t *testing.T) {

now := unversioned.Now()

protocols := []struct {
name string
port string
}{
{
name: "http",
port: "80",
},
{
name: "https",
port: "443",
},
{
name: "ws",
port: "80",
},
{
name: "wss",
port: "443",
},
}

//create path based route
endpointEvent := &watch.Event{
Type: watch.Added,
Expand All @@ -447,6 +469,13 @@ func TestRouterPathSpecificity(t *testing.T) {
To: kapi.ObjectReference{
Name: "myService",
},
TLS: &routeapi.TLSConfig{
Termination: routeapi.TLSTerminationEdge,
Certificate: tr.ExampleCert,
Key: tr.ExampleKey,
CACertificate: tr.ExampleCACert,
InsecureEdgeTerminationPolicy: routeapi.InsecureEdgeTerminationPolicyAllow,
},
},
},
}
Expand All @@ -457,16 +486,18 @@ func TestRouterPathSpecificity(t *testing.T) {
fakeMasterAndPod.EndpointChannel <- eventString(endpointEvent)
fakeMasterAndPod.RouteChannel <- eventString(routeEvent)

//ensure you can curl path but not main host
if err := waitForRoute(routeTestAddress, "www.example.com", "http", nil, tr.HelloPodPath); err != nil {
t.Fatalf("unexpected response: %q", err)
}
if _, err := getRoute(routeAddress, "www.example.com", "http", nil, ""); err != ErrUnavailable {
t.Fatalf("unexpected response: %q", err)
}
//ensure you can curl path with port in Host header
if err := waitForRoute(routeTestAddress, "www.example.com:80", "http", nil, tr.HelloPodPath); err != nil {
t.Fatalf("unexpected response: %q", err)
for _, proto := range protocols {
//ensure you can curl path but not main host
if err := waitForRoute(routeTestAddress, "www.example.com", proto.name, nil, tr.HelloPodPath); err != nil {
t.Fatalf("unexpected response with protocol %s (port %s): %q", proto.name, proto.port, err)
}
if _, err := getRoute(routeAddress, "www.example.com", proto.name, nil, ""); err != ErrUnavailable {
t.Fatalf("unexpected response with protocol %s (port %s): %q", proto.name, proto.port, err)
}
//ensure you can curl path with port in Host header
if err := waitForRoute(routeTestAddress, "www.example.com:"+proto.port, proto.name, nil, tr.HelloPodPath); err != nil {
t.Fatalf("unexpected response with protocol %s (port %s): %q", proto.name, proto.port, err)
}
}

//create newer, conflicting path based route
Expand Down Expand Up @@ -494,17 +525,26 @@ func TestRouterPathSpecificity(t *testing.T) {
To: kapi.ObjectReference{
Name: "altService",
},
TLS: &routeapi.TLSConfig{
Termination: routeapi.TLSTerminationEdge,
Certificate: tr.ExampleCert,
Key: tr.ExampleKey,
CACertificate: tr.ExampleCACert,
InsecureEdgeTerminationPolicy: routeapi.InsecureEdgeTerminationPolicyAllow,
},
},
},
}
fakeMasterAndPod.EndpointChannel <- eventString(endpointEvent)
fakeMasterAndPod.RouteChannel <- eventString(routeEvent)

if err := waitForRoute(routeTestAddress, "www.example.com", "http", nil, tr.HelloPodPath); err != nil {
t.Fatalf("unexpected response: %q", err)
}
if err := waitForRoute(routeTestAddress, "www.example.com:80", "http", nil, tr.HelloPodPath); err != nil {
t.Fatalf("unexpected response: %q", err)
for _, proto := range protocols {
if err := waitForRoute(routeTestAddress, "www.example.com", proto.name, nil, tr.HelloPodPath); err != nil {
t.Fatalf("unexpected response with protocol %s (port %s): %q", proto.name, proto.port, err)
}
if err := waitForRoute(routeTestAddress, "www.example.com:"+proto.port, proto.name, nil, tr.HelloPodPath); err != nil {
t.Fatalf("unexpected response with protocol %s (port %s): %q", proto.name, proto.port, err)
}
}

//create host based route
Expand All @@ -521,20 +561,29 @@ func TestRouterPathSpecificity(t *testing.T) {
To: kapi.ObjectReference{
Name: "myService",
},
TLS: &routeapi.TLSConfig{
Termination: routeapi.TLSTerminationEdge,
Certificate: tr.ExampleCert,
Key: tr.ExampleKey,
CACertificate: tr.ExampleCACert,
InsecureEdgeTerminationPolicy: routeapi.InsecureEdgeTerminationPolicyAllow,
},
},
},
}
fakeMasterAndPod.RouteChannel <- eventString(routeEvent)

//ensure you can curl path and host
if err := waitForRoute(routeTestAddress, "www.example.com", "http", nil, tr.HelloPodPath); err != nil {
t.Fatalf("unexpected response: %q", err)
}
if err := waitForRoute(routeAddress, "www.example.com", "http", nil, tr.HelloPod); err != nil {
t.Fatalf("unexpected response: %q", err)
}
if err := waitForRoute(routeTestAddress, "www.example.com:80", "http", nil, tr.HelloPodPath); err != nil {
t.Fatalf("unexpected response: %q", err)
for _, proto := range protocols {
//ensure you can curl path and host
if err := waitForRoute(routeTestAddress, "www.example.com", proto.name, nil, tr.HelloPodPath); err != nil {
t.Fatalf("unexpected response with protocol %s (port %s): %q", proto.name, proto.port, err)
}
if err := waitForRoute(routeAddress, "www.example.com", proto.name, nil, tr.HelloPod); err != nil {
t.Fatalf("unexpected response with protocol %s (port %s): %q", proto.name, proto.port, err)
}
if err := waitForRoute(routeTestAddress, "www.example.com:"+proto.port, proto.name, nil, tr.HelloPodPath); err != nil {
t.Fatalf("unexpected response with protocol %s (port %s): %q", proto.name, proto.port, err)
}
}

//delete path based route
Expand All @@ -551,6 +600,13 @@ func TestRouterPathSpecificity(t *testing.T) {
To: kapi.ObjectReference{
Name: "myService",
},
TLS: &routeapi.TLSConfig{
Termination: routeapi.TLSTerminationEdge,
Certificate: tr.ExampleCert,
Key: tr.ExampleKey,
CACertificate: tr.ExampleCACert,
InsecureEdgeTerminationPolicy: routeapi.InsecureEdgeTerminationPolicyAllow,
},
},
},
}
Expand All @@ -562,14 +618,16 @@ func TestRouterPathSpecificity(t *testing.T) {
// same service, and that that service varies its response in accordance with
// the path, so we still get the tr.HelloPodPath response when we request
// /test even though we request using routeAddress.
if err := waitForRoute(routeTestAddress, "www.example.com", "http", nil, tr.HelloPodPath); err != nil {
t.Fatalf("unexpected response: %q", err)
}
if err := waitForRoute(routeAddress, "www.example.com", "http", nil, tr.HelloPod); err != nil {
t.Fatalf("unexpected response: %q", err)
}
if err := waitForRoute(routeTestAddress, "www.example.com:80", "http", nil, tr.HelloPodPath); err != nil {
t.Fatalf("unexpected response: %q", err)
for _, proto := range protocols {
if err := waitForRoute(routeTestAddress, "www.example.com", proto.name, nil, tr.HelloPodPath); err != nil {
t.Fatalf("unexpected response with protocol %s (port %s): %q", proto.name, proto.port, err)
}
if err := waitForRoute(routeAddress, "www.example.com", proto.name, nil, tr.HelloPod); err != nil {
t.Fatalf("unexpected response with protocol %s (port %s): %q", proto.name, proto.port, err)
}
if err := waitForRoute(routeTestAddress, "www.example.com:"+proto.port, proto.name, nil, tr.HelloPodPath); err != nil {
t.Fatalf("unexpected response with protocol %s (port %s): %q", proto.name, proto.port, err)
}
}

// create newer, conflicting host based route that is ignored
Expand All @@ -586,19 +644,28 @@ func TestRouterPathSpecificity(t *testing.T) {
To: kapi.ObjectReference{
Name: "altService",
},
TLS: &routeapi.TLSConfig{
Termination: routeapi.TLSTerminationEdge,
Certificate: tr.ExampleCert,
Key: tr.ExampleKey,
CACertificate: tr.ExampleCACert,
InsecureEdgeTerminationPolicy: routeapi.InsecureEdgeTerminationPolicyAllow,
},
},
},
}
fakeMasterAndPod.RouteChannel <- eventString(routeEvent)

if err := waitForRoute(routeTestAddress, "www.example.com", "http", nil, tr.HelloPodPath); err != nil {
t.Fatalf("unexpected response: %q", err)
}
if err := waitForRoute(routeAddress, "www.example.com", "http", nil, tr.HelloPod); err != nil {
t.Fatalf("unexpected response: %q", err)
}
if err := waitForRoute(routeTestAddress, "www.example.com:80", "http", nil, tr.HelloPodPath); err != nil {
t.Fatalf("unexpected response: %q", err)
for _, proto := range protocols {
if err := waitForRoute(routeTestAddress, "www.example.com", proto.name, nil, tr.HelloPodPath); err != nil {
t.Fatalf("unexpected response with protocol %s (port %s): %q", proto.name, proto.port, err)
}
if err := waitForRoute(routeAddress, "www.example.com", proto.name, nil, tr.HelloPod); err != nil {
t.Fatalf("unexpected response with protocol %s (port %s): %q", proto.name, proto.port, err)
}
if err := waitForRoute(routeTestAddress, "www.example.com:"+proto.port, proto.name, nil, tr.HelloPodPath); err != nil {
t.Fatalf("unexpected response with protocol %s (port %s): %q", proto.name, proto.port, err)
}
}

//create old, conflicting host based route which should take over the route
Expand All @@ -615,19 +682,28 @@ func TestRouterPathSpecificity(t *testing.T) {
To: kapi.ObjectReference{
Name: "altService",
},
TLS: &routeapi.TLSConfig{
Termination: routeapi.TLSTerminationEdge,
Certificate: tr.ExampleCert,
Key: tr.ExampleKey,
CACertificate: tr.ExampleCACert,
InsecureEdgeTerminationPolicy: routeapi.InsecureEdgeTerminationPolicyAllow,
},
},
},
}
fakeMasterAndPod.RouteChannel <- eventString(routeEvent)

if err := waitForRoute(routeTestAddress, "www.example.com", "http", nil, tr.HelloPodAlternate); err != nil {
t.Fatalf("unexpected response: %q", err)
}
if err := waitForRoute(routeAddress, "www.example.com", "http", nil, tr.HelloPodAlternate); err != nil {
t.Fatalf("unexpected response: %q", err)
}
if err := waitForRoute(routeTestAddress, "www.example.com:80", "http", nil, tr.HelloPodAlternate); err != nil {
t.Fatalf("unexpected response: %q", err)
for _, proto := range protocols {
if err := waitForRoute(routeTestAddress, "www.example.com", proto.name, nil, tr.HelloPodAlternate); err != nil {
t.Fatalf("unexpected response with protocol %s (port %s): %q", proto.name, proto.port, err)
}
if err := waitForRoute(routeAddress, "www.example.com", proto.name, nil, tr.HelloPodAlternate); err != nil {
t.Fatalf("unexpected response with protocol %s (port %s): %q", proto.name, proto.port, err)
}
if err := waitForRoute(routeTestAddress, "www.example.com:"+proto.port, proto.name, nil, tr.HelloPodAlternate); err != nil {
t.Fatalf("unexpected response with protocol %s (port %s): %q", proto.name, proto.port, err)
}
}

// Clean up the host-based route and endpoint.
Expand All @@ -643,6 +719,13 @@ func TestRouterPathSpecificity(t *testing.T) {
To: kapi.ObjectReference{
Name: "myService",
},
TLS: &routeapi.TLSConfig{
Termination: routeapi.TLSTerminationEdge,
Certificate: tr.ExampleCert,
Key: tr.ExampleKey,
CACertificate: tr.ExampleCACert,
InsecureEdgeTerminationPolicy: routeapi.InsecureEdgeTerminationPolicyAllow,
},
},
},
}
Expand Down

0 comments on commit 30e2fb5

Please sign in to comment.