This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package grpcadapter
|
||||
|
||||
import (
|
||||
"context"
|
||||
ledgerv1 "gl/gen/ledger/v1"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/metadata"
|
||||
"google.golang.org/grpc/status"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAuthorityCommandsRequireOneConfiguredAdministrativeToken(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name, configured string
|
||||
tokens []string
|
||||
}{
|
||||
{"unconfigured", "", []string{"token"}},
|
||||
{"missing", "token", nil},
|
||||
{"wrong", "token", []string{"wrong"}},
|
||||
{"duplicate", "token", []string{"token", "token"}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
handler := NewHandler(nil, nil).WithSettlementAdminToken(tc.configured)
|
||||
ctx := metadata.NewIncomingContext(context.Background(), metadata.MD{"x-admin-token": tc.tokens})
|
||||
if _, err := handler.SetOperatingMode(ctx, &ledgerv1.SetOperatingModeRequest{}); status.Code(err) != codes.PermissionDenied {
|
||||
t.Fatalf("toggle: %v", err)
|
||||
}
|
||||
if _, err := handler.PostInternalJournal(ctx, &ledgerv1.AppendJournalRequest{}); status.Code(err) != codes.PermissionDenied {
|
||||
t.Fatalf("internal posting: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user