From 15ed534c259e6b4fa44e5ce1801162b4e72db4e8 Mon Sep 17 00:00:00 2001 From: IvanHunters Date: Wed, 4 Mar 2026 21:13:22 +0300 Subject: [PATCH] test(bucket): update E2E test for user model and readonly access Update bucket E2E test to match the new per-user access model: - Create bucket with admin (readwrite) and viewer (readonly) users - Test that readwrite user can upload, list, and download objects - Test that readonly user can list and download but cannot upload - Use per-user BucketAccess and credential secret names Signed-off-by: IvanHunters --- hack/e2e-apps/bucket.bats | 59 ++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 17 deletions(-) diff --git a/hack/e2e-apps/bucket.bats b/hack/e2e-apps/bucket.bats index 2621812af..0ec4f75c1 100644 --- a/hack/e2e-apps/bucket.bats +++ b/hack/e2e-apps/bucket.bats @@ -1,7 +1,7 @@ #!/usr/bin/env bats @test "Create and Verify Seeweedfs Bucket" { - # Create the bucket resource + # Create the bucket resource with readwrite and readonly users name='test' kubectl apply -f - < bucket-test-credentials.json + # Get admin (readwrite) credentials + kubectl -n tenant-test get secret bucket-${name}-admin -ojsonpath='{.data.BucketInfo}' | base64 -d > bucket-admin-credentials.json + ADMIN_ACCESS_KEY=$(jq -r '.spec.secretS3.accessKeyID' bucket-admin-credentials.json) + ADMIN_SECRET_KEY=$(jq -r '.spec.secretS3.accessSecretKey' bucket-admin-credentials.json) + BUCKET_NAME=$(jq -r '.spec.bucketName' bucket-admin-credentials.json) - # Get credentials from the secret - ACCESS_KEY=$(jq -r '.spec.secretS3.accessKeyID' bucket-test-credentials.json) - SECRET_KEY=$(jq -r '.spec.secretS3.accessSecretKey' bucket-test-credentials.json) - BUCKET_NAME=$(jq -r '.spec.bucketName' bucket-test-credentials.json) + # Get viewer (readonly) credentials + kubectl -n tenant-test get secret bucket-${name}-viewer -ojsonpath='{.data.BucketInfo}' | base64 -d > bucket-viewer-credentials.json + VIEWER_ACCESS_KEY=$(jq -r '.spec.secretS3.accessKeyID' bucket-viewer-credentials.json) + VIEWER_SECRET_KEY=$(jq -r '.spec.secretS3.accessSecretKey' bucket-viewer-credentials.json) # Start port-forwarding bash -c 'timeout 100s kubectl port-forward service/seaweedfs-s3 -n tenant-root 8333:8333 > /dev/null 2>&1 &' @@ -31,17 +39,34 @@ EOF # Wait for port-forward to be ready timeout 30 sh -ec 'until nc -z localhost 8333; do sleep 1; done' - # Set up MinIO alias with error handling - mc alias set local https://localhost:8333 $ACCESS_KEY $SECRET_KEY --insecure + # --- Test readwrite user (admin) --- + mc alias set rw-user https://localhost:8333 $ADMIN_ACCESS_KEY $ADMIN_SECRET_KEY --insecure - # Upload file to bucket - mc cp bucket-test-credentials.json $BUCKET_NAME/bucket-test-credentials.json + # Admin can upload + echo "readwrite test" > /tmp/rw-test.txt + mc cp /tmp/rw-test.txt rw-user/$BUCKET_NAME/rw-test.txt - # Verify file was uploaded - mc ls $BUCKET_NAME/bucket-test-credentials.json + # Admin can list + mc ls rw-user/$BUCKET_NAME/rw-test.txt - # Clean up uploaded file - mc rm $BUCKET_NAME/bucket-test-credentials.json + # Admin can download + mc cp rw-user/$BUCKET_NAME/rw-test.txt /tmp/rw-test-download.txt + # --- Test readonly user (viewer) --- + mc alias set ro-user https://localhost:8333 $VIEWER_ACCESS_KEY $VIEWER_SECRET_KEY --insecure + + # Viewer can list + mc ls ro-user/$BUCKET_NAME/rw-test.txt + + # Viewer can download + mc cp ro-user/$BUCKET_NAME/rw-test.txt /tmp/ro-test-download.txt + + # Viewer cannot upload (must fail) + echo "readonly test" > /tmp/ro-test.txt + run mc cp /tmp/ro-test.txt ro-user/$BUCKET_NAME/ro-test.txt + [ "$status" -ne 0 ] + + # --- Cleanup --- + mc rm rw-user/$BUCKET_NAME/rw-test.txt kubectl -n tenant-test delete bucket.apps.cozystack.io ${name} }