Skip to content

Commit

Permalink
add more windows policy UTs
Browse files Browse the repository at this point in the history
  • Loading branch information
paulyufan2 committed Aug 28, 2024
1 parent 462598d commit da75eb2
Showing 1 changed file with 59 additions and 4 deletions.
63 changes: 59 additions & 4 deletions network/policy/policy_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ var _ = Describe("Windows Policies", func() {
}}`),
}

expected_policy := `{"InboundProxyPort":"15003","OutboundProxyPort":"15001","FilterTuple":{"Protocols":"6"},"UserSID":"S-1-5-32-556","InboundExceptions":{},"OutboundExceptions":{}}`
expectedPolicy := `{"InboundProxyPort":"15003","OutboundProxyPort":"15001","FilterTuple":{"Protocols":"6"},"UserSID":"S-1-5-32-556","InboundExceptions":{},"OutboundExceptions":{}}`

generatedPolicy, err := GetHcnL4WFPProxyPolicy(policy)
Expect(err).To(BeNil())
Expect(string(generatedPolicy.Settings)).To(Equal(expected_policy))
Expect(string(generatedPolicy.Settings)).To(Equal(expectedPolicy))
})
})

Expand All @@ -71,11 +71,66 @@ var _ = Describe("Windows Policies", func() {
"Action": "Allow"
}`),
}
expected_policy := `{"Protocols":"TCP","Action":"Allow","Direction":"In"}`
expectedPolicy := `{"Protocols":"TCP","Action":"Allow","Direction":"In"}`

generatedPolicy, err := GetHcnACLPolicy(policy)
Expect(err).To(BeNil())
Expect(string(generatedPolicy.Settings)).To(Equal(expected_policy))
Expect(string(generatedPolicy.Settings)).To(Equal(expectedPolicy))
})
})

Describe("Test GetHcnOutBoundNATPolicy", func() {
It("Should raise error for invalid json", func() {
policy := Policy{
Type: OutBoundNatPolicy,
Data: []byte(`invalid json`),
}

_, err := GetHcnOutBoundNATPolicy(policy, nil)
Expect(err).NotTo(BeNil())
})

It("Should marshall the OutBoundNAT policy correctly", func() {
policy := Policy{
Type: OutBoundNatPolicy,
Data: []byte(`{
"Type": "OutBoundNAT",
"ExceptionList": ["10.240.0.0/16","10.0.0.0/8"]
}`),
}
expectedPolicy := `{"Exceptions":["10.240.0.0/16","10.0.0.0/8"]}`

generatedPolicy, err := GetHcnOutBoundNATPolicy(policy, nil)
Expect(err).To(BeNil())
Expect(string(generatedPolicy.Settings)).To(Equal(expectedPolicy))
})
})

Describe("Test GetHcnRoutePolicy", func() {
It("Should raise error for invalid json", func() {
policy := Policy{
Type: RoutePolicy,
Data: []byte(`invalid json`),
}

_, err := GetHcnRoutePolicy(policy)
Expect(err).NotTo(BeNil())
})

It("Should marshall the Route policy correctly", func() {
policy := Policy{
Type: RoutePolicy,
Data: []byte(`{
"Type": "ROUTE",
"DestinationPrefix": "10.0.0.0/8",
"NeedEncap": true
}`),
}
expectedPolicy := `{"DestinationPrefix":"10.0.0.0/8","NeedEncap":true}`

generatedPolicy, err := GetHcnRoutePolicy(policy)
Expect(err).To(BeNil())
Expect(string(generatedPolicy.Settings)).To(Equal(expectedPolicy))
})
})

Expand Down

0 comments on commit da75eb2

Please sign in to comment.