-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #145 from rowi1de/main
- Loading branch information
Showing
16 changed files
with
284 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,9 @@ on: | |
types: | ||
- published | ||
|
||
permissions: | ||
packages: write | ||
|
||
jobs: | ||
build-images: | ||
runs-on: ubuntu-latest | ||
|
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 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 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 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,25 @@ | ||
package handler | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/http" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func (h *Handler) Validate(c *gin.Context) { | ||
if h.cfg.SealedSecrets.CertURL != "" { | ||
configError := fmt.Errorf("validate can't be used with CertURL (%s)", h.cfg.SealedSecrets.CertURL) | ||
c.Data(http.StatusConflict, "text/plain", []byte(configError.Error())) | ||
return | ||
} | ||
err := h.sealer.Validate(c, c.Request.Body) | ||
|
||
if err != nil { | ||
log.Printf("Error in %s: %v\n", Sanitize(c.Request.URL.Path), err) | ||
c.Data(http.StatusBadRequest, "text/plain", []byte(err.Error())) | ||
} else { | ||
c.Data(http.StatusOK, "text/plain", []byte("OK")) | ||
} | ||
} |
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,78 @@ | ||
package handler | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"net/http" | ||
"net/http/httptest" | ||
|
||
"github.com/bakito/sealed-secrets-web/pkg/config" | ||
"github.com/bakito/sealed-secrets-web/pkg/mocks/seal" | ||
"github.com/gin-gonic/gin" | ||
"github.com/golang/mock/gomock" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Handler ", func() { | ||
Context("Validate", func() { | ||
var ( | ||
recorder *httptest.ResponseRecorder | ||
c *gin.Context | ||
mock *gomock.Controller | ||
sealer *seal.MockSealer | ||
h *Handler | ||
cfg *config.Config | ||
) | ||
BeforeEach(func() { | ||
gin.SetMode(gin.ReleaseMode) | ||
recorder = httptest.NewRecorder() | ||
c, _ = gin.CreateTestContext(recorder) | ||
mock = gomock.NewController(GinkgoT()) | ||
sealer = seal.NewMockSealer(mock) | ||
cfg = &config.Config{} | ||
h = &Handler{ | ||
sealer: sealer, | ||
cfg: cfg, | ||
} | ||
}) | ||
|
||
It("should return success if validation succeeds", func() { | ||
c.Request, _ = http.NewRequest("POST", "/v1/validate", bytes.NewReader([]byte(stringDataAsYAML))) | ||
c.Request.Header.Set("Content-Type", "application/x-yaml") | ||
|
||
sealer.EXPECT().Validate(gomock.Any(), gomock.Any()).Return(nil) | ||
|
||
h.Validate(c) | ||
|
||
Ω(recorder.Code).Should(Equal(http.StatusOK)) | ||
Ω(recorder.Body.String()).Should(Equal("OK")) | ||
Ω(recorder.Header().Get("Content-Type")).Should(Equal("text/plain")) | ||
}) | ||
|
||
It("should return an error if validation fails", func() { | ||
c.Request, _ = http.NewRequest("POST", "/v1/validate", bytes.NewReader([]byte(stringDataAsYAML))) | ||
c.Request.Header.Set("Content-Type", "application/x-yaml") | ||
|
||
sealer.EXPECT().Validate(gomock.Any(), gomock.Any()).Return(errors.New("Validation failed")) | ||
|
||
h.Validate(c) | ||
|
||
Ω(recorder.Code).Should(Equal(http.StatusBadRequest)) | ||
Ω(recorder.Body.String()).Should(Equal("Validation failed")) | ||
Ω(recorder.Header().Get("Content-Type")).Should(Equal("text/plain")) | ||
}) | ||
|
||
It("should return an error if certURL is used", func() { | ||
cfg.SealedSecrets.CertURL = "http://sealed-secrets/v1/cert.pem" | ||
c.Request, _ = http.NewRequest("POST", "/v1/validate", bytes.NewReader([]byte(stringDataAsYAML))) | ||
c.Request.Header.Set("Content-Type", "application/x-yaml") | ||
|
||
h.Validate(c) | ||
|
||
Ω(recorder.Code).Should(Equal(http.StatusConflict)) | ||
Ω(recorder.Body.String()).Should(Equal("validate can't be used with CertURL (http://sealed-secrets/v1/cert.pem)")) | ||
Ω(recorder.Header().Get("Content-Type")).Should(Equal("text/plain")) | ||
}) | ||
}) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,34 @@ | ||
#!/bin/sh | ||
|
||
set -eo pipefail | ||
|
||
# install registry | ||
docker run -d --restart=always -p "127.0.0.1:5001:5000" --name kind-registry registry:2 | ||
|
||
# startup kind | ||
curl -L https://raw.githubusercontent.com/bakito/kind-with-registry-action/main/kind-config.yaml -o testdata/e2e/kind-config.yaml | ||
kind create cluster --config=testdata/e2e/kind-config.yaml | ||
|
||
# setup registry | ||
docker network connect kind kind-registry | ||
kubectl apply -f https://raw.githubusercontent.com/bakito/kind-with-registry-action/main/configmap-registry.yaml | ||
|
||
# setup ingress | ||
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml | ||
kubectl wait --namespace ingress-nginx \ | ||
--for=condition=ready pod \ | ||
--selector=app.kubernetes.io/component=controller \ | ||
--timeout=90s | ||
|
||
# build image | ||
./testdata/e2e/buildImage.sh | ||
|
||
# install sealed secrets | ||
helm repo add sealed-secrets https://bitnami-labs.github.io/sealed-secrets | ||
helm install sealed-secrets sealed-secrets/sealed-secrets \ | ||
--namespace sealed-secrets \ | ||
--create-namespace \ | ||
--atomic | ||
|
||
# install sealed secrets web | ||
./testdata/e2e/installSealedSecretsWebChart.sh yaml |
Oops, something went wrong.