generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 23
/
logs_mtls_cert_key_pair_dont_match_test.go
101 lines (83 loc) · 3.45 KB
/
logs_mtls_cert_key_pair_dont_match_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//go:build e2e
package e2e
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
operatorv1alpha1 "github.com/kyma-project/telemetry-manager/apis/operator/v1alpha1"
"github.com/kyma-project/telemetry-manager/internal/conditions"
"github.com/kyma-project/telemetry-manager/internal/testutils"
"github.com/kyma-project/telemetry-manager/test/testkit/assert"
kitk8s "github.com/kyma-project/telemetry-manager/test/testkit/k8s"
"github.com/kyma-project/telemetry-manager/test/testkit/mocks/backend"
"github.com/kyma-project/telemetry-manager/test/testkit/mocks/loggen"
"github.com/kyma-project/telemetry-manager/test/testkit/suite"
)
var _ = Describe(suite.ID(), Label(suite.LabelLogs), Ordered, func() {
var (
mockNs = suite.ID()
pipelineName = suite.ID()
)
makeResources := func() []client.Object {
var objs []client.Object
objs = append(objs, kitk8s.NewNamespace(mockNs).K8sObject())
serverCertsDefault, clientCertsDefault, err := testutils.NewCertBuilder(backend.DefaultName, mockNs).Build()
Expect(err).ToNot(HaveOccurred())
_, clientCertsCreatedAgain, err := testutils.NewCertBuilder(backend.DefaultName, mockNs).Build()
Expect(err).ToNot(HaveOccurred())
backend := backend.New(mockNs, backend.SignalTypeLogs, backend.WithTLS(*serverCertsDefault))
objs = append(objs, backend.K8sObjects()...)
invalidClientCerts := &testutils.ClientCerts{
CaCertPem: clientCertsDefault.CaCertPem,
ClientCertPem: clientCertsDefault.ClientCertPem,
ClientKeyPem: clientCertsCreatedAgain.ClientKeyPem,
}
logPipeline := testutils.NewLogPipelineBuilder().
WithName(pipelineName).
WithHTTPOutput(
testutils.HTTPHost(backend.Host()),
testutils.HTTPPort(backend.Port()),
testutils.HTTPClientTLSFromString(
invalidClientCerts.CaCertPem.String(),
invalidClientCerts.ClientCertPem.String(),
invalidClientCerts.ClientKeyPem.String(),
)).
Build()
logProducer := loggen.New(mockNs)
objs = append(objs, logProducer.K8sObject())
objs = append(objs, &logPipeline)
return objs
}
Context("When a log pipeline with TLS Cert that does not match the Key is created", Ordered, func() {
BeforeAll(func() {
k8sObjects := makeResources()
DeferCleanup(func() {
Expect(kitk8s.DeleteObjects(ctx, k8sClient, k8sObjects...)).Should(Succeed())
})
Expect(kitk8s.CreateObjects(ctx, k8sClient, k8sObjects...)).Should(Succeed())
})
It("Should set ConfigurationGenerated condition to False in pipeline", func() {
assert.LogPipelineHasCondition(ctx, k8sClient, pipelineName, metav1.Condition{
Type: conditions.TypeConfigurationGenerated,
Status: metav1.ConditionFalse,
Reason: conditions.ReasonTLSConfigurationInvalid,
})
})
It("Should set TelemetryFlowHealthy condition to False in pipeline", func() {
assert.LogPipelineHasCondition(ctx, k8sClient, pipelineName, metav1.Condition{
Type: conditions.TypeFlowHealthy,
Status: metav1.ConditionFalse,
Reason: conditions.ReasonSelfMonConfigNotGenerated,
})
})
It("Should set LogComponentsHealthy condition to False in Telemetry", func() {
assert.TelemetryHasState(ctx, k8sClient, operatorv1alpha1.StateWarning)
assert.TelemetryHasCondition(ctx, k8sClient, metav1.Condition{
Type: conditions.TypeLogComponentsHealthy,
Status: metav1.ConditionFalse,
Reason: conditions.ReasonTLSConfigurationInvalid,
})
})
})
})