Files
archie/internal/infrastructure/staterpc/service_logs_test.go
T
sam cf3455ef2e feat(rpc): mTLS between services from operator-issued certificates
Replace the service bearer tokens with [tls] ca_file and cert_dir. Caller
identity comes from the verified certificate, not metadata. Without TLS,
services listen and dial on loopback only. Task containers get only the CA
and keep their grant.
2026-10-16 02:37:51 +11:00

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.StateStoreService_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)
}
})
}
}