MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestTLSSkipVerifyCombinations

Function TestTLSSkipVerifyCombinations

rest/server_context_test.go:380–441  ·  view source on GitHub ↗

CBG-1518 - Test CA Certificate behaviour with and with Bootstrap.ServerTLSSkipVerify

(t *testing.T)

Source from the content-addressed store, hash-verified

378
379// CBG-1518 - Test CA Certificate behaviour with and with Bootstrap.ServerTLSSkipVerify
380func 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 }

Callers

nothing calls this directly

Calls 7

ValidateMethod · 0.95
PtrFunction · 0.92
TestCtxFunction · 0.92
IsEnterpriseEditionFunction · 0.92
RunMethod · 0.65
ContainsMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected