One gRPC service per domain in state.v1 (tasks, executions, accounts, identities, packages, captures, bindings, access, orgs, alerts and so on), each with its own server type in staterpc. RPC and message names and numbers are unchanged.
43 lines
1.4 KiB
Go
43 lines
1.4 KiB
Go
package staterpc
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/codes"
|
|
grpccreds "google.golang.org/grpc/credentials"
|
|
"google.golang.org/grpc/metadata"
|
|
"google.golang.org/grpc/peer"
|
|
"google.golang.org/grpc/status"
|
|
|
|
pb "github.com/samcharles93/archie-core/internal/contracts/state/v1"
|
|
)
|
|
|
|
func TestServiceLogsRequireService(t *testing.T) {
|
|
run := strings.Repeat("ab", 32)
|
|
grants := &TaskGrants{Store: credentials{}}
|
|
if err := grants.register(t.Context(), 7, run, time.Hour); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, tt := range []struct {
|
|
name, token string
|
|
peer *peer.Peer
|
|
code codes.Code
|
|
}{
|
|
{"service", "", &peer.Peer{}, codes.OK},
|
|
{"task cannot read other services", run, &peer.Peer{AuthInfo: grpccreds.TLSInfo{}}, codes.PermissionDenied},
|
|
{"anonymous", "", &peer.Peer{AuthInfo: grpccreds.TLSInfo{}}, codes.Unauthenticated},
|
|
} {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
ctx := peer.NewContext(metadata.NewIncomingContext(t.Context(), metadata.Pairs(tokenMetadataKey, tt.token)), tt.peer)
|
|
_, err := grants.UnaryInterceptor()(ctx, &pb.RecentLogsRequest{}, &grpc.UnaryServerInfo{FullMethod: pb.StatusService_RecentLogs_FullMethodName}, func(context.Context, any) (any, error) { return &pb.RecentLogsResponse{}, nil })
|
|
if status.Code(err) != tt.code {
|
|
t.Fatalf("code %s want %s", status.Code(err), tt.code)
|
|
}
|
|
})
|
|
}
|
|
}
|