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 test for network policy regex #517

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Vincent056
Copy link

@Vincent056 Vincent056 commented May 10, 2024

Added e2e test for configure-network-policies-namespaces rule, test if whitelist-regex works as expected.

This works in-conjunction with ComplianceAsCode/content#11952

@openshift-ci openshift-ci bot requested review from jhrozek and mrogers950 May 10, 2024 00:22
Copy link

openshift-ci bot commented May 10, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Vincent056

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

tests/e2e/serial/main_test.go Show resolved Hide resolved
tests/e2e/serial/main_test.go Outdated Show resolved Hide resolved
@Vincent056
Copy link
Author

/retest

Added e2e test for configure-network-policies-namespaces rule, test if whitelist-regex works as expected
tests/e2e/serial/main_test.go Outdated Show resolved Hide resolved
Co-authored-by: Watson Yuuma Sato <[email protected]>
@yuumasato
Copy link
Member

Sorry @Vincent056 we got an error on t.Skip()
tests/e2e/serial/main_test.go:1965:3: (*testing.common).Skip call has possible formatting directive %s

@Vincent056
Copy link
Author

/retest

@yuumasato
Copy link
Member

@Vincent056 Still the same error:

# github.com/ComplianceAsCode/compliance-operator/tests/e2e/serial
tests/e2e/serial/main_test.go:1965:3: (*testing.common).Skip call has possible formatting directive %s
FAIL	github.com/ComplianceAsCode/compliance-operator/tests/e2e/serial [build failed]
FAIL
make: *** [Makefile:610: e2e-serial] Error 1

Copy link

openshift-ci bot commented Jul 19, 2024

@Vincent056: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-aws-serial 6dd67e0 link true /test e2e-aws-serial

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@rhmdnd rhmdnd added this to the 1.6.0 milestone Aug 9, 2024
@rhmdnd rhmdnd requested review from rhmdnd, xiaojiey and BhargaviGudi and removed request for jhrozek and mrogers950 August 28, 2024 21:03
t.Fatal(err)
}

regextValue := ""
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: regexValue

regextValue := ""

for _, ns := range nsList.Items {
if strings.HasPrefix(ns.Name, "openshift-") || strings.HasPrefix(ns.Name, "kube-") {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for reviewers:

We don't need to add these to the regular expression explicitly since we've baked that into the rule.

https://github.com/ComplianceAsCode/content/blob/master/applications/openshift/networking/configure_network_policies_namespaces/rule.yml#L31

@@ -1933,6 +1934,169 @@ func TestSuspendScanSettingDoesNotCreateScan(t *testing.T) {
}
}

func TestConfigureNetworkPolicy(t *testing.T) {
f := framework.Global
suiteName := "test-configure-network-policy"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We could use suiteNameCompliant and suiteNameNonCompliant to distinguish these and align them closer to their status asserted towards the end of the test.


regextValue = regextValue + ns.ObjectMeta.Name

tp := &compv1alpha1.TailoredProfile{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Similar naming comment as above with the suites (could do something like compliantTailoredProfile or tpCompliant.

Then on line 2010, something like nonCompliantTailoredProfile, or tpNonCompliant.

}
defer f.Client.Delete(context.TODO(), tpNoPass)

ssb := &compv1alpha1.ScanSettingBinding{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Similar naming comment as above.

}
defer f.Client.Delete(context.TODO(), ssb)

ssbNoPass := &compv1alpha1.ScanSettingBinding{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Similar naming comment as above.

Copy link

@rhmdnd rhmdnd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, just minor nits that we can address in a follow up if needed. But it also looks like we need to rebase this anyway, so we can fix them in the next revision, too.

@rhmdnd rhmdnd modified the milestones: 1.6.0, 1.6.1 Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants