@@ -246,27 +246,33 @@ func TestBackend_StorePayload(t *testing.T) {
246246
247247// TestBackend_StorePayload_Insecure tests the StorePayload functionality with both secure and insecure configurations.
248248// It verifies that:
249- // 1. In secure mode, the backend should reject connections to untrusted registries
250- // 2. In insecure mode, the backend should attempt to connect but fail due to missing image
249+ // 1. In secure mode, the backend should reject connections to untrusted registries due to TLS certificate verification failure
250+ // 2. In insecure mode, the backend should successfully connect and upload signatures, bypassing TLS verification
251251func TestBackend_StorePayload_Insecure (t * testing.T ) {
252252 // Setup test registry with self-signed certificate
253253 s , registryURL := setupTestRegistry (t )
254254 defer s .Close ()
255255
256256 testCases := []struct {
257- name string
258- insecure bool
259- wantErrMsg string
257+ name string
258+ insecure bool
259+ wantErr bool
260+ wantErrMsg string
261+ description string
260262 }{
261263 {
262- name : "secure mode - should reject untrusted registry" ,
263- insecure : false ,
264- wantErrMsg : "tls: failed to verify certificate: x509:" ,
264+ name : "secure mode with untrusted certificate" ,
265+ insecure : false ,
266+ wantErr : true ,
267+ wantErrMsg : "tls: failed to verify certificate: x509:" ,
268+ description : "Should reject connection to registry with self-signed certificate" ,
265269 },
266270 {
267- name : "insecure mode - should attempt connection but fail due to missing image" ,
268- insecure : true ,
269- wantErrMsg : "getting signed image: entity not found in registry" ,
271+ name : "insecure mode bypassing TLS verification" ,
272+ insecure : true ,
273+ wantErr : false ,
274+ wantErrMsg : "" ,
275+ description : "Should successfully connect and upload signature despite untrusted certificate" ,
270276 },
271277 }
272278
@@ -311,12 +317,17 @@ func TestBackend_StorePayload_Insecure(t *testing.T) {
311317 PayloadFormat : formats .PayloadTypeSimpleSigning ,
312318 })
313319
314- if err == nil {
315- t .Error ("expected error but got nil" )
316- return
317- }
318- if ! strings .Contains (err .Error (), tc .wantErrMsg ) {
319- t .Errorf ("error message mismatch\n got: %v\n want: %v" , err , tc .wantErrMsg )
320+ // Validate test results based on expected outcome
321+ if tc .wantErr {
322+ if err == nil {
323+ t .Errorf ("%s: expected error but got nil" , tc .description )
324+ return
325+ }
326+ if tc .wantErrMsg != "" && ! strings .Contains (err .Error (), tc .wantErrMsg ) {
327+ t .Errorf ("%s: error message mismatch\n got: %v\n want: %v" , tc .description , err , tc .wantErrMsg )
328+ }
329+ } else if err != nil {
330+ t .Errorf ("%s: expected success but got error: %v" , tc .description , err )
320331 }
321332 })
322333 }
0 commit comments