Skip to content

Commit

Permalink
mod: self-contain bats refresher tests
Browse files Browse the repository at this point in the history
  • Loading branch information
duffney committed Aug 28, 2024
1 parent 2f8bdef commit 3255050
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion test/bats/azure-test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,11 @@ SLEEP_TIME=1
}

@test "validate refresher reconcile count" {
teardown() {
echo "cleaning up"
wait_for_process ${WAIT_TIME} ${SLEEP_TIME} 'kubectl delete keymanagementprovider kmp-akv-refresh --ignore-not-found=true'
rm test.yaml
}
sed -e "s/keymanagementprovider-akv/kmp-akv-refresh/" \
-e "s/1m/1s/" \
-e "s/yourCertName/${NOTATION_PEM_NAME}/" \
Expand All @@ -336,11 +341,27 @@ SLEEP_TIME=1
}

@test "validate refresher updates kmp with latest certificate version" {
cleanup() {
echo "cleaning up"
wait_for_process ${WAIT_TIME} ${SLEEP_TIME} 'kubectl delete keymanagementprovider kmp-akv-refresh --ignore-not-found=true'
rm test.yaml
rm policy.json
}
sed -e "s/keymanagementprovider-akv/kmp-akv-refresh/" \
-e "s/1m/5s/" \
-e "s/yourCertName/${NOTATION_PEM_NAME}/" \
-e '/version: yourCertVersion/d' \
-e "s|https://yourkeyvault.vault.azure.net/|${VAULT_URI}|" \
-e "s/tenantID:/tenantID: ${TENANT_ID}/" \
-e "s/clientID:/clientID: ${IDENTITY_CLIENT_ID}/" \
./config/samples/clustered/kmp/config_v1beta1_keymanagementprovider_akv_refresh_enabled.yaml >test.yaml
run kubectl apply -f test.yaml
assert_success
sleep 5
result=$(kubectl get keymanagementprovider kmp-akv-refresh -o jsonpath='{.status.properties.Certificates[0].Version}')
az keyvault certificate get-default-policy -o json >>policy.json
wait_for_process 20 10 "az keyvault certificate create --vault-name $KEYVAULT_NAME --name $NOTATION_PEM_NAME --policy @policy.json"
sleep 15
run rm policy.json
refreshResult=$(kubectl get keymanagementprovider kmp-akv-refresh -o jsonpath='{.status.properties.Certificates[0].Version}')
[ "$result" != "$refreshResult" ]
}
Expand All @@ -352,6 +373,14 @@ SLEEP_TIME=1
rm policy.json
rm test.yaml
}
sed -e "s/keymanagementprovider-akv/kmp-akv-refresh/" \
-e "s/1m/1s/" \
-e "s/yourCertName/${NOTATION_PEM_NAME}/" \
-e '/version: yourCertVersion/d' \
-e "s|https://yourkeyvault.vault.azure.net/|${VAULT_URI}|" \
-e "s/tenantID:/tenantID: ${TENANT_ID}/" \
-e "s/clientID:/clientID: ${IDENTITY_CLIENT_ID}/" \
./config/samples/clustered/kmp/config_v1beta1_keymanagementprovider_akv_refresh_enabled.yaml >test.yaml
version=$(az keyvault certificate show --vault-name $KEYVAULT_NAME --name $NOTATION_PEM_NAME --query 'sid' -o tsv | rev | cut -d'/' -f1 | rev)
sed -i \
-e "/name: ${NOTATION_PEM_NAME}/a \ \ \ \ \ \ \ \ version: ${version}" \
Expand Down

0 comments on commit 3255050

Please sign in to comment.