forked from baron/baron-sso
74 lines
3.3 KiB
Go
74 lines
3.3 KiB
Go
package domain
|
|
|
|
import "testing"
|
|
|
|
func TestNormalizeRole(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
in string
|
|
want string
|
|
}{
|
|
{name: "super admin unchanged", in: "super_admin", want: RoleSuperAdmin},
|
|
{name: "tenant admin unchanged", in: "tenant_admin", want: RoleTenantAdmin},
|
|
{name: "rp admin unchanged", in: "rp_admin", want: RoleRPAdmin},
|
|
{name: "user unchanged", in: "user", want: RoleUser},
|
|
{name: "super admin hyphen alias", in: "super-admin", want: RoleSuperAdmin},
|
|
{name: "super admin compact alias", in: "superadmin", want: RoleSuperAdmin},
|
|
{name: "legacy admin", in: "admin", want: RoleTenantAdmin},
|
|
{name: "legacy tenant member", in: "tenant_member", want: RoleUser},
|
|
{name: "trim and lower", in: " ADMIN ", want: RoleTenantAdmin},
|
|
{name: "unknown role mapped to user", in: "custom_role", want: RoleUser},
|
|
{name: "empty string mapped to user", in: " ", want: RoleUser},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
if got := NormalizeRole(tc.in); got != tc.want {
|
|
t.Fatalf("NormalizeRole(%q)=%q, want %q", tc.in, got, tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestUserStatusPolicy(t *testing.T) {
|
|
tests := []struct {
|
|
status string
|
|
normalized string
|
|
baronAllowed bool
|
|
orgVisible bool
|
|
worksProvisioned bool
|
|
worksDeprovisioned bool
|
|
}{
|
|
{status: UserStatusActive, normalized: UserStatusActive, baronAllowed: true, orgVisible: true, worksProvisioned: true},
|
|
{status: UserStatusTemporaryLeave, normalized: UserStatusTemporaryLeave, baronAllowed: true, orgVisible: true, worksProvisioned: true},
|
|
{status: UserStatusSuspended, normalized: UserStatusSuspended, orgVisible: true, worksProvisioned: true},
|
|
{status: UserStatusPreboarding, normalized: UserStatusPreboarding},
|
|
{status: UserStatusBaronGuest, normalized: UserStatusBaronGuest, baronAllowed: true, worksDeprovisioned: true},
|
|
{status: UserStatusExtendedLeave, normalized: UserStatusExtendedLeave, worksDeprovisioned: true},
|
|
{status: UserStatusArchived, normalized: UserStatusArchived, worksDeprovisioned: true},
|
|
{status: UserStatusInactive, normalized: UserStatusPreboarding},
|
|
{status: UserStatusLeaveOfAbsence, normalized: UserStatusTemporaryLeave, baronAllowed: true, orgVisible: true, worksProvisioned: true},
|
|
{status: "BARON_ONLY", normalized: UserStatusBaronGuest, baronAllowed: true, worksDeprovisioned: true},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.status, func(t *testing.T) {
|
|
if got := NormalizeUserStatus(tc.status); got != tc.normalized {
|
|
t.Fatalf("NormalizeUserStatus(%q)=%q, want %q", tc.status, got, tc.normalized)
|
|
}
|
|
if got := IsBaronActivityAllowedStatus(tc.status); got != tc.baronAllowed {
|
|
t.Fatalf("IsBaronActivityAllowedStatus(%q)=%v, want %v", tc.status, got, tc.baronAllowed)
|
|
}
|
|
if got := IsOrgVisibleUserStatus(tc.status); got != tc.orgVisible {
|
|
t.Fatalf("IsOrgVisibleUserStatus(%q)=%v, want %v", tc.status, got, tc.orgVisible)
|
|
}
|
|
if got := IsWorksProvisionedUserStatus(tc.status); got != tc.worksProvisioned {
|
|
t.Fatalf("IsWorksProvisionedUserStatus(%q)=%v, want %v", tc.status, got, tc.worksProvisioned)
|
|
}
|
|
if got := IsWorksDeprovisionUserStatus(tc.status); got != tc.worksDeprovisioned {
|
|
t.Fatalf("IsWorksDeprovisionUserStatus(%q)=%v, want %v", tc.status, got, tc.worksDeprovisioned)
|
|
}
|
|
})
|
|
}
|
|
}
|