-
Notifications
You must be signed in to change notification settings - Fork 679
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test/e2e: add HTTPProxy tests 001, 011 (#3667)
Updates #3621. Signed-off-by: Steve Kriss <krisss@vmware.com>
- Loading branch information
Showing
3 changed files
with
217 additions
and
0 deletions.
There are no files selected for viewing
150 changes: 150 additions & 0 deletions
150
test/e2e/httpproxy/001_required_field_validation_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
// Copyright Project Contour Authors | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// +build e2e | ||
|
||
package httpproxy | ||
|
||
import ( | ||
"context" | ||
|
||
contourv1 "github.com/projectcontour/contour/apis/projectcontour/v1" | ||
"github.com/projectcontour/contour/test/e2e" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
) | ||
|
||
func testRequiredFieldValidation(fx *e2e.Framework) { | ||
t := fx.T() | ||
ns := "001-required-field-validation" | ||
|
||
fx.CreateNamespace(ns) | ||
defer fx.DeleteNamespace(ns) | ||
|
||
// This HTTPProxy is expressed as an Unstructured because the JSON | ||
// tags for the relevant field do not include "omitempty", so when | ||
// a typed Go struct is serialized to JSON the field *is* included | ||
// and therefore does not fail validation. | ||
missingConditionHeaderName := &unstructured.Unstructured{ | ||
Object: map[string]interface{}{ | ||
"apiVersion": "projectcontour.io/v1", | ||
"kind": "HTTPProxy", | ||
"metadata": map[string]interface{}{ | ||
"name": "missing-condition-header-name", | ||
"namespace": ns, | ||
}, | ||
"spec": map[string]interface{}{ | ||
"routes": []map[string]interface{}{ | ||
{ | ||
"conditions": []map[string]interface{}{ | ||
{ | ||
"header": map[string]interface{}{ | ||
"present": true, | ||
}, | ||
}, | ||
}, | ||
"services": []map[string]interface{}{ | ||
{ | ||
"name": "foo", | ||
"port": 80, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
err := fx.Client.Create(context.TODO(), missingConditionHeaderName) | ||
require.Error(t, err) | ||
assert.Contains(t, err.Error(), "spec.routes.conditions.header.name: Required value") | ||
|
||
// This HTTPProxy is expressed as an Unstructured because the JSON | ||
// tags for the relevant field do not include "omitempty", so when | ||
// a typed Go struct is serialized to JSON the field *is* included | ||
// and therefore does not fail validation. | ||
missingVirtualHostName := &unstructured.Unstructured{ | ||
Object: map[string]interface{}{ | ||
"apiVersion": "projectcontour.io/v1", | ||
"kind": "HTTPProxy", | ||
"metadata": map[string]interface{}{ | ||
"name": "missing-virtualhost-name", | ||
"namespace": ns, | ||
}, | ||
"spec": map[string]interface{}{ | ||
"virtualhost": map[string]interface{}{ | ||
"tls": map[string]interface{}{ | ||
"passthrough": true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
err = fx.Client.Create(context.TODO(), missingVirtualHostName) | ||
require.Error(t, err) | ||
assert.Contains(t, err.Error(), "spec.virtualhost.fqdn: Required value") | ||
|
||
// This HTTPProxy is expressed as an Unstructured because the JSON | ||
// tags for the relevant field do not include "omitempty", so when | ||
// a typed Go struct is serialized to JSON the field *is* included | ||
// and therefore does not fail validation. | ||
missingIncludesName := &unstructured.Unstructured{ | ||
Object: map[string]interface{}{ | ||
"apiVersion": "projectcontour.io/v1", | ||
"kind": "HTTPProxy", | ||
"metadata": map[string]interface{}{ | ||
"name": "missing-includes-name", | ||
"namespace": ns, | ||
}, | ||
"spec": map[string]interface{}{ | ||
"includes": []map[string]interface{}{ | ||
{ | ||
"namespace": "foo", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
err = fx.Client.Create(context.TODO(), missingIncludesName) | ||
require.Error(t, err) | ||
assert.Contains(t, err.Error(), "spec.includes.name: Required value") | ||
|
||
servicePortRange := &contourv1.HTTPProxy{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: ns, | ||
Name: "service-port-range", | ||
}, | ||
Spec: contourv1.HTTPProxySpec{ | ||
VirtualHost: &contourv1.VirtualHost{ | ||
Fqdn: "ports.projectcontour.io", | ||
}, | ||
Routes: []contourv1.Route{ | ||
{ | ||
Services: []contourv1.Service{ | ||
{ | ||
Name: "any-service-name", | ||
Port: 80000, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
err = fx.Client.Create(context.TODO(), servicePortRange) | ||
require.Error(t, err) | ||
assert.Contains(t, err.Error(), "spec.routes.services.port: Invalid value") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright Project Contour Authors | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// +build e2e | ||
|
||
package httpproxy | ||
|
||
import ( | ||
"context" | ||
|
||
contourv1 "github.com/projectcontour/contour/apis/projectcontour/v1" | ||
"github.com/projectcontour/contour/test/e2e" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func testRetryPolicyValidation(fx *e2e.Framework) { | ||
t := fx.T() | ||
ns := "011-retry-policy-validation" | ||
|
||
fx.CreateNamespace(ns) | ||
defer fx.DeleteNamespace(ns) | ||
|
||
p := &contourv1.HTTPProxy{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: ns, | ||
Name: "invalid-retry-on-condition", | ||
}, | ||
Spec: contourv1.HTTPProxySpec{ | ||
Routes: []contourv1.Route{ | ||
{ | ||
Services: []contourv1.Service{ | ||
{ | ||
Name: "foo", | ||
Port: 80, | ||
}, | ||
}, | ||
RetryPolicy: &contourv1.RetryPolicy{ | ||
RetryOn: []contourv1.RetryOn{ | ||
"foobar", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
err := fx.Client.Create(context.TODO(), p) | ||
require.Error(t, err) | ||
assert.Contains(t, err.Error(), "spec.routes.retryPolicy.retryOn: Unsupported value") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters