Skip to content

Commit

Permalink
test/e2e: Nil check before assertion on succeeded request (#4080)
Browse files Browse the repository at this point in the history
Log message uses status code from response which might be nil

Signed-off-by: Sunjay Bhatia <sunjayb@vmware.com>
  • Loading branch information
sunjayBhatia authored Oct 6, 2021
1 parent 88d678b commit ec04b41
Show file tree
Hide file tree
Showing 21 changed files with 61 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/e2e/gateway/gateway_allow_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func testGatewayAllowType(namespace string) {
Path: "/gateway-in-allowed-list",
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)
body := f.GetEchoResponseBody(res.Body)
assert.Equal(t, "echo-blue", body.Service)
Expand Down Expand Up @@ -132,6 +133,7 @@ func testGatewayAllowType(namespace string) {
Path: "/gateway-not-in-allowed-list",
Condition: e2e.HasStatusCode(404),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 404 response code, got %d", res.StatusCode)

// This route allows gateways in the same namespace, and the actual
Expand Down Expand Up @@ -174,6 +176,7 @@ func testGatewayAllowType(namespace string) {
Path: "/gateway-in-same-namespace",
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)

// This route allows gateways in the same namespace, and the actual
Expand Down Expand Up @@ -219,6 +222,7 @@ func testGatewayAllowType(namespace string) {
Path: "/gateway-not-in-same-namespace",
Condition: e2e.HasStatusCode(404),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 404 response code, got %d", res.StatusCode)
})
}
1 change: 1 addition & 0 deletions test/e2e/gateway/host_rewrite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func testHostRewrite(namespace string) {
Host: string(route.Spec.Hostnames[0]),
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)
body := f.GetEchoResponseBody(res.Body)
assert.Equal(t, "echo", body.Service)
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/gateway/request_header_modifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func testRequestHeaderModifierForwardTo(namespace string) {
},
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)
body := f.GetEchoResponseBody(res.Body)
assert.Equal(t, "echo-header-filter", body.Service)
Expand All @@ -130,6 +131,7 @@ func testRequestHeaderModifierForwardTo(namespace string) {
},
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)
body = f.GetEchoResponseBody(res.Body)
assert.Equal(t, "echo-header-nofilter", body.Service)
Expand Down Expand Up @@ -223,6 +225,7 @@ func testRequestHeaderModifierRule(namespace string) {
},
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)
body := f.GetEchoResponseBody(res.Body)
assert.Equal(t, "echo-header-filter", body.Service)
Expand All @@ -244,6 +247,7 @@ func testRequestHeaderModifierRule(namespace string) {
},
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)
body = f.GetEchoResponseBody(res.Body)
assert.Equal(t, "echo-header-nofilter", body.Service)
Expand Down
1 change: 1 addition & 0 deletions test/e2e/gateway/tls_wildcard_host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func testTLSWildcardHost(namespace string) {
},
Condition: e2e.HasStatusCode(tc.wantStatus),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected %d response code, got %d", tc.wantStatus, res.StatusCode)
}
})
Expand Down
1 change: 1 addition & 0 deletions test/e2e/httpproxy/dynamic_headers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func testDynamicHeaders(namespace string) {
Host: p.Spec.VirtualHost.Fqdn,
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)

body := f.GetEchoResponseBody(res.Body)
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/httpproxy/external_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ func testExternalAuth(namespace string) {
Path: "/first",
Condition: e2e.HasStatusCode(401),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 401 response code, got %d", res.StatusCode)

// The `testserver` authorization server will accept any request with
Expand All @@ -242,6 +243,7 @@ func testExternalAuth(namespace string) {
Path: "/first/allow",
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)

body := f.GetEchoResponseBody(res.Body)
Expand All @@ -254,6 +256,7 @@ func testExternalAuth(namespace string) {
Path: "/second",
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)

// The default route should not authorize by default.
Expand All @@ -262,6 +265,7 @@ func testExternalAuth(namespace string) {
Path: "/matches-default-route",
Condition: e2e.HasStatusCode(401),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 401 response code, got %d", res.StatusCode)

// The `testserver` authorization server will accept any request with
Expand All @@ -273,6 +277,7 @@ func testExternalAuth(namespace string) {
Path: "/matches-default-route/allow",
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)

body = f.GetEchoResponseBody(res.Body)
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/httpproxy/external_name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func testExternalNameServiceInsecure(namespace string) {
Host: p.Spec.VirtualHost.Fqdn,
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)
})
}
Expand Down Expand Up @@ -160,6 +161,7 @@ func testExternalNameServiceTLS(namespace string) {
Host: p.Spec.VirtualHost.Fqdn,
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)
})
}
Expand Down
14 changes: 14 additions & 0 deletions test/e2e/httpproxy/global_rate_limiting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func testGlobalRateLimitingVirtualHostNonTLS(namespace string) {
Host: p.Spec.VirtualHost.Fqdn,
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)

require.NoError(t, retry.RetryOnConflict(retry.DefaultBackoff, func() error {
Expand Down Expand Up @@ -96,6 +97,7 @@ func testGlobalRateLimitingVirtualHostNonTLS(namespace string) {
Host: p.Spec.VirtualHost.Fqdn,
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)

// Make another request against the proxy, confirm a 429 response
Expand All @@ -104,6 +106,7 @@ func testGlobalRateLimitingVirtualHostNonTLS(namespace string) {
Host: p.Spec.VirtualHost.Fqdn,
Condition: e2e.HasStatusCode(429),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 429 response code, got %d", res.StatusCode)
})
}
Expand Down Expand Up @@ -156,6 +159,7 @@ func testGlobalRateLimitingRouteNonTLS(namespace string) {
Host: p.Spec.VirtualHost.Fqdn,
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)

// Add a global rate limit policy on the first route.
Expand Down Expand Up @@ -190,6 +194,7 @@ func testGlobalRateLimitingRouteNonTLS(namespace string) {
Host: p.Spec.VirtualHost.Fqdn,
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)

// Make another request against the proxy, confirm a 429 response
Expand All @@ -198,6 +203,7 @@ func testGlobalRateLimitingRouteNonTLS(namespace string) {
Host: p.Spec.VirtualHost.Fqdn,
Condition: e2e.HasStatusCode(429),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 429 response code, got %d", res.StatusCode)

// Make a request against the route that doesn't have rate limiting
Expand All @@ -207,6 +213,7 @@ func testGlobalRateLimitingRouteNonTLS(namespace string) {
Path: "/unlimited",
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code for non-rate-limited route, got %d", res.StatusCode)
})
}
Expand Down Expand Up @@ -250,6 +257,7 @@ func testGlobalRateLimitingVirtualHostTLS(namespace string) {
Host: p.Spec.VirtualHost.Fqdn,
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)

// Add a global rate limit policy on the virtual host.
Expand Down Expand Up @@ -283,6 +291,7 @@ func testGlobalRateLimitingVirtualHostTLS(namespace string) {
Host: p.Spec.VirtualHost.Fqdn,
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)

// Make another request against the proxy, confirm a 429 response
Expand All @@ -291,6 +300,7 @@ func testGlobalRateLimitingVirtualHostTLS(namespace string) {
Host: p.Spec.VirtualHost.Fqdn,
Condition: e2e.HasStatusCode(429),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 429 response code, got %d", res.StatusCode)
})
}
Expand Down Expand Up @@ -347,6 +357,7 @@ func testGlobalRateLimitingRouteTLS(namespace string) {
Host: p.Spec.VirtualHost.Fqdn,
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)

// Add a global rate limit policy on the first route.
Expand Down Expand Up @@ -380,6 +391,7 @@ func testGlobalRateLimitingRouteTLS(namespace string) {
Host: p.Spec.VirtualHost.Fqdn,
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)

// Make another request against the proxy, confirm a 429 response
Expand All @@ -388,6 +400,7 @@ func testGlobalRateLimitingRouteTLS(namespace string) {
Host: p.Spec.VirtualHost.Fqdn,
Condition: e2e.HasStatusCode(429),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 429 response code, got %d", res.StatusCode)

// Make a request against the route that doesn't have rate limiting
Expand All @@ -397,6 +410,7 @@ func testGlobalRateLimitingRouteTLS(namespace string) {
Path: "/unlimited",
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code for non-rate-limited route, got %d", res.StatusCode)
})
}
1 change: 1 addition & 0 deletions test/e2e/httpproxy/host_header_rewrite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func testHostHeaderRewrite(namespace string) {
Host: p.Spec.VirtualHost.Fqdn,
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)

assert.Equal(t, "rewritten.com", f.GetEchoResponseBody(res.Body).Host)
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/httpproxy/http_health_checks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func testHTTPHealthChecks(namespace string) {
Host: p.Spec.VirtualHost.Fqdn,
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)

// set the health check policy to always fail
Expand All @@ -82,6 +83,7 @@ func testHTTPHealthChecks(namespace string) {
Host: p.Spec.VirtualHost.Fqdn,
Condition: e2e.HasStatusCode(503),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 503 response code, got %d", res.StatusCode)

// set the health check policy to always pass
Expand All @@ -103,6 +105,7 @@ func testHTTPHealthChecks(namespace string) {
Host: p.Spec.VirtualHost.Fqdn,
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)
})
}
2 changes: 2 additions & 0 deletions test/e2e/httpproxy/https_fallback_certificate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func testHTTPSFallbackCertificate(namespace string) {
Host: p.Spec.VirtualHost.Fqdn,
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected a 200 response code, got %d", res.StatusCode)

assert.Equal(t, "echo", f.GetEchoResponseBody(res.Body).Service)
Expand All @@ -80,6 +81,7 @@ func testHTTPSFallbackCertificate(namespace string) {
},
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected a 200 response code, got %d", res.StatusCode)
})
}
4 changes: 4 additions & 0 deletions test/e2e/httpproxy/https_misdirected_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func testHTTPSMisdirectedRequest(namespace string) {
Host: p.Spec.VirtualHost.Fqdn,
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)

assert.Equal(t, "echo", f.GetEchoResponseBody(res.Body).Service)
Expand All @@ -77,6 +78,7 @@ func testHTTPSMisdirectedRequest(namespace string) {
},
Condition: e2e.HasStatusCode(421),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 421 (Misdirected Request) response code, got %d", res.StatusCode)

// The virtual host name is port-insensitive, so verify that we can
Expand All @@ -88,6 +90,7 @@ func testHTTPSMisdirectedRequest(namespace string) {
},
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)

// Verify that the hostname match is case-insensitive.
Expand All @@ -100,6 +103,7 @@ func testHTTPSMisdirectedRequest(namespace string) {
},
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)
})
}
3 changes: 3 additions & 0 deletions test/e2e/httpproxy/https_sni_enforcement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func testHTTPSSNIEnforcement(namespace string) {
Path: "/https-sni-enforcement",
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)

assert.Equal(t, "echo-one", f.GetEchoResponseBody(res.Body).Service)
Expand Down Expand Up @@ -104,6 +105,7 @@ func testHTTPSSNIEnforcement(namespace string) {
Path: "/https-sni-enforcement",
Condition: e2e.HasStatusCode(200),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 200 response code, got %d", res.StatusCode)

assert.Equal(t, "echo-two", f.GetEchoResponseBody(res.Body).Service)
Expand All @@ -118,6 +120,7 @@ func testHTTPSSNIEnforcement(namespace string) {
},
Condition: e2e.HasStatusCode(421),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 421 (Misdirected Request) response code, got %d", res.StatusCode)
})
}
Loading

0 comments on commit ec04b41

Please sign in to comment.