Skip to content

Tests: Add unit test coverage for private uploads, signed URLs, and privacy export - #752

Open
noruzzamans wants to merge 1 commit into
humanmade:masterfrom
noruzzamans:test/add-private-uploads-and-privacy-export-unit-tests
Open

noruzzamans wants to merge 1 commit into
humanmade:masterfrom
noruzzamans:test/add-private-uploads-and-privacy-export-unit-tests

Conversation

@noruzzamans

Copy link
Copy Markdown

Summary

This pull request enhances the unit test coverage of S3_Uploads by adding dedicated tests for private uploads, presigned URLs, ACL modifications, S3 location parsing, resource hints, and GDPR personal data exports in tests/test-s3-uploads.php:

  • S3 location resolution (test_get_s3_location_for_url, test_get_s3_location_for_path): Verifies canonical S3 URLs, upload directory base URLs, s3:// stream paths, and proper null handling for external URLs or non-S3 paths.
  • Resource hints DNS prefetch (test_wp_filter_resource_hints): Verifies that the S3 bucket URL is added to dns-prefetch relation hints, and ensures other relation types remain untouched.
  • Private attachment detection (test_is_private_attachment): Validates default behavior (false) and filtering via the s3_uploads_is_attachment_private hook.
  • Presigned URLs for private attachments (test_add_s3_signed_params_to_attachment_url): Verifies that public attachments remain untouched, private attachments receive signed S3 parameters (X-Amz-Signature), previous query parameters are stripped to prevent signature corruption, and the s3_uploads_private_attachment_url_expiry filter is respected.
  • Image src and srcset signing (test_add_s3_signed_params_to_attachment_image_src, test_add_s3_signed_params_to_attachment_image_srcset): Verifies signed URLs across wp_get_attachment_image_src and responsive wp_calculate_image_srcset sources while handling empty or invalid post IDs.
  • Setting attachment files ACL (test_set_attachment_files_acl): Tests batch ACL updates for attachment files and verifies that the s3_uploads_set_attachment_files_acl action fires with the correct attachment ID and ACL parameter.
  • Automatic private ACL on metadata generation (test_set_attachment_private_on_generate_attachment_metadata): Verifies that when an attachment is marked private, metadata generation automatically triggers private ACL updates for the generated image sizes.
  • GDPR Personal Data Export (test_privacy_personal_data_export_dir_and_file_move): Validates that s3:// exports directories are properly rerouted to a local temp folder (set_wp_privacy_exports_dir), and the created zip archive is securely moved to the S3 exports directory (move_temp_personal_data_to_s3) before the local temp file is unlinked.

Test plan

  • Ran ./tests/run-tests.sh: all 37 tests pass with 107 assertions (increased from 27 tests and 66 assertions).
  • Psalm static analysis runs with 0 errors (No errors found!).
  • Tested against local MinIO S3 object storage container.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant