...

Source file src/edge-infra.dev/pkg/sds/emergencyaccess/rules/validation_test.go

Documentation: edge-infra.dev/pkg/sds/emergencyaccess/rules

     1  package rulesengine
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestUserHasRoles(t *testing.T) {
    10  	tests := map[string]struct {
    11  		eaRoles     []string
    12  		userEARoles []string
    13  		expVal      bool
    14  	}{
    15  		"True one match": {
    16  			eaRoles:     []string{"test1", "test2"},
    17  			userEARoles: []string{"test1"},
    18  			expVal:      true,
    19  		},
    20  		"True all matches": {
    21  			eaRoles:     []string{"test1", "test2"},
    22  			userEARoles: []string{"test1", "test2"},
    23  			expVal:      true,
    24  		},
    25  		"False no match": {
    26  			eaRoles:     []string{"test1"},
    27  			userEARoles: []string{"test2"},
    28  			expVal:      false,
    29  		},
    30  		"False no eaRoles": {
    31  			userEARoles: []string{"test1"},
    32  			expVal:      false,
    33  		},
    34  		"False no userEARoles": {
    35  			eaRoles: []string{"test1"},
    36  			expVal:  false,
    37  		},
    38  		"False no eaRoles or userEARoles": {
    39  			expVal: false,
    40  		},
    41  	}
    42  	for name, tc := range tests {
    43  		t.Run(name, func(t *testing.T) {
    44  			reng := RulesEngine{}
    45  			assert.Equal(t, tc.expVal, reng.UserHasRoles("userID", tc.eaRoles, tc.userEARoles))
    46  		})
    47  	}
    48  }
    49  

View as plain text