Files
Gabriel MABILLE 8d84517103 AuthN: Introduce DefaultOrgID function for managed service accounts (#93432)
* Managed Service Accounts: Use AutoAssignOrgID

* Fix the IsExternalServiceAccount function

* Reassign service account role

* Account for AutoAssignOrg

* Update pkg/services/serviceaccounts/models.go

* Simplify IsExternalServiceAccount function

* Add tests

* Easier to understand test

* Revert small change
2024-09-20 14:43:29 +02:00

43 lines
798 B
Go

package serviceaccounts
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestIsExternalServiceAccount(t *testing.T) {
tests := []struct {
name string
login string
want bool
}{
{
name: "external service account",
login: "sa-1-extsvc-test",
want: true,
},
{
name: "not external service account (too short)",
login: "sa-1-test",
want: false,
},
{
name: "not external service account (wrong sa prefix)",
login: "saN-1-extsvc-test",
want: false,
},
{
name: "not external service account (wrong extsvc prefix)",
login: "sa-1-extsvcN-test",
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := IsExternalServiceAccount(tt.login)
require.Equal(t, tt.want, got)
})
}
}