CBG-1518 - Test CA Certificate behaviour with and with Bootstrap.ServerTLSSkipVerify
(t *testing.T)
| 378 | |
| 379 | // CBG-1518 - Test CA Certificate behaviour with and with Bootstrap.ServerTLSSkipVerify |
| 380 | func TestTLSSkipVerifyCombinations(t *testing.T) { |
| 381 | errorText := "cannot skip server TLS validation and use CA Cert" |
| 382 | testCases := []struct { |
| 383 | name string |
| 384 | serverTLSSkipVerify *bool |
| 385 | caCert string |
| 386 | expectError bool |
| 387 | }{ |
| 388 | { |
| 389 | name: "CA Provided, explicitly not skipping TLS validation", |
| 390 | serverTLSSkipVerify: base.Ptr(false), |
| 391 | caCert: "t.ca", |
| 392 | expectError: false, |
| 393 | }, |
| 394 | { |
| 395 | name: "CA Provided only", |
| 396 | caCert: "t.ca", |
| 397 | expectError: false, |
| 398 | }, |
| 399 | { |
| 400 | name: "CA Provided and skipping TLS validation", |
| 401 | serverTLSSkipVerify: base.Ptr(true), |
| 402 | caCert: "t.ca", |
| 403 | expectError: true, |
| 404 | }, |
| 405 | { |
| 406 | name: "Skipping TLS validation, no CA", |
| 407 | serverTLSSkipVerify: base.Ptr(true), |
| 408 | caCert: "", |
| 409 | expectError: false, |
| 410 | }, |
| 411 | { |
| 412 | name: "No CA, no TLS validation skip", |
| 413 | expectError: false, |
| 414 | }, |
| 415 | { |
| 416 | name: "No CA, no TLS validation skip explicitly", |
| 417 | serverTLSSkipVerify: base.Ptr(false), |
| 418 | expectError: false, |
| 419 | }, |
| 420 | } |
| 421 | for _, test := range testCases { |
| 422 | t.Run(test.name, func(t *testing.T) { |
| 423 | startupConfig := &StartupConfig{ |
| 424 | Bootstrap: BootstrapConfig{ |
| 425 | CACertPath: test.caCert, |
| 426 | ServerTLSSkipVerify: test.serverTLSSkipVerify, |
| 427 | }, |
| 428 | } |
| 429 | |
| 430 | err := startupConfig.Validate(base.TestCtx(t), base.IsEnterpriseEdition()) |
| 431 | if test.expectError { |
| 432 | assert.Error(t, err) |
| 433 | assert.Contains(t, err.Error(), errorText) |
| 434 | } else if err != nil { |
| 435 | // check if unrelated error |
| 436 | assert.NotContains(t, err.Error(), errorText) |
| 437 | } |