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"
|
|
|
|
|
2022-07-31 16:16:28 +00:00
|
|
|
"github.com/onsi/ginkgo/v2"
|
2018-01-17 12:26:53 +00:00
|
|
|
|
2021-08-21 20:42:00 +00:00
|
|
|
networking "k8s.io/api/networking/v1"
|
2018-01-17 12:26:53 +00:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
"k8s.io/ingress-nginx/test/e2e/framework"
|
|
|
|
)
|
|
|
|
|
2020-02-16 18:27:58 +00:00
|
|
|
var _ = framework.DescribeSetting("server-tokens", func() {
|
2021-08-21 20:42:00 +00:00
|
|
|
pathtype := networking.PathTypePrefix
|
2018-01-17 12:26:53 +00:00
|
|
|
f := framework.NewDefaultFramework("server-tokens")
|
2018-01-23 23:37:47 +00:00
|
|
|
serverTokens := "server-tokens"
|
2018-01-17 12:26:53 +00:00
|
|
|
|
2020-02-19 03:08:56 +00:00
|
|
|
ginkgo.BeforeEach(func() {
|
2018-10-29 21:39:04 +00:00
|
|
|
f.NewEchoDeployment()
|
2018-01-17 12:26:53 +00:00
|
|
|
})
|
|
|
|
|
2020-02-19 03:08:56 +00:00
|
|
|
ginkgo.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
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-19 03:08:56 +00:00
|
|
|
ginkgo.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{
|
2021-08-21 20:42:00 +00:00
|
|
|
IngressClassName: &f.IngressClass,
|
2019-12-12 23:12:12 +00:00
|
|
|
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
|
|
|
{
|
2021-08-21 20:42:00 +00:00
|
|
|
Path: "/",
|
|
|
|
PathType: &pathtype,
|
2019-12-12 23:12:12 +00:00
|
|
|
Backend: networking.IngressBackend{
|
2021-08-21 20:42:00 +00:00
|
|
|
Service: &networking.IngressServiceBackend{
|
|
|
|
Name: framework.EchoService,
|
|
|
|
Port: networking.ServiceBackendPort{
|
|
|
|
Number: int32(80),
|
|
|
|
},
|
|
|
|
},
|
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 on")
|
2018-01-17 12:26:53 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|