Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding smoke tests #653

Merged
merged 60 commits into from
Mar 7, 2023
Merged
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
76563ce
adding smoke tests
Prateeknandle Jan 12, 2023
f42befa
refractor
Prateeknandle Jan 14, 2023
416b21b
sleep time decrese
Prateeknandle Jan 14, 2023
73356a2
sleep time increase
Prateeknandle Jan 14, 2023
8d792bb
adding test for network policy
Prateeknandle Jan 18, 2023
c64031a
printing policy
Prateeknandle Jan 18, 2023
d3649df
adding cases
Prateeknandle Jan 18, 2023
4b51b34
additional time removing
Prateeknandle Jan 18, 2023
e173607
adding sleep time
Prateeknandle Jan 18, 2023
d552060
adding sleep time 20&25
Prateeknandle Jan 18, 2023
5e8b897
decreasing time
Prateeknandle Jan 19, 2023
458f11c
print
Prateeknandle Jan 19, 2023
f209db6
looping discover cmd
Prateeknandle Jan 20, 2023
c0610d5
adding sleep time
Prateeknandle Jan 20, 2023
e5108ae
printing statement
Prateeknandle Jan 20, 2023
68e6331
looping network policy
Prateeknandle Jan 20, 2023
f9ce105
cleaning up
Prateeknandle Jan 20, 2023
a099eeb
clean up
Prateeknandle Jan 20, 2023
d583ee8
making func generic
Prateeknandle Jan 23, 2023
5298228
adding flag
Prateeknandle Jan 23, 2023
c6427a1
adding flag for network policy
Prateeknandle Jan 23, 2023
7596371
changing tests
Prateeknandle Jan 24, 2023
18d5c9a
clean up
Prateeknandle Jan 24, 2023
db59e84
tcp to udp for ingress
Prateeknandle Jan 24, 2023
22677a8
removing print statement
Prateeknandle Jan 24, 2023
a919602
print statement
Prateeknandle Jan 24, 2023
8bfc019
udp to tcp
Prateeknandle Jan 24, 2023
3143cd0
udp to tcp
Prateeknandle Jan 24, 2023
4331cae
tcp to udp
Prateeknandle Jan 24, 2023
331edde
flag_i
Prateeknandle Jan 24, 2023
6cdf066
flag_i
Prateeknandle Jan 24, 2023
995fb2f
print
Prateeknandle Jan 24, 2023
f97cac8
print
Prateeknandle Jan 24, 2023
76acff0
print
Prateeknandle Jan 24, 2023
3fb9dba
break remove
Prateeknandle Jan 24, 2023
ddfa474
break add
Prateeknandle Jan 24, 2023
4fea428
adding label
Prateeknandle Jan 24, 2023
0781c75
removing label
Prateeknandle Jan 24, 2023
5acf30b
changing test case for network policy
Prateeknandle Jan 25, 2023
2605b1c
print
Prateeknandle Jan 25, 2023
d7addc7
adding test
Prateeknandle Jan 25, 2023
8d7880d
back
Prateeknandle Jan 25, 2023
83a376b
curl cmd check for wordpress
Prateeknandle Feb 6, 2023
557aaff
adding rules
Prateeknandle Feb 6, 2023
bbb6967
handling panic
Prateeknandle Feb 6, 2023
65bdf15
handling panic
Prateeknandle Feb 7, 2023
6643130
refractor
Prateeknandle Feb 7, 2023
04b86bf
change in rule
Prateeknandle Feb 7, 2023
1d4c369
Merge branch 'dev' into smoke_test
Prateeknandle Feb 7, 2023
29322d3
adding egress rule for mysql
Prateeknandle Feb 7, 2023
34f3188
increasing executions
Prateeknandle Feb 7, 2023
ffb0282
check summary logs
Prateeknandle Feb 7, 2023
fbc75da
check summary logs
Prateeknandle Feb 7, 2023
738ad9d
check summary logs
Prateeknandle Feb 7, 2023
4cc3eb6
increasing time
Prateeknandle Feb 7, 2023
c1b4c65
adding summary tests
Prateeknandle Feb 14, 2023
ff08bcc
adding summary rules
Prateeknandle Feb 16, 2023
2a36fec
removing print for summary
Prateeknandle Feb 16, 2023
511309a
print
Prateeknandle Feb 16, 2023
23c0942
cnt print
Prateeknandle Feb 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refractor
Signed-off-by: Prateeknandle <prateeknandle@gmail.com>
  • Loading branch information
Prateeknandle committed Feb 7, 2023
commit 6643130376183c14a4373cd383ab8d13ce155827
103 changes: 55 additions & 48 deletions tests/smoke/smoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,56 @@ func checksyspolicyrules(rules []string, policy types.KubeArmorPolicy) int {
return flag
}

func checkntwpolicyrules(policies []nv1.NetworkPolicy) (int, int) {
flag := 0
flag_i := 0
for i := range policies {
var p string
var port int
if policies[i].Spec.PodSelector.MatchLabels["app"] == "wordpress" {
flag = 0
for _, e := range policies[i].Spec.Egress {
if e.Ports[0].Port != nil {
if e.Ports[0].Protocol != nil {
p = (string(*e.Ports[0].Protocol))
}
port = e.Ports[0].Port.IntValue()
if p == "TCP" && port == 3306 {
flag += 1
}
} else {
p = (string(*e.Ports[0].Protocol))
if p == "UDP" {
flag += 1
}
}
}
} else if policies[i].Spec.PodSelector.MatchLabels["app"] == "mysql" {
flag_i = 0
for _, i := range policies[i].Spec.Ingress {
if i.Ports[0].Port != nil {
if i.Ports[0].Protocol != nil {
p = (string(*i.Ports[0].Protocol))
}
port = i.Ports[0].Port.IntValue()
if p == "TCP" && port == 3306 {
flag_i += 1
}
} else {
p = (string(*i.Ports[0].Protocol))
if p == "UDP" {
flag_i += 1
}
}
}
}
if flag > 0 && flag_i > 0 {
return flag, flag_i
}
}
return flag, flag_i
}

// WordpressPortForward enable port forwarding for wordpress
func WordpressPortForward() error {
if stopChan != nil {
Expand Down Expand Up @@ -138,7 +188,7 @@ func discoversyspolicy(ns string, l string, rules []string, maxcnt int) (types.K
}
err = json.Unmarshal(cmd, &policy)
if err != nil {
log.Error().Msgf("Failed to unmarshal the policy after %v iteration : %v", cnt, err)
log.Error().Msgf("Failed to unmarshal the system policy : %v", err)
}

flag := checksyspolicyrules(rules, policy)
Expand All @@ -162,7 +212,6 @@ func discovernetworkpolicy(ns string, maxcnt int) ([]nv1.NetworkPolicy, error) {
}

yamls := strings.Split(string(cmd), "---")
fmt.Println("=========>value", len(yamls))
fmt.Println("=========>value", yamls)
if len(yamls) > 0 {
yamls = yamls[:len(yamls)-1]
Expand All @@ -172,55 +221,13 @@ func discovernetworkpolicy(ns string, maxcnt int) ([]nv1.NetworkPolicy, error) {
policy := &nv1.NetworkPolicy{}
err = yaml.Unmarshal([]byte(yamlobject), policy)
if err != nil {
log.Error().Msgf("Failed to unmarshal the policy : %v", err)
log.Error().Msgf("Failed to unmarshal the network policy : %v", err)
}
policies = append(policies, *policy)
fmt.Println("=========>value", policy)
}

for i := range policies {
var p string
var port int
if policies[i].Spec.PodSelector.MatchLabels["app"] == "wordpress" {
flag = 0
for _, e := range policies[i].Spec.Egress {
if e.Ports[0].Port != nil {
if e.Ports[0].Protocol != nil {
p = (string(*e.Ports[0].Protocol))
}
port = e.Ports[0].Port.IntValue()
if p == "TCP" && port == 3306 {
flag += 1
}
} else {
p = (string(*e.Ports[0].Protocol))
if p == "UDP" {
flag += 1
}
}
}
} else if policies[i].Spec.PodSelector.MatchLabels["app"] == "mysql" {
flag_i = 0
for _, i := range policies[i].Spec.Ingress {
if i.Ports[0].Port != nil {
if i.Ports[0].Protocol != nil {
p = (string(*i.Ports[0].Protocol))
}
port = i.Ports[0].Port.IntValue()
if p == "TCP" && port == 3306 {
flag_i += 1
}
} else {
p = (string(*i.Ports[0].Protocol))
if p == "UDP" {
flag_i += 1
}
}
}
}
if flag > 0 && flag_i > 0 {
return policies, err
}
flag, flag_i = checkntwpolicyrules(policies)
if flag > 0 && flag_i > 0 {
return policies, err
}
if flag == 0 || flag_i == 0 {
time.Sleep(10 * time.Second)
Expand Down