github.com/kiali/kiali@v1.84.0/business/checkers/peerauthentications/disabled_meshwide_checker_test.go (about)

     1  package peerauthentications
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/kiali/kiali/config"
     7  	"github.com/kiali/kiali/models"
     8  	"github.com/kiali/kiali/tests/testutils/validations"
     9  )
    10  
    11  // This vals works only with AutoMTls disabled
    12  
    13  // Context: MeshPeerAuthn disabled
    14  // Context: DestinationRule tls mode disabled
    15  // It doesn't return any validation
    16  func TestMeshPeerAuthnDisabledDestRuleDisabled(t *testing.T) {
    17  	testNoDisabledMeshValidations("disabled_meshwide_checker_1.yaml", t)
    18  }
    19  
    20  // Context: MeshPeerAuthn disabled
    21  // Context: DestinationRule tls mode ISTIO_MUTUAL
    22  // It returns a validation
    23  func TestMeshPeerAuthnDisabledDestRuleEnabled(t *testing.T) {
    24  	testWithDisabledMeshValidations("disabled_meshwide_checker_2.yaml", t)
    25  }
    26  
    27  // Context: MeshPeerAuthn disabled
    28  // Context: No Destination Rule at mesh-wide
    29  // It doesn't return any validation
    30  func TestMeshPeerAuthnNoDestRule(t *testing.T) {
    31  	testNoDisabledMeshValidations("disabled_meshwide_checker_3.yaml", t)
    32  }
    33  
    34  func disabledMeshTestPrep(scenario string, t *testing.T) ([]*models.IstioCheck, bool) {
    35  	conf := config.NewConfig()
    36  	config.Set(conf)
    37  
    38  	loader := yamlFixtureLoaderFor(scenario)
    39  	err := loader.Load()
    40  	if err != nil {
    41  		t.Error("Error loading test data.")
    42  	}
    43  
    44  	vals, valid := DisabledMeshWideChecker{
    45  		PeerAuthn:        loader.GetResources().PeerAuthentications[0],
    46  		DestinationRules: loader.GetResources().DestinationRules,
    47  	}.Check()
    48  
    49  	return vals, valid
    50  }
    51  
    52  func testNoDisabledMeshValidations(scenario string, t *testing.T) {
    53  	vals, valid := disabledMeshTestPrep(scenario, t)
    54  	tb := validations.IstioCheckTestAsserter{T: t, Validations: vals, Valid: valid}
    55  	tb.AssertNoValidations()
    56  }
    57  
    58  func testWithDisabledMeshValidations(scenario string, t *testing.T) {
    59  	vals, valid := disabledMeshTestPrep(scenario, t)
    60  	tb := validations.IstioCheckTestAsserter{T: t, Validations: vals, Valid: valid}
    61  	tb.AssertValidationsPresent(1, false)
    62  	tb.AssertValidationAt(0, models.ErrorSeverity, "spec/mtls", "peerauthentications.mtls.disablemeshdestinationrulemissing")
    63  }