-
Notifications
You must be signed in to change notification settings - Fork 11
/
e2e_egress_test.go
109 lines (92 loc) · 3.04 KB
/
e2e_egress_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
102
103
104
105
106
107
108
109
package e2e
import (
"strings"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/flomesh-io/fsm/tests/framework"
)
var _ = FSMDescribe("HTTP and HTTPS Egress",
FSMDescribeInfo{
Tier: 1,
Bucket: 3,
OS: OSCrossPlatform,
},
func() {
Context("Egress", func() {
const sourceNs = "client"
It("Allows egress traffic when enabled", func() {
// Install FSM
installOpts := Td.GetFSMInstallOpts()
installOpts.EgressEnabled = true
Expect(Td.InstallFSM(installOpts)).To(Succeed())
meshConfig, _ := Td.GetMeshConfig(Td.FsmNamespace)
// Create Test NS
Expect(Td.CreateNs(sourceNs, nil)).To(Succeed())
Expect(Td.AddNsToMesh(true, sourceNs)).To(Succeed())
// Get simple Pod definitions for the client
svcAccDef, podDef, svcDef, err := Td.GetOSSpecificSleepPod(sourceNs)
Expect(err).NotTo(HaveOccurred())
_, err = Td.CreateServiceAccount(sourceNs, &svcAccDef)
Expect(err).NotTo(HaveOccurred())
srcPod, err := Td.CreatePod(sourceNs, podDef)
Expect(err).NotTo(HaveOccurred())
_, err = Td.CreateService(sourceNs, svcDef)
Expect(err).NotTo(HaveOccurred())
// Expect it to be up and running in it's receiver namespace
Expect(Td.WaitForPodsRunningReady(sourceNs, 1, nil)).To(Succeed())
protocols := []string{
"http://",
"https://",
}
egressURLs := []string{
"edition.cnn.com",
"github.com",
}
var urls []string
for _, protocol := range protocols {
for _, test := range egressURLs {
urls = append(urls, protocol+test)
}
}
for _, url := range urls {
cond := Td.WaitForRepeatedSuccess(func() bool {
result := Td.HTTPRequest(HTTPRequestDef{
SourceNs: srcPod.Namespace,
SourcePod: srcPod.Name,
SourceContainer: srcPod.Name,
Destination: url,
})
if result.Err != nil || result.StatusCode != 200 {
Td.T.Logf("%s > REST req failed (status: %d) %v", url, result.StatusCode, result.Err)
return false
}
Td.T.Logf("%s > REST req succeeded: %d", url, result.StatusCode)
return true
}, 5, Td.ReqSuccessTimeout)
Expect(cond).To(BeTrue())
}
By("Disabling Egress")
meshConfig.Spec.Traffic.EnableEgress = false
_, err = Td.UpdateFSMConfig(meshConfig)
Expect(err).NotTo(HaveOccurred())
for _, url := range urls {
cond := Td.WaitForRepeatedSuccess(func() bool {
result := Td.HTTPRequest(HTTPRequestDef{
SourceNs: srcPod.Namespace,
SourcePod: srcPod.Name,
SourceContainer: srcPod.Name,
Destination: url,
})
if result.Err == nil || !strings.Contains(result.Err.Error(), "command terminated with exit code 7 ") {
Td.T.Logf("%s > REST req failed incorrectly (status: %d) %v", url, result.StatusCode, result.Err)
return false
}
Td.T.Logf("%s > REST req failed correctly: %v", url, result.Err)
return true
}, 5 /*success count threshold*/, 60*time.Second /*timeout*/)
Expect(cond).To(BeTrue())
}
})
})
})