Browse Source

fix: use require instead of assert to prevent nil dereference panic in CORS test

The test used assert.NoError (non-fatal) for GetBucketCors, then
immediately accessed getResp.CORSRules. When the API returns an error,
getResp is nil causing a panic. Switch to require.NoError/NotNil/Len
so the test stops before dereferencing a nil response.
pull/8559/head
Chris Lu 2 days ago
parent
commit
66099b7456
  1. 8
      test/s3/cors/s3_cors_test.go

8
test/s3/cors/s3_cors_test.go

@ -140,7 +140,7 @@ func TestCORSConfigurationManagement(t *testing.T) {
Bucket: aws.String(bucketName), Bucket: aws.String(bucketName),
CORSConfiguration: corsConfig, CORSConfiguration: corsConfig,
}) })
assert.NoError(t, err, "Should be able to put CORS configuration")
require.NoError(t, err, "Should be able to put CORS configuration")
// Wait for metadata subscription to update cache // Wait for metadata subscription to update cache
time.Sleep(50 * time.Millisecond) time.Sleep(50 * time.Millisecond)
@ -149,9 +149,9 @@ func TestCORSConfigurationManagement(t *testing.T) {
getResp, err := client.GetBucketCors(context.TODO(), &s3.GetBucketCorsInput{ getResp, err := client.GetBucketCors(context.TODO(), &s3.GetBucketCorsInput{
Bucket: aws.String(bucketName), Bucket: aws.String(bucketName),
}) })
assert.NoError(t, err, "Should be able to get CORS configuration")
assert.NotNil(t, getResp.CORSRules, "CORS configuration should not be nil")
assert.Len(t, getResp.CORSRules, 1, "Should have one CORS rule")
require.NoError(t, err, "Should be able to get CORS configuration")
require.NotNil(t, getResp.CORSRules, "CORS configuration should not be nil")
require.Len(t, getResp.CORSRules, 1, "Should have one CORS rule")
rule := getResp.CORSRules[0] rule := getResp.CORSRules[0]
assert.Equal(t, []string{"*"}, rule.AllowedHeaders, "Allowed headers should match") assert.Equal(t, []string{"*"}, rule.AllowedHeaders, "Allowed headers should match")

Loading…
Cancel
Save