Skip to content

Commit da60a0b

Browse files
committed
ADD] Adding e2e test over using env for TLS and mTls
Also fixing bug in get lentgh of archive object in minio-mc Signed-off-by: poyaz <[email protected]>
1 parent 41825f9 commit da60a0b

1 file changed

Lines changed: 128 additions & 4 deletions

File tree

e2e/test-10-self-signed-tls.bats

Lines changed: 128 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,45 @@ DEBUG_DETIK="true"
8989
[ "${output}" = "${expected_content}" ]
9090
}
9191

92+
@test "Given a PVC, When creating a Backup (mTLS with env) of an app, Then expect Restic repository - using self-signed issuer" {
93+
expected_content="expected content for mtls: $(timestamp)"
94+
expected_filename="expected_filename.txt"
95+
96+
given_a_running_operator
97+
given_a_clean_ns
98+
given_s3_storage
99+
give_self_signed_issuer
100+
given_a_subject "${expected_filename}" "${expected_content}"
101+
102+
kubectl apply -f definitions/secrets
103+
kubectl apply -f definitions/backup/config-mtls-env.yaml
104+
yq e '.spec.podSecurityContext.fsGroup='$(id -u)' | .spec.podSecurityContext.runAsUser='$(id -u)'' definitions/backup/backup-mtls-env.yaml | kubectl apply -f -
105+
106+
try "at most 10 times every 5s to get backup named 'k8up-backup-mtls-env' and verify that '.status.started' is 'true'"
107+
verify_object_value_by_label job 'k8up.io/owned-by=backup_k8up-backup-mtls-env' '.status.active' 1 true
108+
109+
wait_until backup/k8up-backup-mtls-env completed
110+
111+
run restic snapshots
112+
113+
echo "---BEGIN restic snapshots output---"
114+
echo "${output}"
115+
echo "---END---"
116+
117+
echo -n "Number of Snapshots >= 1? "
118+
jq -e 'length >= 1' <<< "${output}" # Ensure that there was actually a backup created
119+
120+
run get_latest_snap
121+
122+
run restic dump "${output}" "/data/subject-pvc/${expected_filename}"
123+
124+
echo "---BEGIN actual ${expected_filename}---"
125+
echo "${output}"
126+
echo "---END---"
127+
128+
[ "${output}" = "${expected_content}" ]
129+
}
130+
92131
### End backup section
93132

94133
### Start restore to pvc section
@@ -251,6 +290,30 @@ DEBUG_DETIK="true"
251290
expect_dl_file_in_container 'deploy/subject-dl-deployment' 'subject-container' "/data/${expected_filename}" "${expected_content}"
252291
}
253292

293+
@test "Given an existing Restic repository, When creating a Restore (mTLS with env), Then Restore to S3 (mTLS with env) - using self-signed issuer" {
294+
# Backup
295+
expected_content="Old content for mtls: $(timestamp)"
296+
expected_filename="old_file.txt"
297+
given_a_running_operator
298+
given_a_clean_ns
299+
given_s3_storage
300+
give_self_signed_issuer
301+
given_an_existing_backup "${expected_filename}" "${expected_content}"
302+
303+
# Restore
304+
kubectl apply -f definitions/secrets
305+
kubectl apply -f definitions/restore/config-mtls-env.yaml
306+
yq e '.spec.podSecurityContext.fsGroup='$(id -u)' | .spec.podSecurityContext.runAsUser='$(id -u)'' definitions/restore/s3-mtls-restore-mtls-env.yaml | kubectl apply -f -
307+
308+
try "at most 10 times every 1s to get Restore named 'k8up-s3-mtls-restore-mtls-env' and verify that '.status.started' is 'true'"
309+
try "at most 10 times every 1s to get Job named 'k8up-s3-mtls-restore-mtls-env' and verify that '.status.active' is '1'"
310+
311+
wait_until restore/k8up-s3-mtls-restore-mtls-env completed
312+
verify "'.status.conditions[?(@.type==\"Completed\")].reason' is 'Succeeded' for Restore named 'k8up-s3-mtls-restore-mtls-env'"
313+
314+
expect_dl_file_in_container 'deploy/subject-dl-deployment' 'subject-container' "/data/${expected_filename}" "${expected_content}"
315+
}
316+
254317
### End restore to s3 section
255318

256319
### Start archive to s3 section
@@ -286,7 +349,7 @@ DEBUG_DETIK="true"
286349
run mc ls minio/archive
287350

288351
echo "---BEGIN total archives output---"
289-
total_archives=$(echo -e "${output}" | wc -l)
352+
total_archives=$(echo -n -e "${output}" | wc -l)
290353
echo "${total_archives}"
291354
echo "---END---"
292355

@@ -324,7 +387,7 @@ DEBUG_DETIK="true"
324387
run mc ls minio/archive
325388

326389
echo "---BEGIN total archives output---"
327-
total_archives=$(echo -e "${output}" | wc -l)
390+
total_archives=$(echo -n -e "${output}" | wc -l)
328391
echo "${total_archives}"
329392
echo "---END---"
330393

@@ -362,7 +425,7 @@ DEBUG_DETIK="true"
362425
run mc ls minio/archive
363426

364427
echo "---BEGIN total archives output---"
365-
total_archives=$(echo -e "${output}" | wc -l)
428+
total_archives=$(echo -n -e "${output}" | wc -l)
366429
echo "${total_archives}"
367430
echo "---END---"
368431

@@ -400,7 +463,46 @@ DEBUG_DETIK="true"
400463
run mc ls minio/archive
401464

402465
echo "---BEGIN total archives output---"
403-
total_archives=$(echo -e "${output}" | wc -l)
466+
total_archives=$(echo -n -e "${output}" | wc -l)
467+
echo "${total_archives}"
468+
echo "---END---"
469+
470+
[ "$total_snapshots" -eq "$total_archives" ]
471+
}
472+
473+
@test "Given an existing Restic repository, When creating a Archive (mTLS with env), Then Restore to S3 (mTLS with env) - using self-signed issuer" {
474+
# Backup
475+
expected_content="Old content for mtls: $(timestamp)"
476+
expected_filename="old_file.txt"
477+
given_a_running_operator
478+
given_a_clean_ns
479+
given_s3_storage
480+
give_self_signed_issuer
481+
given_an_existing_backup "${expected_filename}" "${expected_content}"
482+
given_a_clean_archive archive
483+
484+
# Archive
485+
kubectl apply -f definitions/secrets
486+
kubectl apply -f definitions/archive/config-mtls-env.yaml
487+
yq e '.spec.podSecurityContext.fsGroup='$(id -u)' | .spec.podSecurityContext.runAsUser='$(id -u)'' definitions/archive/s3-mtls-archive-mtls-env.yaml | kubectl apply -f -
488+
489+
try "at most 10 times every 1s to get Archive named 'k8up-s3-mtls-archive-mtls-env' and verify that '.status.started' is 'true'"
490+
try "at most 10 times every 1s to get Job named 'k8up-s3-mtls-archive-mtls-env' and verify that '.status.active' is '1'"
491+
492+
wait_until archive/k8up-s3-mtls-archive-mtls-env completed
493+
verify "'.status.conditions[?(@.type==\"Completed\")].reason' is 'Succeeded' for Archive named 'k8up-s3-mtls-archive-mtls-env'"
494+
495+
run restic list snapshots
496+
497+
echo "---BEGIN total restic snapshots output---"
498+
total_snapshots=$(echo -e "${output}" | wc -l)
499+
echo "${total_snapshots}"
500+
echo "---END---"
501+
502+
run mc ls minio/archive
503+
504+
echo "---BEGIN total archives output---"
505+
total_archives=$(echo -n -e "${output}" | wc -l)
404506
echo "${total_archives}"
405507
echo "---END---"
406508

@@ -453,4 +555,26 @@ DEBUG_DETIK="true"
453555
verify "'.status.conditions[?(@.type==\"Completed\")].reason' is 'Succeeded' for Check named 'k8up-check-mtls'"
454556
}
455557

558+
@test "Given a PVC, When creating a Check (mTLS with env) of an app, Then expect Restic repository - using self-signed issuer" {
559+
# Backup
560+
expected_content="Old content for mtls: $(timestamp)"
561+
expected_filename="old_file.txt"
562+
given_a_running_operator
563+
given_a_clean_ns
564+
given_s3_storage
565+
give_self_signed_issuer
566+
given_an_existing_backup "${expected_filename}" "${expected_content}"
567+
568+
# Check
569+
kubectl apply -f definitions/secrets
570+
kubectl apply -f definitions/check/config-mtls-env.yaml
571+
yq e '.spec.podSecurityContext.fsGroup='$(id -u)' | .spec.podSecurityContext.runAsUser='$(id -u)'' definitions/check/check-mtls-env.yaml | kubectl apply -f -
572+
573+
try "at most 10 times every 1s to get Check named 'k8up-check-mtls-env' and verify that '.status.started' is 'true'"
574+
try "at most 10 times every 1s to get Job named 'k8up-check-mtls-env' and verify that '.status.active' is '1'"
575+
576+
wait_until check/k8up-check-mtls-env completed
577+
verify "'.status.conditions[?(@.type==\"Completed\")].reason' is 'Succeeded' for Check named 'k8up-check-mtls-env'"
578+
}
579+
456580
### End check section

0 commit comments

Comments
 (0)