ingress-nginx-helm/internal/ingress/annotations/sslpassthrough/main_test.go

81 lines
2 KiB
Go
Raw Normal View History

2016-06-01 18:47:37 +00:00
/*
Copyright 2016 The Kubernetes Authors.
2016-06-01 18:47:37 +00:00
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.
*/
package sslpassthrough
2016-06-01 18:47:37 +00:00
import (
"testing"
2017-07-16 19:19:59 +00:00
api "k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
2017-04-01 14:39:42 +00:00
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2017-11-23 16:46:23 +00:00
"k8s.io/ingress-nginx/internal/ingress/annotations/parser"
2017-11-08 20:58:57 +00:00
"k8s.io/ingress-nginx/internal/ingress/resolver"
2017-04-01 14:39:42 +00:00
"k8s.io/apimachinery/pkg/util/intstr"
2016-06-01 18:47:37 +00:00
)
func buildIngress() *extensions.Ingress {
return &extensions.Ingress{
2017-04-01 14:39:42 +00:00
ObjectMeta: meta_v1.ObjectMeta{
2016-06-01 18:47:37 +00:00
Name: "foo",
Namespace: api.NamespaceDefault,
},
Spec: extensions.IngressSpec{
Backend: &extensions.IngressBackend{
ServiceName: "default-backend",
ServicePort: intstr.FromInt(80),
},
},
}
}
func TestParseAnnotations(t *testing.T) {
2016-06-01 18:47:37 +00:00
ing := buildIngress()
2017-11-08 20:58:57 +00:00
_, err := NewParser(&resolver.Mock{}).Parse(ing)
if err == nil {
t.Errorf("unexpected error: %v", err)
2016-06-01 18:47:37 +00:00
}
data := map[string]string{}
2017-11-23 16:46:23 +00:00
data[parser.GetAnnotationWithPrefix("ssl-passthrough")] = "true"
ing.SetAnnotations(data)
// test ingress using the annotation without a TLS section
2017-11-08 20:58:57 +00:00
_, err = NewParser(&resolver.Mock{}).Parse(ing)
if err != nil {
t.Errorf("unexpected error parsing ingress with sslpassthrough")
}
// test with a valid host
ing.Spec.TLS = []extensions.IngressTLS{
{
Hosts: []string{"foo.bar.com"},
},
}
2017-11-08 20:58:57 +00:00
i, err := NewParser(&resolver.Mock{}).Parse(ing)
if err != nil {
t.Errorf("expected error parsing ingress with sslpassthrough")
}
val, ok := i.(bool)
if !ok {
t.Errorf("expected a bool type")
}
if !val {
t.Errorf("expected true but false returned")
2016-06-01 18:47:37 +00:00
}
}