75 lines
2.3 KiB
Go
75 lines
2.3 KiB
Go
package repository
|
|
|
|
import "testing"
|
|
|
|
func TestDefaultPermissionSeedUsesFinancePermissions(t *testing.T) {
|
|
permissions := map[string]struct{}{}
|
|
for _, permission := range defaultPermissions {
|
|
permissions[permission.Code] = struct{}{}
|
|
}
|
|
|
|
for _, code := range []string{"money:view", "money:payment-link:create"} {
|
|
if _, ok := permissions[code]; ok {
|
|
t.Fatalf("legacy money permission %s must not be part of default seed", code)
|
|
}
|
|
}
|
|
|
|
for _, code := range []string{
|
|
"payment-temporary-link:create",
|
|
"finance:view",
|
|
"finance-application:create",
|
|
"finance-application:audit",
|
|
"finance-withdrawal:view",
|
|
"finance-operation:user-coin-credit",
|
|
"finance-operation:user-coin-debit",
|
|
"finance-operation:user-wallet-credit",
|
|
"finance-operation:user-wallet-debit",
|
|
"finance-operation:coin-seller-coin-credit",
|
|
"finance-operation:coin-seller-coin-debit",
|
|
"host-withdrawal:view",
|
|
} {
|
|
if _, ok := permissions[code]; !ok {
|
|
t.Fatalf("finance permission %s missing from default seed", code)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestDefaultRoleFinancePermissionTemplates(t *testing.T) {
|
|
opsPermissions := seedTestPermissionSet(defaultRolePermissionCodes("ops-admin"))
|
|
opsMigrationPermissions := seedTestPermissionSet(defaultRolePermissionMigrationCodes("ops-admin"))
|
|
|
|
for _, code := range []string{
|
|
"payment-temporary-link:create",
|
|
"finance-application:create",
|
|
"finance-operation:user-coin-credit",
|
|
"finance-operation:user-coin-debit",
|
|
"finance-operation:user-wallet-credit",
|
|
"finance-operation:user-wallet-debit",
|
|
"finance-operation:coin-seller-coin-credit",
|
|
"finance-operation:coin-seller-coin-debit",
|
|
"host-withdrawal:view",
|
|
} {
|
|
if _, ok := opsPermissions[code]; !ok {
|
|
t.Fatalf("ops-admin default permissions missing %s", code)
|
|
}
|
|
if _, ok := opsMigrationPermissions[code]; !ok {
|
|
t.Fatalf("ops-admin migration permissions missing %s", code)
|
|
}
|
|
}
|
|
|
|
if _, ok := opsPermissions["finance-application:audit"]; ok {
|
|
t.Fatal("ops-admin must not receive finance audit permission by default")
|
|
}
|
|
if _, ok := opsMigrationPermissions["finance-application:audit"]; ok {
|
|
t.Fatal("ops-admin migration must not append finance audit permission by default")
|
|
}
|
|
}
|
|
|
|
func seedTestPermissionSet(codes []string) map[string]struct{} {
|
|
out := make(map[string]struct{}, len(codes))
|
|
for _, code := range codes {
|
|
out[code] = struct{}{}
|
|
}
|
|
return out
|
|
}
|