2023-03-28 18:39:22 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-03-28 18:39:22 +00:00
|
|
|
|
2020-03-31 16:59:10 +00:00
|
|
|
package structs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2021-06-23 19:11:23 +00:00
|
|
|
func TestIngressGatewayConfigEntry(t *testing.T) {
|
2021-07-22 18:20:45 +00:00
|
|
|
defaultMeta := DefaultEnterpriseMetaInDefaultPartition()
|
2020-04-16 21:00:48 +00:00
|
|
|
|
2021-06-23 19:11:23 +00:00
|
|
|
cases := map[string]configEntryTestcase{
|
|
|
|
"normalize: empty protocol": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
2020-04-16 21:00:48 +00:00
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "",
|
|
|
|
Services: []IngressService{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
expected: &IngressGatewayConfigEntry{
|
2020-04-16 21:00:48 +00:00
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "tcp",
|
|
|
|
Services: []IngressService{},
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
EnterpriseMeta: *defaultMeta,
|
2020-04-16 21:00:48 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
normalizeOnly: true,
|
2020-04-16 21:00:48 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
"normalize: lowercase protocols": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
2020-04-16 21:00:48 +00:00
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "TCP",
|
|
|
|
Services: []IngressService{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Port: 1112,
|
|
|
|
Protocol: "HtTP",
|
|
|
|
Services: []IngressService{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
expected: &IngressGatewayConfigEntry{
|
2020-04-16 21:00:48 +00:00
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "tcp",
|
|
|
|
Services: []IngressService{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Port: 1112,
|
|
|
|
Protocol: "http",
|
|
|
|
Services: []IngressService{},
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
EnterpriseMeta: *defaultMeta,
|
2020-04-16 21:00:48 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
normalizeOnly: true,
|
2020-04-16 21:00:48 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
"port conflict": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
2020-03-31 16:59:10 +00:00
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "tcp",
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "mysql",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "tcp",
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "postgres",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
validateErr: "port 1111 declared on two listeners",
|
2020-03-31 16:59:10 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
"http features: wildcard": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
2020-03-31 16:59:10 +00:00
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "http",
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "*",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
"http features: wildcard service on invalid protocol": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
2020-03-31 16:59:10 +00:00
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "tcp",
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "*",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
validateErr: "Wildcard service name is only valid for protocol",
|
2020-03-31 16:59:10 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
"http features: multiple services": {
|
2022-05-18 21:55:59 +00:00
|
|
|
entry: &IngressGatewayConfigEntry{
|
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "http",
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "db1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "db2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"http features: multiple services on tcp listener": {
|
2021-06-23 19:11:23 +00:00
|
|
|
entry: &IngressGatewayConfigEntry{
|
2020-03-31 16:59:10 +00:00
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "tcp",
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "db1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "db2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-05-18 21:55:59 +00:00
|
|
|
validateErr: "Multiple services per listener are only supported for L7",
|
2020-03-31 16:59:10 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
// ==========================
|
|
|
|
"tcp listener requires a defined service": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
2020-03-31 16:59:10 +00:00
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "tcp",
|
|
|
|
Services: []IngressService{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
validateErr: "No service declared for listener with port 1111",
|
2020-03-31 16:59:10 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
"http listener requires a defined service": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
2020-03-31 16:59:10 +00:00
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "http",
|
|
|
|
Services: []IngressService{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
validateErr: "No service declared for listener with port 1111",
|
2020-03-31 16:59:10 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
"empty service name not supported": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
2020-03-31 16:59:10 +00:00
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "tcp",
|
|
|
|
Services: []IngressService{
|
|
|
|
{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
validateErr: "Service name cannot be blank",
|
2020-03-31 16:59:10 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
"protocol validation": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
2020-03-31 16:59:10 +00:00
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "asdf",
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "db",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
validateErr: "protocol must be 'tcp', 'http', 'http2', or 'grpc'. 'asdf' is an unsupported protocol",
|
2020-03-31 16:59:10 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
"hosts cannot be set on a tcp listener": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
2020-04-23 15:06:19 +00:00
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "tcp",
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "db",
|
|
|
|
Hosts: []string{"db.example.com"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
validateErr: "Associating hosts to a service is not supported for the tcp protocol",
|
2020-04-23 15:06:19 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
"hosts cannot be set on a wildcard specifier": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
2020-04-23 15:06:19 +00:00
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "http",
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "*",
|
|
|
|
Hosts: []string{"db.example.com"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
validateErr: "Associating hosts to a wildcard service is not supported",
|
2020-04-23 15:06:19 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
"hosts must be unique per listener": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
2020-04-23 15:06:19 +00:00
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "http",
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "db",
|
|
|
|
Hosts: []string{"test.example.com"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "api",
|
|
|
|
Hosts: []string{"test.example.com"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
validateErr: "Hosts must be unique within a specific listener",
|
2020-04-23 15:06:19 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
"hosts must be a valid DNS name": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
2020-04-28 20:20:53 +00:00
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "http",
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "db",
|
|
|
|
Hosts: []string{"example..com"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
validateErr: `Host "example..com" must be a valid DNS hostname`,
|
2020-04-28 20:20:53 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
"wildcard specifier is only allowed in the leftmost label": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
2020-04-28 20:20:53 +00:00
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "http",
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "db",
|
|
|
|
Hosts: []string{"*.example.com"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
"wildcard specifier is not allowed in non-leftmost labels": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
2020-04-28 20:20:53 +00:00
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "http",
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "db",
|
|
|
|
Hosts: []string{"example.*.com"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
validateErr: `Host "example.*.com" is not valid, a wildcard specifier is only allowed as the leftmost label`,
|
2020-04-28 20:20:53 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
"wildcard specifier is not allowed in leftmost labels as a partial": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
2020-04-28 20:20:53 +00:00
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "http",
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "db",
|
|
|
|
Hosts: []string{"*-test.example.com"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
validateErr: `Host "*-test.example.com" is not valid, a wildcard specifier is only allowed as the leftmost label`,
|
2020-04-28 20:20:53 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
"wildcard specifier is allowed for hosts when TLS is disabled": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
2020-06-11 15:03:06 +00:00
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "http",
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "db",
|
|
|
|
Hosts: []string{"*"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
"wildcard specifier is not allowed for hosts when TLS is enabled": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
2020-06-11 15:03:06 +00:00
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
TLS: GatewayTLSConfig{
|
|
|
|
Enabled: true,
|
|
|
|
},
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "http",
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "db",
|
|
|
|
Hosts: []string{"*"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
validateErr: `Host '*' is not allowed when TLS is enabled, all hosts must be valid DNS records to add as a DNSSAN`,
|
|
|
|
},
|
2021-07-13 11:13:18 +00:00
|
|
|
"request header manip allowed for http(ish) protocol": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "http",
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "web",
|
|
|
|
RequestHeaders: &HTTPHeaderModifiers{
|
|
|
|
Set: map[string]string{"x-foo": "bar"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Port: 2222,
|
|
|
|
Protocol: "http2",
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "web2",
|
|
|
|
ResponseHeaders: &HTTPHeaderModifiers{
|
|
|
|
Set: map[string]string{"x-foo": "bar"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Port: 3333,
|
|
|
|
Protocol: "grpc",
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "api",
|
|
|
|
ResponseHeaders: &HTTPHeaderModifiers{
|
|
|
|
Remove: []string{"x-grpc-internal"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-08-17 11:27:31 +00:00
|
|
|
expectUnchanged: true,
|
2021-07-13 11:13:18 +00:00
|
|
|
},
|
|
|
|
"request header manip not allowed for non-http protocol": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "tcp",
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "db",
|
|
|
|
RequestHeaders: &HTTPHeaderModifiers{
|
|
|
|
Set: map[string]string{"x-foo": "bar"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "request headers only valid for http",
|
|
|
|
},
|
|
|
|
"response header manip not allowed for non-http protocol": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "tcp",
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "db",
|
|
|
|
ResponseHeaders: &HTTPHeaderModifiers{
|
|
|
|
Remove: []string{"x-foo"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "response headers only valid for http",
|
|
|
|
},
|
2021-07-13 12:53:59 +00:00
|
|
|
"duplicate services not allowed": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "http",
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "web",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "web",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-08-27 13:47:02 +00:00
|
|
|
// Match only the last part of the exected error because the service name
|
|
|
|
// differs between Ent and OSS default/default/web vs web
|
|
|
|
validateErr: "cannot be added multiple times (listener on port 1111)",
|
2021-07-13 12:53:59 +00:00
|
|
|
},
|
2021-08-17 11:27:31 +00:00
|
|
|
"TLS.SDS kitchen sink": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
TLS: GatewayTLSConfig{
|
|
|
|
SDS: &GatewayTLSSDSConfig{
|
|
|
|
ClusterName: "secret-service1",
|
|
|
|
CertResource: "some-ns/ingress-default",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "http",
|
|
|
|
TLS: &GatewayTLSConfig{
|
|
|
|
SDS: &GatewayTLSSDSConfig{
|
|
|
|
ClusterName: "secret-service2",
|
|
|
|
CertResource: "some-ns/ingress-1111",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "web",
|
|
|
|
Hosts: []string{"*"},
|
|
|
|
TLS: &GatewayServiceTLSConfig{
|
|
|
|
SDS: &GatewayTLSSDSConfig{
|
|
|
|
ClusterName: "secret-service3",
|
|
|
|
CertResource: "some-ns/web",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"TLS.SDS gateway-level": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
TLS: GatewayTLSConfig{
|
|
|
|
SDS: &GatewayTLSSDSConfig{
|
|
|
|
ClusterName: "secret-service1",
|
|
|
|
CertResource: "some-ns/ingress-default",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "tcp",
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "db",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectUnchanged: true,
|
|
|
|
},
|
|
|
|
"TLS.SDS listener-level": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "tcp",
|
|
|
|
TLS: &GatewayTLSConfig{
|
|
|
|
SDS: &GatewayTLSSDSConfig{
|
|
|
|
ClusterName: "secret-service1",
|
|
|
|
CertResource: "some-ns/db1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "db1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Port: 2222,
|
|
|
|
Protocol: "tcp",
|
|
|
|
TLS: &GatewayTLSConfig{
|
|
|
|
SDS: &GatewayTLSSDSConfig{
|
|
|
|
ClusterName: "secret-service2",
|
|
|
|
CertResource: "some-ns/db2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "db2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectUnchanged: true,
|
|
|
|
},
|
|
|
|
"TLS.SDS gateway-level cluster only": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
TLS: GatewayTLSConfig{
|
|
|
|
SDS: &GatewayTLSSDSConfig{
|
|
|
|
ClusterName: "secret-service",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "tcp",
|
|
|
|
TLS: &GatewayTLSConfig{
|
|
|
|
SDS: &GatewayTLSSDSConfig{
|
|
|
|
CertResource: "some-ns/db1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "db1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Port: 2222,
|
|
|
|
Protocol: "tcp",
|
|
|
|
TLS: &GatewayTLSConfig{
|
|
|
|
SDS: &GatewayTLSSDSConfig{
|
|
|
|
CertResource: "some-ns/db2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "db2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectUnchanged: true,
|
|
|
|
},
|
|
|
|
"TLS.SDS mixed TLS and non-TLS listeners": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
// No Gateway level TLS.Enabled or SDS config
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "tcp",
|
|
|
|
TLS: &GatewayTLSConfig{
|
|
|
|
SDS: &GatewayTLSSDSConfig{
|
|
|
|
ClusterName: "sds-cluster",
|
|
|
|
CertResource: "some-ns/db1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "db1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Port: 2222,
|
|
|
|
Protocol: "tcp",
|
|
|
|
// No TLS config
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "db2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectUnchanged: true,
|
|
|
|
},
|
|
|
|
"TLS.SDS only service-level mixed": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
// No Gateway level TLS.Enabled or SDS config
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "http",
|
|
|
|
// No TLS config
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "web",
|
|
|
|
Hosts: []string{"www.example.com"},
|
|
|
|
TLS: &GatewayServiceTLSConfig{
|
|
|
|
SDS: &GatewayTLSSDSConfig{
|
|
|
|
ClusterName: "sds-cluster",
|
|
|
|
CertResource: "web-cert",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "api",
|
|
|
|
Hosts: []string{"api.example.com"},
|
|
|
|
TLS: &GatewayServiceTLSConfig{
|
|
|
|
SDS: &GatewayTLSSDSConfig{
|
|
|
|
ClusterName: "sds-cluster",
|
|
|
|
CertResource: "api-cert",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Port: 2222,
|
|
|
|
Protocol: "http",
|
|
|
|
// No TLS config
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "db2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectUnchanged: true,
|
|
|
|
},
|
|
|
|
"TLS.SDS requires cluster if gateway-level cert specified": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
TLS: GatewayTLSConfig{
|
|
|
|
SDS: &GatewayTLSSDSConfig{
|
|
|
|
CertResource: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "tcp",
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "db",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "TLS.SDS.ClusterName is required if CertResource is set",
|
|
|
|
},
|
|
|
|
"TLS.SDS listener requires cluster if there is no gateway-level one": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "tcp",
|
|
|
|
TLS: &GatewayTLSConfig{
|
|
|
|
SDS: &GatewayTLSSDSConfig{
|
|
|
|
CertResource: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "db",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "TLS.SDS.ClusterName is required if CertResource is set",
|
|
|
|
},
|
|
|
|
"TLS.SDS listener requires a cert resource if gw ClusterName set": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
TLS: GatewayTLSConfig{
|
|
|
|
SDS: &GatewayTLSSDSConfig{
|
|
|
|
ClusterName: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "tcp",
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "db",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "TLS.SDS.CertResource is required if ClusterName is set for gateway (listener on port 1111)",
|
|
|
|
},
|
|
|
|
"TLS.SDS listener requires a cert resource if listener ClusterName set": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "tcp",
|
|
|
|
TLS: &GatewayTLSConfig{
|
|
|
|
SDS: &GatewayTLSSDSConfig{
|
|
|
|
ClusterName: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "db",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "TLS.SDS.CertResource is required if ClusterName is set for listener (listener on port 1111)",
|
|
|
|
},
|
|
|
|
"TLS.SDS at service level is not supported without Hosts set": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "http",
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "*",
|
|
|
|
TLS: &GatewayServiceTLSConfig{
|
|
|
|
SDS: &GatewayTLSSDSConfig{
|
|
|
|
CertResource: "foo",
|
|
|
|
ClusterName: "sds-cluster",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-08-27 15:00:07 +00:00
|
|
|
// Note we don't assert the last part `(service \"*\" on listener on port 1111)`
|
|
|
|
// since the service name is normalized differently on OSS and Ent
|
|
|
|
validateErr: "A service specifying TLS.SDS.CertResource must have at least one item in Hosts",
|
2021-08-17 11:27:31 +00:00
|
|
|
},
|
|
|
|
"TLS.SDS at service level needs a cluster from somewhere": {
|
|
|
|
entry: &IngressGatewayConfigEntry{
|
|
|
|
Kind: "ingress-gateway",
|
|
|
|
Name: "ingress-web",
|
|
|
|
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "http",
|
|
|
|
Services: []IngressService{
|
|
|
|
{
|
|
|
|
Name: "foo",
|
|
|
|
Hosts: []string{"foo.example.com"},
|
|
|
|
TLS: &GatewayServiceTLSConfig{
|
|
|
|
SDS: &GatewayTLSSDSConfig{
|
|
|
|
CertResource: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-08-27 15:00:07 +00:00
|
|
|
// Note we don't assert the last part `(service \"foo\" on listener on port 1111)`
|
|
|
|
// since the service name is normalized differently on OSS and Ent
|
|
|
|
validateErr: "TLS.SDS.ClusterName is required if CertResource is set",
|
2021-08-17 11:27:31 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
testConfigEntryNormalizeAndValidate(t, cases)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIngressConfigEntry_ListRelatedServices(t *testing.T) {
|
|
|
|
type testcase struct {
|
|
|
|
entry IngressGatewayConfigEntry
|
|
|
|
expectServices []ServiceID
|
|
|
|
}
|
|
|
|
|
|
|
|
cases := map[string]testcase{
|
|
|
|
"one exact": {
|
|
|
|
entry: IngressGatewayConfigEntry{
|
|
|
|
Kind: IngressGateway,
|
|
|
|
Name: "ingress-web",
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "tcp",
|
|
|
|
Services: []IngressService{
|
|
|
|
{Name: "web"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectServices: []ServiceID{NewServiceID("web", nil)},
|
|
|
|
},
|
|
|
|
"one wild": {
|
|
|
|
entry: IngressGatewayConfigEntry{
|
|
|
|
Kind: IngressGateway,
|
|
|
|
Name: "ingress-web",
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "tcp",
|
|
|
|
Services: []IngressService{
|
|
|
|
{Name: "*"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectServices: nil,
|
|
|
|
},
|
|
|
|
"kitchen sink": {
|
|
|
|
entry: IngressGatewayConfigEntry{
|
|
|
|
Kind: IngressGateway,
|
|
|
|
Name: "ingress-web",
|
|
|
|
Listeners: []IngressListener{
|
|
|
|
{
|
|
|
|
Port: 1111,
|
|
|
|
Protocol: "tcp",
|
|
|
|
Services: []IngressService{
|
|
|
|
{Name: "api"},
|
|
|
|
{Name: "web"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Port: 2222,
|
|
|
|
Protocol: "tcp",
|
|
|
|
Services: []IngressService{
|
|
|
|
{Name: "web"},
|
|
|
|
{Name: "*"},
|
|
|
|
{Name: "db"},
|
|
|
|
{Name: "blah"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectServices: []ServiceID{
|
|
|
|
NewServiceID("api", nil),
|
|
|
|
NewServiceID("blah", nil),
|
|
|
|
NewServiceID("db", nil),
|
|
|
|
NewServiceID("web", nil),
|
|
|
|
},
|
2020-06-11 15:03:06 +00:00
|
|
|
},
|
2020-03-31 16:59:10 +00:00
|
|
|
}
|
|
|
|
|
2021-06-23 19:11:23 +00:00
|
|
|
for name, tc := range cases {
|
|
|
|
tc := tc
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
got := tc.entry.ListRelatedServices()
|
|
|
|
require.Equal(t, tc.expectServices, got)
|
2020-03-31 16:59:10 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2020-03-31 19:27:32 +00:00
|
|
|
|
2021-06-23 19:11:23 +00:00
|
|
|
func TestTerminatingGatewayConfigEntry(t *testing.T) {
|
|
|
|
cases := map[string]configEntryTestcase{
|
|
|
|
"service conflict": {
|
|
|
|
entry: &TerminatingGatewayConfigEntry{
|
2020-03-31 19:27:32 +00:00
|
|
|
Kind: "terminating-gateway",
|
|
|
|
Name: "terminating-gw-west",
|
|
|
|
Services: []LinkedService{
|
|
|
|
{
|
|
|
|
Name: "foo",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
validateErr: "specified more than once",
|
2020-03-31 19:27:32 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
"blank service name": {
|
|
|
|
entry: &TerminatingGatewayConfigEntry{
|
2020-03-31 19:27:32 +00:00
|
|
|
Kind: "terminating-gateway",
|
|
|
|
Name: "terminating-gw-west",
|
|
|
|
Services: []LinkedService{
|
|
|
|
{
|
|
|
|
Name: "",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
validateErr: "Service name cannot be blank.",
|
2020-03-31 19:27:32 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
"not all TLS options provided-1": {
|
|
|
|
entry: &TerminatingGatewayConfigEntry{
|
2020-03-31 19:27:32 +00:00
|
|
|
Kind: "terminating-gateway",
|
|
|
|
Name: "terminating-gw-west",
|
|
|
|
Services: []LinkedService{
|
|
|
|
{
|
|
|
|
Name: "web",
|
|
|
|
CertFile: "client.crt",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
validateErr: "must have a CertFile, CAFile, and KeyFile",
|
2020-03-31 19:27:32 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
"not all TLS options provided-2": {
|
|
|
|
entry: &TerminatingGatewayConfigEntry{
|
2020-03-31 19:27:32 +00:00
|
|
|
Kind: "terminating-gateway",
|
|
|
|
Name: "terminating-gw-west",
|
|
|
|
Services: []LinkedService{
|
|
|
|
{
|
|
|
|
Name: "web",
|
|
|
|
KeyFile: "tls.key",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
validateErr: "must have a CertFile, CAFile, and KeyFile",
|
2020-03-31 19:27:32 +00:00
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
"all TLS options provided": {
|
|
|
|
entry: &TerminatingGatewayConfigEntry{
|
2020-03-31 19:27:32 +00:00
|
|
|
Kind: "terminating-gateway",
|
|
|
|
Name: "terminating-gw-west",
|
|
|
|
Services: []LinkedService{
|
|
|
|
{
|
|
|
|
Name: "web",
|
|
|
|
CAFile: "ca.crt",
|
|
|
|
CertFile: "client.crt",
|
|
|
|
KeyFile: "tls.key",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 19:11:23 +00:00
|
|
|
"only providing ca file is allowed": {
|
|
|
|
entry: &TerminatingGatewayConfigEntry{
|
2020-03-31 19:27:32 +00:00
|
|
|
Kind: "terminating-gateway",
|
|
|
|
Name: "terminating-gw-west",
|
|
|
|
Services: []LinkedService{
|
|
|
|
{
|
2020-04-27 22:25:37 +00:00
|
|
|
Name: "web",
|
|
|
|
CAFile: "ca.crt",
|
2020-03-31 19:27:32 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-06-23 19:11:23 +00:00
|
|
|
testConfigEntryNormalizeAndValidate(t, cases)
|
2020-03-31 19:27:32 +00:00
|
|
|
}
|
2020-06-22 19:14:12 +00:00
|
|
|
|
|
|
|
func TestGatewayService_Addresses(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
|
|
name string
|
|
|
|
input GatewayService
|
|
|
|
argument []string
|
|
|
|
expected []string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "port is zero",
|
|
|
|
input: GatewayService{},
|
|
|
|
expected: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "no hosts with empty array",
|
|
|
|
input: GatewayService{
|
|
|
|
Port: 8080,
|
|
|
|
},
|
|
|
|
expected: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "no hosts with default",
|
|
|
|
input: GatewayService{
|
|
|
|
Port: 8080,
|
|
|
|
},
|
|
|
|
argument: []string{
|
|
|
|
"service.ingress.dc.domain",
|
|
|
|
"service.ingress.dc.alt.domain",
|
2021-02-25 09:34:47 +00:00
|
|
|
"service.ingress.dc.alt.domain.",
|
2020-06-22 19:14:12 +00:00
|
|
|
},
|
|
|
|
expected: []string{
|
|
|
|
"service.ingress.dc.domain:8080",
|
|
|
|
"service.ingress.dc.alt.domain:8080",
|
2021-02-25 09:34:47 +00:00
|
|
|
"service.ingress.dc.alt.domain:8080",
|
2020-06-22 19:14:12 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "user-defined hosts",
|
|
|
|
input: GatewayService{
|
|
|
|
Port: 8080,
|
2021-02-25 09:34:47 +00:00
|
|
|
Hosts: []string{"*.test.example.com", "other.example.com", "other.example.com."},
|
2020-06-22 19:14:12 +00:00
|
|
|
},
|
|
|
|
argument: []string{
|
|
|
|
"service.ingress.dc.domain",
|
|
|
|
"service.ingress.alt.domain",
|
|
|
|
},
|
2021-02-25 09:34:47 +00:00
|
|
|
expected: []string{"*.test.example.com:8080", "other.example.com:8080", "other.example.com:8080"},
|
2020-06-22 19:14:12 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-06-23 17:48:30 +00:00
|
|
|
for _, tc := range cases {
|
2020-06-22 19:14:12 +00:00
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
addresses := tc.input.Addresses(tc.argument)
|
|
|
|
require.ElementsMatch(t, tc.expected, addresses)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2023-01-18 22:14:34 +00:00
|
|
|
|
|
|
|
func TestAPIGateway_Listeners(t *testing.T) {
|
|
|
|
cases := map[string]configEntryTestcase{
|
2023-03-20 16:37:30 +00:00
|
|
|
"no listeners defined": {
|
|
|
|
entry: &APIGatewayConfigEntry{
|
|
|
|
Kind: "api-gateway",
|
|
|
|
Name: "api-gw-one",
|
|
|
|
},
|
|
|
|
validateErr: "api gateway must have at least one listener",
|
|
|
|
},
|
2023-01-18 22:14:34 +00:00
|
|
|
"listener name conflict": {
|
|
|
|
entry: &APIGatewayConfigEntry{
|
|
|
|
Kind: "api-gateway",
|
|
|
|
Name: "api-gw-one",
|
|
|
|
Listeners: []APIGatewayListener{
|
|
|
|
{
|
|
|
|
Port: 80,
|
|
|
|
Name: "foo",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Port: 80,
|
|
|
|
Name: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "multiple listeners with the name",
|
|
|
|
},
|
2023-02-21 19:12:19 +00:00
|
|
|
"empty listener name": {
|
|
|
|
entry: &APIGatewayConfigEntry{
|
|
|
|
Kind: "api-gateway",
|
|
|
|
Name: "api-gw-one",
|
|
|
|
Listeners: []APIGatewayListener{
|
|
|
|
{
|
|
|
|
Port: 80,
|
|
|
|
Protocol: "tcp",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "listener name \"\" is invalid, must be at least 1 character and contain only letters, numbers, or dashes",
|
|
|
|
},
|
|
|
|
"invalid listener name": {
|
|
|
|
entry: &APIGatewayConfigEntry{
|
|
|
|
Kind: "api-gateway",
|
|
|
|
Name: "api-gw-one",
|
|
|
|
Listeners: []APIGatewayListener{
|
|
|
|
{
|
|
|
|
Port: 80,
|
|
|
|
Protocol: "tcp",
|
|
|
|
Name: "/",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "listener name \"/\" is invalid, must be at least 1 character and contain only letters, numbers, or dashes",
|
|
|
|
},
|
2023-01-18 22:14:34 +00:00
|
|
|
"merged listener protocol conflict": {
|
|
|
|
entry: &APIGatewayConfigEntry{
|
|
|
|
Kind: "api-gateway",
|
|
|
|
Name: "api-gw-two",
|
|
|
|
Listeners: []APIGatewayListener{
|
|
|
|
{
|
2023-02-21 19:12:19 +00:00
|
|
|
Name: "listener-one",
|
2023-01-18 22:14:34 +00:00
|
|
|
Port: 80,
|
|
|
|
Protocol: ListenerProtocolHTTP,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "foo",
|
|
|
|
Port: 80,
|
|
|
|
Protocol: ListenerProtocolTCP,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "cannot be merged",
|
|
|
|
},
|
|
|
|
"merged listener hostname conflict": {
|
|
|
|
entry: &APIGatewayConfigEntry{
|
|
|
|
Kind: "api-gateway",
|
|
|
|
Name: "api-gw-three",
|
|
|
|
Listeners: []APIGatewayListener{
|
|
|
|
{
|
2023-02-21 19:12:19 +00:00
|
|
|
Name: "listener",
|
2023-01-18 22:14:34 +00:00
|
|
|
Port: 80,
|
|
|
|
Hostname: "host.one",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "foo",
|
|
|
|
Port: 80,
|
|
|
|
Hostname: "host.two",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "cannot be merged",
|
|
|
|
},
|
|
|
|
"invalid protocol": {
|
|
|
|
entry: &APIGatewayConfigEntry{
|
|
|
|
Kind: "api-gateway",
|
|
|
|
Name: "api-gw-four",
|
|
|
|
Listeners: []APIGatewayListener{
|
|
|
|
{
|
2023-02-21 19:12:19 +00:00
|
|
|
Name: "listener",
|
2023-01-18 22:14:34 +00:00
|
|
|
Port: 80,
|
|
|
|
Hostname: "host.one",
|
|
|
|
Protocol: APIGatewayListenerProtocol("UDP"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "unsupported listener protocol",
|
|
|
|
},
|
|
|
|
"hostname in unsupported protocol": {
|
|
|
|
entry: &APIGatewayConfigEntry{
|
|
|
|
Kind: "api-gateway",
|
|
|
|
Name: "api-gw-five",
|
|
|
|
Listeners: []APIGatewayListener{
|
|
|
|
{
|
2023-02-21 19:12:19 +00:00
|
|
|
Name: "listener",
|
2023-01-18 22:14:34 +00:00
|
|
|
Port: 80,
|
|
|
|
Hostname: "host.one",
|
|
|
|
Protocol: APIGatewayListenerProtocol("tcp"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "hostname specification is not supported",
|
|
|
|
},
|
|
|
|
"invalid port": {
|
|
|
|
entry: &APIGatewayConfigEntry{
|
|
|
|
Kind: "api-gateway",
|
|
|
|
Name: "api-gw-six",
|
|
|
|
Listeners: []APIGatewayListener{
|
|
|
|
{
|
2023-02-21 19:12:19 +00:00
|
|
|
Name: "listener",
|
2023-01-18 22:14:34 +00:00
|
|
|
Port: -1,
|
|
|
|
Protocol: APIGatewayListenerProtocol("tcp"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "not in the range 1-65535",
|
|
|
|
},
|
|
|
|
"invalid hostname": {
|
|
|
|
entry: &APIGatewayConfigEntry{
|
|
|
|
Kind: "api-gateway",
|
|
|
|
Name: "api-gw-seven",
|
|
|
|
Listeners: []APIGatewayListener{
|
|
|
|
{
|
2023-02-21 19:12:19 +00:00
|
|
|
Name: "listener",
|
2023-01-18 22:14:34 +00:00
|
|
|
Port: 80,
|
|
|
|
Hostname: "*.*.host.one",
|
|
|
|
Protocol: APIGatewayListenerProtocol("http"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "only allowed as the left-most label",
|
|
|
|
},
|
|
|
|
"unsupported certificate kind": {
|
|
|
|
entry: &APIGatewayConfigEntry{
|
|
|
|
Kind: "api-gateway",
|
|
|
|
Name: "api-gw-eight",
|
|
|
|
Listeners: []APIGatewayListener{
|
|
|
|
{
|
2023-02-21 19:12:19 +00:00
|
|
|
Name: "listener",
|
2023-01-18 22:14:34 +00:00
|
|
|
Port: 80,
|
|
|
|
Hostname: "host.one",
|
|
|
|
Protocol: APIGatewayListenerProtocol("http"),
|
|
|
|
TLS: APIGatewayTLSConfiguration{
|
|
|
|
Certificates: []ResourceReference{{
|
|
|
|
Kind: APIGateway,
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "unsupported certificate kind",
|
|
|
|
},
|
|
|
|
"unnamed certificate": {
|
|
|
|
entry: &APIGatewayConfigEntry{
|
|
|
|
Kind: "api-gateway",
|
|
|
|
Name: "api-gw-nine",
|
|
|
|
Listeners: []APIGatewayListener{
|
|
|
|
{
|
2023-02-21 19:12:19 +00:00
|
|
|
Name: "listener",
|
2023-01-18 22:14:34 +00:00
|
|
|
Port: 80,
|
|
|
|
Hostname: "host.one",
|
|
|
|
Protocol: APIGatewayListenerProtocol("http"),
|
|
|
|
TLS: APIGatewayTLSConfiguration{
|
|
|
|
Certificates: []ResourceReference{{
|
|
|
|
Kind: InlineCertificate,
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "certificate reference must have a name",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
testConfigEntryNormalizeAndValidate(t, cases)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBoundAPIGateway(t *testing.T) {
|
|
|
|
cases := map[string]configEntryTestcase{
|
|
|
|
"invalid certificate, no name": {
|
|
|
|
entry: &BoundAPIGatewayConfigEntry{
|
|
|
|
Kind: BoundAPIGateway,
|
|
|
|
Name: "bound-api-gw-one",
|
|
|
|
Listeners: []BoundAPIGatewayListener{
|
|
|
|
{
|
|
|
|
Name: "one",
|
|
|
|
Certificates: []ResourceReference{{
|
|
|
|
Kind: InlineCertificate,
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "certificate reference must have a name",
|
|
|
|
},
|
|
|
|
"invalid certificate, no kind": {
|
|
|
|
entry: &BoundAPIGatewayConfigEntry{
|
|
|
|
Kind: BoundAPIGateway,
|
|
|
|
Name: "bound-api-gw-two",
|
|
|
|
Listeners: []BoundAPIGatewayListener{
|
|
|
|
{
|
|
|
|
Name: "one",
|
|
|
|
Certificates: []ResourceReference{{
|
|
|
|
Name: "foo",
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "unsupported certificate kind",
|
|
|
|
},
|
|
|
|
"invalid route, no name": {
|
|
|
|
entry: &BoundAPIGatewayConfigEntry{
|
|
|
|
Kind: BoundAPIGateway,
|
|
|
|
Name: "bound-api-gw-three",
|
|
|
|
Listeners: []BoundAPIGatewayListener{
|
|
|
|
{
|
|
|
|
Name: "one",
|
|
|
|
Routes: []ResourceReference{{
|
|
|
|
Kind: TCPRoute,
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "route reference must have a name",
|
|
|
|
},
|
|
|
|
"invalid route, no kind": {
|
|
|
|
entry: &BoundAPIGatewayConfigEntry{
|
|
|
|
Kind: BoundAPIGateway,
|
|
|
|
Name: "bound-api-gw-four",
|
|
|
|
Listeners: []BoundAPIGatewayListener{
|
|
|
|
{
|
|
|
|
Name: "one",
|
|
|
|
Routes: []ResourceReference{{
|
|
|
|
Name: "foo",
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validateErr: "unsupported route kind",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
testConfigEntryNormalizeAndValidate(t, cases)
|
|
|
|
}
|
2023-01-20 20:11:16 +00:00
|
|
|
|
|
|
|
func TestListenerBindRoute(t *testing.T) {
|
|
|
|
cases := map[string]struct {
|
|
|
|
listener BoundAPIGatewayListener
|
|
|
|
route BoundRoute
|
|
|
|
expectedListener BoundAPIGatewayListener
|
|
|
|
expectedDidBind bool
|
|
|
|
}{
|
|
|
|
"Listener has no routes": {
|
|
|
|
listener: BoundAPIGatewayListener{},
|
|
|
|
route: &TCPRouteConfigEntry{
|
|
|
|
Kind: TCPRoute,
|
|
|
|
Name: "Test Route",
|
|
|
|
},
|
|
|
|
expectedListener: BoundAPIGatewayListener{
|
|
|
|
Routes: []ResourceReference{
|
|
|
|
{
|
|
|
|
Kind: TCPRoute,
|
|
|
|
Name: "Test Route",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectedDidBind: true,
|
|
|
|
},
|
|
|
|
"Listener to update existing route": {
|
|
|
|
listener: BoundAPIGatewayListener{
|
|
|
|
Routes: []ResourceReference{
|
|
|
|
{
|
|
|
|
Kind: TCPRoute,
|
|
|
|
Name: "Test Route 1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Kind: TCPRoute,
|
|
|
|
Name: "Test Route 2",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Kind: TCPRoute,
|
|
|
|
Name: "Test Route 3",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
route: &TCPRouteConfigEntry{
|
|
|
|
Kind: TCPRoute,
|
|
|
|
Name: "Test Route 2",
|
|
|
|
},
|
|
|
|
expectedListener: BoundAPIGatewayListener{
|
|
|
|
Routes: []ResourceReference{
|
|
|
|
{
|
|
|
|
Kind: TCPRoute,
|
|
|
|
Name: "Test Route 1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Kind: TCPRoute,
|
|
|
|
Name: "Test Route 2",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Kind: TCPRoute,
|
|
|
|
Name: "Test Route 3",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectedDidBind: true,
|
|
|
|
},
|
|
|
|
"Listener appends new route": {
|
|
|
|
listener: BoundAPIGatewayListener{
|
|
|
|
Routes: []ResourceReference{
|
|
|
|
{
|
|
|
|
Kind: TCPRoute,
|
|
|
|
Name: "Test Route 1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Kind: TCPRoute,
|
|
|
|
Name: "Test Route 2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
route: &TCPRouteConfigEntry{
|
|
|
|
Kind: TCPRoute,
|
|
|
|
Name: "Test Route 3",
|
|
|
|
},
|
|
|
|
expectedListener: BoundAPIGatewayListener{
|
|
|
|
Routes: []ResourceReference{
|
|
|
|
{
|
|
|
|
Kind: TCPRoute,
|
|
|
|
Name: "Test Route 1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Kind: TCPRoute,
|
|
|
|
Name: "Test Route 2",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Kind: TCPRoute,
|
|
|
|
Name: "Test Route 3",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectedDidBind: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range cases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
2023-02-08 19:50:17 +00:00
|
|
|
routeRef := ResourceReference{
|
|
|
|
Kind: tc.route.GetKind(),
|
|
|
|
Name: tc.route.GetName(),
|
|
|
|
EnterpriseMeta: *tc.route.GetEnterpriseMeta(),
|
|
|
|
}
|
|
|
|
actualDidBind := tc.listener.BindRoute(routeRef)
|
2023-01-20 20:11:16 +00:00
|
|
|
require.Equal(t, tc.expectedDidBind, actualDidBind)
|
|
|
|
require.Equal(t, tc.expectedListener.Routes, tc.listener.Routes)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestListenerUnbindRoute(t *testing.T) {
|
|
|
|
cases := map[string]struct {
|
|
|
|
listener BoundAPIGatewayListener
|
|
|
|
route BoundRoute
|
|
|
|
expectedListener BoundAPIGatewayListener
|
|
|
|
expectedDidUnbind bool
|
|
|
|
}{
|
|
|
|
"Listener has no routes": {
|
|
|
|
listener: BoundAPIGatewayListener{},
|
|
|
|
route: &TCPRouteConfigEntry{
|
|
|
|
Kind: TCPRoute,
|
|
|
|
Name: "Test Route",
|
|
|
|
},
|
|
|
|
expectedListener: BoundAPIGatewayListener{},
|
|
|
|
expectedDidUnbind: false,
|
|
|
|
},
|
|
|
|
"Listener to remove existing route": {
|
|
|
|
listener: BoundAPIGatewayListener{
|
|
|
|
Routes: []ResourceReference{
|
|
|
|
{
|
|
|
|
Kind: TCPRoute,
|
|
|
|
Name: "Test Route 1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Kind: TCPRoute,
|
|
|
|
Name: "Test Route 2",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Kind: TCPRoute,
|
|
|
|
Name: "Test Route 3",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
route: &TCPRouteConfigEntry{
|
|
|
|
Kind: TCPRoute,
|
|
|
|
Name: "Test Route 2",
|
|
|
|
},
|
|
|
|
expectedListener: BoundAPIGatewayListener{
|
|
|
|
Routes: []ResourceReference{
|
|
|
|
{
|
|
|
|
Kind: TCPRoute,
|
|
|
|
Name: "Test Route 1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Kind: TCPRoute,
|
|
|
|
Name: "Test Route 3",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expectedDidUnbind: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range cases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
2023-02-08 19:50:17 +00:00
|
|
|
routeRef := ResourceReference{
|
|
|
|
Kind: tc.route.GetKind(),
|
|
|
|
Name: tc.route.GetName(),
|
|
|
|
EnterpriseMeta: *tc.route.GetEnterpriseMeta(),
|
|
|
|
}
|
|
|
|
actualDidUnbind := tc.listener.UnbindRoute(routeRef)
|
2023-01-20 20:11:16 +00:00
|
|
|
require.Equal(t, tc.expectedDidUnbind, actualDidUnbind)
|
|
|
|
require.Equal(t, tc.expectedListener.Routes, tc.listener.Routes)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|