Skip to content

Commit

Permalink
1. fix failing test due to log message assertion (#812)
Browse files Browse the repository at this point in the history
2. modify log level
  • Loading branch information
patilpankaj212 authored May 26, 2021
1 parent 0a1912f commit a4d7af9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/http-server/webhook-scan-logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (g *APIHandler) getLogs(w http.ResponseWriter, r *http.Request) {
}

func (g *APIHandler) getLogByUID(w http.ResponseWriter, r *http.Request) {
zap.S().Info("handle: validating webhook's get log by uid request")
zap.S().Debug("handle: validating webhook's get log by uid request")

if !config.GetK8sAdmissionControl().Dashboard {
apiErrorResponse(w, ErrDashboardDisabled.Error(), http.StatusBadRequest)
Expand Down
17 changes: 10 additions & 7 deletions test/e2e/validatingwebhook/validating_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ var _ = Describe("ValidatingWebhook", func() {
os.RemoveAll(certsFolder)
})

// log message to be asserted when sever starts
assertLogMessage := "https server listening at port %s"

Describe("terrascan server as validating webhook with various available config options", func() {

When("validating webhook with default 'k8s-admission-control' config", func() {
Expand All @@ -121,6 +124,7 @@ var _ = Describe("ValidatingWebhook", func() {
var session *gexec.Session
var webhookConfig *admissionv1.ValidatingWebhookConfiguration
var configFileName string
port := "9010"

It("server should start running on port 9010", func() {
configFileName = "config1.toml"
Expand All @@ -131,11 +135,10 @@ var _ = Describe("ValidatingWebhook", func() {
os.Setenv(k8sWebhookAPIKey, apiKeyValue)
args := []string{"server", "-c", configFileName, "--cert-path", certFileAbsPath, "--key-path", privKeyFileAbsPath, "-l", "debug"}
session = helper.RunCommand(terrascanBinaryPath, outWriter, errWriter, args...)
Eventually(session.Err, defaultTimeout).Should(gbytes.Say("http server listening at port 9010"))
Eventually(session.Err, defaultTimeout).Should(gbytes.Say(fmt.Sprintf(assertLogMessage, port)))
})

Context("in blind mode, log end points return error response", func() {
port := "9010"
myIP, err := validatingwebhook.GetIP()
When("request is made to the get a single log endpoint", func() {
It("should return a 400 bad request response", func() {
Expand Down Expand Up @@ -208,7 +211,7 @@ var _ = Describe("ValidatingWebhook", func() {
os.Setenv(k8sWebhookAPIKey, apiKeyValue)
args := []string{"server", "-c", configFileName, "--cert-path", certFileAbsPath, "--key-path", privKeyFileAbsPath, "-p", port, "-l", "debug"}
session = helper.RunCommand(terrascanBinaryPath, outWriter, errWriter, args...)
Eventually(session.Err, defaultTimeout).Should(gbytes.Say("http server listening at port 9011"))
Eventually(session.Err, defaultTimeout).Should(gbytes.Say(fmt.Sprintf(assertLogMessage, port)))
})

When("request is made to add server as a validating webhook", func() {
Expand Down Expand Up @@ -257,7 +260,7 @@ var _ = Describe("ValidatingWebhook", func() {
os.Setenv(k8sWebhookAPIKey, apiKeyValue)
args := []string{"server", "-c", configFileName, "--cert-path", certFileAbsPath, "--key-path", privKeyFileAbsPath, "-p", port, "-l", "debug"}
session = helper.RunCommand(terrascanBinaryPath, outWriter, errWriter, args...)
Eventually(session.Err, defaultTimeout).Should(gbytes.Say("http server listening at port 9012"))
Eventually(session.Err, defaultTimeout).Should(gbytes.Say(fmt.Sprintf(assertLogMessage, port)))
})

When("request is made to add server as a validating webhook", func() {
Expand Down Expand Up @@ -304,7 +307,7 @@ var _ = Describe("ValidatingWebhook", func() {
os.Setenv(k8sWebhookAPIKey, apiKeyValue)
args := []string{"server", "-c", configFileName, "--cert-path", certFileAbsPath, "--key-path", privKeyFileAbsPath, "-p", port, "-l", "debug"}
session = helper.RunCommand(terrascanBinaryPath, outWriter, errWriter, args...)
Eventually(session.Err, defaultTimeout).Should(gbytes.Say("http server listening at port 9013"))
Eventually(session.Err, defaultTimeout).Should(gbytes.Say(fmt.Sprintf(assertLogMessage, port)))
})

When("request is made to add server as a validating webhook", func() {
Expand Down Expand Up @@ -353,7 +356,7 @@ var _ = Describe("ValidatingWebhook", func() {
os.Setenv(k8sWebhookAPIKey, apiKeyValue)
args := []string{"server", "-c", configFileName, "--cert-path", certFileAbsPath, "--key-path", privKeyFileAbsPath, "-p", port, "-l", "debug"}
session = helper.RunCommand(terrascanBinaryPath, outWriter, errWriter, args...)
Eventually(session.Err, defaultTimeout).Should(gbytes.Say("http server listening at port 9014"))
Eventually(session.Err, defaultTimeout).Should(gbytes.Say(fmt.Sprintf(assertLogMessage, port)))
})

When("request is made to add server as a validating webhook", func() {
Expand Down Expand Up @@ -400,7 +403,7 @@ var _ = Describe("ValidatingWebhook", func() {
os.Setenv(k8sWebhookAPIKey, apiKeyValue)
args := []string{"server", "-c", configFileName, "--cert-path", certFileAbsPath, "--key-path", privKeyFileAbsPath, "-p", port, "-l", "debug"}
session = helper.RunCommand(terrascanBinaryPath, outWriter, errWriter, args...)
Eventually(session.Err, defaultTimeout).Should(gbytes.Say("http server listening at port 9015"))
Eventually(session.Err, defaultTimeout).Should(gbytes.Say(fmt.Sprintf(assertLogMessage, port)))
})

When("request is made to add server as a validating webhook", func() {
Expand Down

0 comments on commit a4d7af9

Please sign in to comment.