mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-17 12:14:21 +01:00
* api-spec: move the api-spec to root and init go.mod * go mod tidy * move buf files in the root as well * gh action for api-spec changes only * gh action for api-spec on push and pr * introduce go.work and remove all replaces * solve dependencies and force btcd/btcec@v2.3.3 * go work sync * force btcd/btcec@v2.3.3 * go mod tidy
49 lines
1.6 KiB
Go
49 lines
1.6 KiB
Go
package permissions_test
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
grpchealth "google.golang.org/grpc/health/grpc_health_v1"
|
|
|
|
"github.com/ark-network/ark/server/internal/interface/grpc/permissions"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
arkv1 "github.com/ark-network/ark/api-spec/protobuf/gen/ark/v1"
|
|
)
|
|
|
|
func TestRestrictedMethods(t *testing.T) {
|
|
allMethods := make([]string, 0)
|
|
for _, m := range arkv1.AdminService_ServiceDesc.Methods {
|
|
allMethods = append(allMethods, fmt.Sprintf("/%s/%s", arkv1.AdminService_ServiceDesc.ServiceName, m.MethodName))
|
|
}
|
|
for _, m := range arkv1.WalletService_ServiceDesc.Methods {
|
|
allMethods = append(allMethods, fmt.Sprintf("/%s/%s", arkv1.WalletService_ServiceDesc.ServiceName, m.MethodName))
|
|
}
|
|
|
|
allPermissions := permissions.AllPermissionsByMethod()
|
|
for _, method := range allMethods {
|
|
_, ok := allPermissions[method]
|
|
require.True(t, ok, fmt.Sprintf("missing permission for %s", method))
|
|
}
|
|
}
|
|
|
|
func TestWhitelistedMethods(t *testing.T) {
|
|
allMethods := make([]string, 0)
|
|
for _, m := range arkv1.ArkService_ServiceDesc.Methods {
|
|
allMethods = append(allMethods, fmt.Sprintf("/%s/%s", arkv1.ArkService_ServiceDesc.ServiceName, m.MethodName))
|
|
}
|
|
|
|
for _, v := range arkv1.WalletInitializerService_ServiceDesc.Methods {
|
|
allMethods = append(allMethods, fmt.Sprintf("/%s/%s", arkv1.WalletInitializerService_ServiceDesc.ServiceName, v.MethodName))
|
|
}
|
|
|
|
allMethods = append(allMethods, fmt.Sprintf("/%s/%s", grpchealth.Health_ServiceDesc.ServiceName, "Check"))
|
|
|
|
whitelist := permissions.Whitelist()
|
|
for _, m := range allMethods {
|
|
_, ok := whitelist[m]
|
|
require.True(t, ok, fmt.Sprintf("missing %s in whitelist", m))
|
|
}
|
|
}
|