@@ -19,6 +19,7 @@ import (
1919 "errors"
2020 "fmt"
2121 "net/http"
22+ "net/url"
2223 "testing"
2324
2425 "github.com/aws/aws-sdk-go-v2/aws"
@@ -27,6 +28,7 @@ import (
2728 "github.com/aws/aws-sdk-go-v2/service/s3"
2829 "github.com/aws/aws-sdk-go-v2/service/s3/types"
2930 "github.com/aws/smithy-go"
31+ gcaws "gocloud.dev/aws"
3032 "gocloud.dev/blob"
3133 "gocloud.dev/blob/driver"
3234 "gocloud.dev/blob/drivertest"
@@ -324,6 +326,26 @@ func TestOpenBucketFromURL(t *testing.T) {
324326 {"s3://mybucket?fips=true" , false },
325327 // OK, use anonymous.
326328 {"s3://mybucket?anonymous=true" , false },
329+ // OK, use request checksum calculation when_supported
330+ {"s3://mybucket?request_checksum_calculation=when_supported" , false },
331+ // OK, use request checksum calculation when_required
332+ {"s3://mybucket?request_checksum_calculation=when_required" , false },
333+ // OK, use response checksum validation when_supported
334+ {"s3://mybucket?response_checksum_validation=when_supported" , false },
335+ // OK, use response checksum validation when_required
336+ {"s3://mybucket?response_checksum_validation=when_required" , false },
337+ // OK, use both checksum parameters
338+ {"s3://mybucket?request_checksum_calculation=when_required&response_checksum_validation=when_supported" , false },
339+ // OK, case insensitive checksum parameters
340+ {"s3://mybucket?request_checksum_calculation=WHEN_SUPPORTED&response_checksum_validation=When_Required" , false },
341+ // Invalid request checksum value
342+ {"s3://mybucket?request_checksum_calculation=invalid" , true },
343+ // Invalid response checksum value
344+ {"s3://mybucket?response_checksum_validation=invalid" , true },
345+ // Empty request checksum value
346+ {"s3://mybucket?request_checksum_calculation=" , true },
347+ // Empty response checksum value
348+ {"s3://mybucket?response_checksum_validation=" , true },
327349 // Invalid accelerate
328350 {"s3://mybucket?accelerate=bogus" , true },
329351 // Invalid FIPS
@@ -354,6 +376,81 @@ func TestOpenBucketFromURL(t *testing.T) {
354376 }
355377}
356378
379+ func TestChecksumConfigurationPassthrough (t * testing.T ) {
380+ // Test that checksum configuration from URL parameters is properly passed through
381+ // to the S3 bucket options
382+ tests := []struct {
383+ name string
384+ url string
385+ wantRequestChecksumCalculation aws.RequestChecksumCalculation
386+ wantErr bool
387+ }{
388+ {
389+ name : "request checksum when_supported" ,
390+ url : "s3://mybucket?request_checksum_calculation=when_supported" ,
391+ wantRequestChecksumCalculation : aws .RequestChecksumCalculationWhenSupported ,
392+ },
393+ {
394+ name : "request checksum when_required" ,
395+ url : "s3://mybucket?request_checksum_calculation=when_required" ,
396+ wantRequestChecksumCalculation : aws .RequestChecksumCalculationWhenRequired ,
397+ },
398+ {
399+ name : "case insensitive" ,
400+ url : "s3://mybucket?request_checksum_calculation=WHEN_SUPPORTED" ,
401+ wantRequestChecksumCalculation : aws .RequestChecksumCalculationWhenSupported ,
402+ },
403+ {
404+ name : "invalid value" ,
405+ url : "s3://mybucket?request_checksum_calculation=invalid" ,
406+ wantErr : true ,
407+ },
408+ }
409+
410+ ctx := context .Background ()
411+ for _ , test := range tests {
412+ t .Run (test .name , func (t * testing.T ) {
413+ // Parse the URL to extract the bucket name and query parameters
414+ u , err := url .Parse (test .url )
415+ if err != nil {
416+ t .Fatalf ("failed to parse URL: %v" , err )
417+ }
418+
419+ // Create a mock AWS config with the query parameters
420+ cfg , err := awscfg .LoadDefaultConfig (ctx )
421+ if err != nil {
422+ t .Fatalf ("failed to load AWS config: %v" , err )
423+ }
424+
425+ // Apply URL parameters to the config
426+ cfg , err = gcaws .V2ConfigFromURLParams (ctx , u .Query ())
427+ if (err != nil ) != test .wantErr {
428+ t .Errorf ("got err %v want error %v" , err , test .wantErr )
429+ return
430+ }
431+ if err != nil {
432+ return
433+ }
434+
435+ // Create URLOpener to test the integration
436+ opener := & URLOpener {}
437+ bucket , err := opener .OpenBucketURL (ctx , u )
438+ if err != nil {
439+ t .Fatalf ("failed to open bucket: %v" , err )
440+ }
441+ defer bucket .Close ()
442+
443+ // Verify that the checksum configuration was applied
444+ // We can't directly access the internal bucket struct, but we can verify
445+ // that the configuration was applied to the AWS config
446+ if cfg .RequestChecksumCalculation != test .wantRequestChecksumCalculation {
447+ t .Errorf ("got RequestChecksumCalculation %v, want %v" ,
448+ cfg .RequestChecksumCalculation , test .wantRequestChecksumCalculation )
449+ }
450+ })
451+ }
452+ }
453+
357454func TestToServerSideEncryptionType (t * testing.T ) {
358455 tests := []struct {
359456 value string
0 commit comments