Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

Commit

Permalink
fix!: require .spec field in CRD validation (#682)
Browse files Browse the repository at this point in the history
* fix(e2e): correctly validate CRD rejection
* fix(e2e): add test validating template.type
  • Loading branch information
Flydiverny authored Apr 6, 2021
1 parent 483fb90 commit e43a6b8
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ spec:

validation:
openAPIV3Schema:
required:
- spec
properties:
spec:
type: object
Expand Down
2 changes: 1 addition & 1 deletion e2e/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM node:12-alpine
RUN mkdir /app
WORKDIR /app
COPY package.json package-lock.json /app/
RUN npm install
RUN npm ci

# Copy app to source directory
COPY . /app
Expand Down
2 changes: 1 addition & 1 deletion e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ To better understand how they are being run take a look at `run-e2e-suite.sh`.
kind create cluster \
--name es-dev-cluster \
--config ./kind.yaml \
--image "kindest/node:v1.15.3"
--image "kindest/node:v1.16.15"
export KUBECONFIG="$(kind get kubeconfig-path --name="es-dev-cluster")"
Expand Down
6 changes: 2 additions & 4 deletions e2e/run-e2e-suite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ trap cleanup EXIT
kubectl apply -f ${DIR}/localstack.deployment.yaml

CHART_DIR="$(dirname "$DIR")/charts/kubernetes-external-secrets"
HELM_TEMPLATE_ARGS="e2e ${CHART_DIR}"

helm template ${HELM_TEMPLATE_ARGS} \
--include-crds \
helm install e2e ${CHART_DIR} \
--set image.repository=external-secrets \
--set image.tag=test \
--set env.LOG_LEVEL=debug \
Expand All @@ -83,7 +81,7 @@ helm template ${HELM_TEMPLATE_ARGS} \
--set env.AWS_DEFAULT_REGION=us-east-1 \
--set env.AWS_REGION=us-east-1 \
--set env.POLLER_INTERVAL_MILLISECONDS=1000 \
--set env.LOCALSTACK_STS_URL=http://sts | kubectl apply -f -
--set env.LOCALSTACK_STS_URL=http://sts

echo -e "${BGREEN}Granting permissions to external-secrets e2e service account...${NC}"
kubectl create serviceaccount external-secrets-e2e || true
Expand Down
5 changes: 3 additions & 2 deletions e2e/tests/crd.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('CRD', () => {
})

it('should reject invalid ExternalSecret manifests', async () => {
kubeClient
return kubeClient
.apis[customResourceManifest.spec.group]
.v1.namespaces('default')[customResourceManifest.spec.names.plural]
.post({
Expand All @@ -48,6 +48,7 @@ describe('CRD', () => {
}
}
})
.catch(err => expect(err).to.be.an('error'))
.then(() => { throw new Error('was not supposed to succeed') })
.catch((err) => expect(err).to.match(/spec: Required value/))
})
})
51 changes: 50 additions & 1 deletion e2e/tests/secrets-manager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ describe('secretsmanager', async () => {
expect(secret.body.metadata.labels.secretLabel).to.equal('Hellofoo123')
})

it('should pull TLS secret from secretsmanager', async () => {
it('should pull TLS secret from secretsmanager - type', async () => {
let result = await createSecret({
Name: `e2e/${uuid}/tls/cert`,
SecretString: '{"crt":"foo","key":"bar"}'
Expand Down Expand Up @@ -171,6 +171,55 @@ describe('secretsmanager', async () => {
expect(secret.body.type).to.equal('kubernetes.io/tls')
})

it('should pull TLS secret from secretsmanager - template', async () => {
let result = await createSecret({
Name: `e2e/${uuid}/tls/cert-template`,
SecretString: '{"crt":"foo","key":"bar"}'
}).catch(err => {
expect(err).to.equal(null)
})

result = await kubeClient
.apis[customResourceManifest.spec.group]
.v1.namespaces('default')[customResourceManifest.spec.names.plural]
.post({
body: {
apiVersion: 'kubernetes-client.io/v1',
kind: 'ExternalSecret',
metadata: {
name: `e2e-secretmanager-tls-template-${uuid}`
},
spec: {
backendType: 'secretsManager',
template: {
type: 'kubernetes.io/tls'
},
data: [
{
key: `e2e/${uuid}/tls/cert-template`,
property: 'crt',
name: 'tls.crt'
},
{
key: `e2e/${uuid}/tls/cert-template`,
property: 'key',
name: 'tls.key'
}
]
}
}
})

expect(result).to.not.equal(undefined)
expect(result.statusCode).to.equal(201)

const secret = await waitForSecret('default', `e2e-secretmanager-tls-template-${uuid}`)
expect(secret).to.not.equal(undefined)
expect(secret.body.data['tls.crt']).to.equal('Zm9v')
expect(secret.body.data['tls.key']).to.equal('YmFy')
expect(secret.body.type).to.equal('kubernetes.io/tls')
})

it('should pull existing secret from secretsmanager in the correct region', async () => {
const smEU = awsConfig.secretsManagerFactory({
region: 'eu-west-1'
Expand Down

0 comments on commit e43a6b8

Please sign in to comment.