-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(kube-hunter): Add integration test for kube-hunter command
Signed-off-by: Daniel Pacak <pacak.daniel@gmail.com>
- Loading branch information
1 parent
bce75c3
commit 728e9b0
Showing
6 changed files
with
138 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package itest | ||
|
||
import ( | ||
"context" | ||
"os/exec" | ||
"time" | ||
|
||
. "github.com/onsi/gomega/gbytes" | ||
|
||
"github.com/aquasecurity/starboard/pkg/kube" | ||
. "github.com/onsi/gomega/gstruct" | ||
|
||
. "github.com/onsi/gomega/gexec" | ||
apiextentions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" | ||
|
||
meta "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Starboard CLI", func() { | ||
|
||
BeforeEach(func() { | ||
command := exec.Command(pathToStarboardCLI, []string{"init", "-v", "3"}...) | ||
session, err := Start(command, GinkgoWriter, GinkgoWriter) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Eventually(session).Should(Exit(0)) | ||
}) | ||
|
||
PDescribe("Running init command", func() { | ||
It("should initialize Starboard", func() { | ||
|
||
crdsList, err := apiextensionsClientset.CustomResourceDefinitions().List(context.TODO(), meta.ListOptions{}) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
GetNames := func(crds []apiextentions.CustomResourceDefinition) []string { | ||
names := make([]string, len(crds)) | ||
for i, crd := range crds { | ||
names[i] = crd.Name | ||
} | ||
return names | ||
} | ||
|
||
Expect(crdsList.Items).To(WithTransform(GetNames, ContainElements( | ||
"ciskubebenchreports.aquasecurity.github.io", | ||
"configauditreports.aquasecurity.github.io", | ||
"kubehunterreports.aquasecurity.github.io", | ||
"vulnerabilities.aquasecurity.github.io", | ||
))) | ||
|
||
_, err = kubernetesClientset.CoreV1().Namespaces().Get(context.TODO(), "starboard", meta.GetOptions{}) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
// TODO Assert other Kubernetes resources that we create in the init command | ||
}) | ||
}) | ||
|
||
PDescribe("Running version command", func() { | ||
It("should print the current version of the executable binary", func() { | ||
command := exec.Command(pathToStarboardCLI, []string{"version"}...) | ||
session, err := Start(command, GinkgoWriter, GinkgoWriter) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Eventually(session).Should(Say("Starboard Version: {Version:dev Commit:none Date:unknown}\n")) | ||
}) | ||
}) | ||
|
||
Describe("Running kube-hunter", func() { | ||
It("should run kube-hunter", func() { | ||
|
||
command := exec.Command(pathToStarboardCLI, "kube-hunter", "-v", "3", "--delete-scan-job=false") | ||
session, err := Start(command, GinkgoWriter, GinkgoWriter) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Eventually(session, 2*time.Minute).Should(Exit(0)) | ||
|
||
report, err := starboardClientset.AquasecurityV1alpha1().KubeHunterReports(). | ||
Get(context.TODO(), "cluster", meta.GetOptions{}) | ||
|
||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(report.Labels).To(MatchAllKeys(Keys{ | ||
kube.LabelResourceKind: Equal("Cluster"), | ||
kube.LabelResourceName: Equal("cluster"), | ||
})) | ||
}) | ||
}) | ||
|
||
//AfterEach(func() { | ||
// command := exec.Command(pathToStarboardCLI, []string{"cleanup", "-v", "3"}...) | ||
// session, err := Start(command, GinkgoWriter, GinkgoWriter) | ||
// Expect(err).ToNot(HaveOccurred()) | ||
// Eventually(session).Should(Exit(0)) | ||
// | ||
// // TODO We have to wait for the termination of the starboard namespace. Otherwise the init command fails | ||
// // TODO when it attempts to create Kubernetes objects in the namespace that is being terminated. | ||
// // TODO Maybe the cleanup command should block and wait unit the namespace is terminated? | ||
// Eventually(func() bool { | ||
// _, err := kubernetesClientset.CoreV1().Namespaces().Get(context.TODO(), "starboard", meta.GetOptions{}) | ||
// return errors.IsNotFound(err) | ||
// }, 10*time.Second).Should(BeTrue()) | ||
//}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters