Skip to content

Commit 2477eea

Browse files
committed
Initial test for connection file
Signed-off-by: ZIV NEVO <[email protected]>
1 parent cfa6718 commit 2477eea

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

pkg/analyzer/policies_synthesizer_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,15 @@ func TestPoliciesSynthesizerAPIDnsPort(t *testing.T) {
131131
}
132132
}
133133

134+
func TestPoliciesSynthesizerConnectionsFile(t *testing.T) {
135+
dirPath := filepath.Join(getTestsDir(), "sockshop", "manifests")
136+
connFilePath := filepath.Join(getTestsDir(), "sockshop", "connections.txt")
137+
synthesizer := NewPoliciesSynthesizer(WithConnectionsFile(connFilePath))
138+
netpols, err := synthesizer.PoliciesFromFolderPaths([]string{dirPath})
139+
require.Nil(t, err)
140+
require.Len(t, netpols, 15)
141+
}
142+
134143
func TestPoliciesSynthesizerAPIFatalError(t *testing.T) {
135144
dirPath1 := filepath.Join(getTestsDir(), "k8s_wordpress_example")
136145
dirPath2 := filepath.Join(getTestsDir(), "badPath")

tests/sockshop/connections.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
sock-shop/deployment/orders -> sock-shop/service/catalogue | TCP:80
2+
sock-shop/deployment/catalogue -> sock-shop/deployment/catalogue-db
3+
# sock-shop/deployment/orders -> 59.48.20.0/24 | TCP:443
4+
5+
# Known workloads in NS ns1, can connect to known workloads in NS sock-shop, named session-db
6+
sock-shop/_/_ -> sock-shop/_/session-db
7+
8+
# All workloads in NS ns1, can connect to the deployment catalogue-db in NS sock-shop
9+
ns1/*/* -> sock-shop/deployment/shipping
10+
11+
# All workloads in the cluster, can connect to the deployment catalogue-db in NS sock-shop
12+
*/*/* -> sock-shop/deployment/orders
13+
14+
# 0.0.0.0/0 -> sock-shop/deployment/catalogue-db
15+
16+
17+
18+
# ns1/*/session-db # not supported
19+
# ns1/deployment/* # not supported
20+
# */deployment/* # not supported
21+
# */deployment/session-db # not supported

0 commit comments

Comments
 (0)