@@ -246,32 +246,39 @@ 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
273279 for _ , tc := range testCases {
274280 t .Run (tc .name , func (t * testing.T ) {
281+
275282 // Initialize backend with test configuration
276283 b := & Backend {
277284 cfg : config.Config {
@@ -311,12 +318,19 @@ func TestBackend_StorePayload_Insecure(t *testing.T) {
311318 PayloadFormat : formats .PayloadTypeSimpleSigning ,
312319 })
313320
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 )
321+ // Validate test results based on expected outcome
322+ if tc .wantErr {
323+ if err == nil {
324+ t .Errorf ("%s: expected error but got nil" , tc .description )
325+ return
326+ }
327+ if tc .wantErrMsg != "" && ! strings .Contains (err .Error (), tc .wantErrMsg ) {
328+ t .Errorf ("%s: error message mismatch\n got: %v\n want: %v" , tc .description , err , tc .wantErrMsg )
329+ }
330+ } else {
331+ if err != nil {
332+ t .Errorf ("%s: expected success but got error: %v" , tc .description , err )
333+ }
320334 }
321335 })
322336 }
0 commit comments