2018-01-17 12:26:53 +00:00
|
|
|
/*
|
|
|
|
Copyright 2018 The Kubernetes 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.
|
|
|
|
*/
|
|
|
|
|
2018-04-27 12:29:08 +00:00
|
|
|
package settings
|
2018-01-17 12:26:53 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
|
2019-12-12 23:12:12 +00:00
|
|
|
networking "k8s.io/api/networking/v1beta1"
|
2018-01-17 12:26:53 +00:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
"k8s.io/apimachinery/pkg/util/intstr"
|
|
|
|
"k8s.io/ingress-nginx/test/e2e/framework"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = framework.IngressNginxDescribe("Server Tokens", func() {
|
|
|
|
f := framework.NewDefaultFramework("server-tokens")
|
2018-01-23 23:37:47 +00:00
|
|
|
serverTokens := "server-tokens"
|
2018-01-17 12:26:53 +00:00
|
|
|
|
|
|
|
BeforeEach(func() {
|
2018-10-29 21:39:04 +00:00
|
|
|
f.NewEchoDeployment()
|
2018-01-17 12:26:53 +00:00
|
|
|
})
|
|
|
|
|
2018-04-10 18:14:36 +00:00
|
|
|
It("should not exists Server header in the response", func() {
|
2018-10-29 21:39:04 +00:00
|
|
|
f.UpdateNginxConfigMapData(serverTokens, "false")
|
2018-01-17 12:26:53 +00:00
|
|
|
|
2019-09-01 18:16:52 +00:00
|
|
|
f.EnsureIngress(framework.NewSingleIngress(serverTokens, "/", serverTokens, f.Namespace, framework.EchoService, 80, nil))
|
2018-01-17 12:26:53 +00:00
|
|
|
|
2018-10-29 21:39:04 +00:00
|
|
|
f.WaitForNginxConfiguration(
|
2018-04-27 18:36:22 +00:00
|
|
|
func(cfg string) bool {
|
|
|
|
return strings.Contains(cfg, "server_tokens off") &&
|
2018-06-23 14:08:39 +00:00
|
|
|
strings.Contains(cfg, "more_clear_headers Server;")
|
2018-01-17 12:26:53 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-04-10 18:14:36 +00:00
|
|
|
It("should exists Server header in the response when is enabled", func() {
|
2018-10-29 21:39:04 +00:00
|
|
|
f.UpdateNginxConfigMapData(serverTokens, "true")
|
2018-01-17 12:26:53 +00:00
|
|
|
|
2019-12-12 23:12:12 +00:00
|
|
|
f.EnsureIngress(&networking.Ingress{
|
2018-01-17 12:26:53 +00:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: serverTokens,
|
2019-02-22 14:03:42 +00:00
|
|
|
Namespace: f.Namespace,
|
2018-01-17 12:26:53 +00:00
|
|
|
Annotations: map[string]string{},
|
|
|
|
},
|
2019-12-12 23:12:12 +00:00
|
|
|
Spec: networking.IngressSpec{
|
|
|
|
Rules: []networking.IngressRule{
|
2018-01-17 12:26:53 +00:00
|
|
|
{
|
|
|
|
Host: serverTokens,
|
2019-12-12 23:12:12 +00:00
|
|
|
IngressRuleValue: networking.IngressRuleValue{
|
|
|
|
HTTP: &networking.HTTPIngressRuleValue{
|
|
|
|
Paths: []networking.HTTPIngressPath{
|
2018-01-17 12:26:53 +00:00
|
|
|
{
|
|
|
|
Path: "/",
|
2019-12-12 23:12:12 +00:00
|
|
|
Backend: networking.IngressBackend{
|
2019-09-01 18:16:52 +00:00
|
|
|
ServiceName: framework.EchoService,
|
2018-01-17 12:26:53 +00:00
|
|
|
ServicePort: intstr.FromInt(80),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2018-10-29 21:39:04 +00:00
|
|
|
f.WaitForNginxConfiguration(
|
2018-04-27 18:36:22 +00:00
|
|
|
func(cfg string) bool {
|
|
|
|
return strings.Contains(cfg, "server_tokens on")
|
2018-01-17 12:26:53 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|