#!/bin/bash # # Quick Authenticated gRPC Test - Single request to verify JWT auth works # Use this for rapid validation before running full load tests set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' echo -e "${BLUE}=== Quick Authenticated gRPC Test ===${NC}" echo "" # Check ghz if ! command -v ghz &> /dev/null; then echo -e "${RED}❌ ghz not installed${NC}" exit 1 fi # Configuration GRPC_HOST="${GRPC_HOST:-localhost:50051}" PROTO_PATH="$PROJECT_ROOT/tli/proto/trading.proto" # Generate JWT token echo -e "${YELLOW}Generating JWT token...${NC}" JWT_TOKEN=$("$PROJECT_ROOT/tests/e2e_helpers/jwt_token_generator.sh" "test_user" "trader") if [ -z "$JWT_TOKEN" ]; then echo -e "${RED}❌ Failed to generate JWT token${NC}" exit 1 fi echo -e "${GREEN}✓ Token generated: ${JWT_TOKEN:0:50}...${NC}" echo "" # Test connectivity echo -e "${YELLOW}Testing API Gateway connectivity...${NC}" if ! nc -z localhost 50051 2>/dev/null; then echo -e "${RED}❌ API Gateway not running on port 50051${NC}" exit 1 fi echo -e "${GREEN}✓ API Gateway accessible${NC}" echo "" # Single authenticated request echo -e "${YELLOW}Sending authenticated request...${NC}" ghz --proto "$PROTO_PATH" \ --import-paths="$PROJECT_ROOT/tli/proto" \ --call "foxhunt.tli.TradingService.SubmitOrder" \ --insecure \ --total 1 \ --metadata "{\"authorization\":\"Bearer $JWT_TOKEN\"}" \ --data '{ "symbol": "BTC/USD", "side": "ORDER_SIDE_BUY", "order_type": "ORDER_TYPE_MARKET", "quantity": 1.0, "time_in_force": "IOC", "client_order_id": "quick-test-001" }' \ "$GRPC_HOST" if [ $? -eq 0 ]; then echo "" echo -e "${GREEN}✓ Authenticated request successful!${NC}" echo "" echo "JWT authentication is working correctly." echo "You can now run full load tests with: ./ghz_authenticated.sh" else echo "" echo -e "${RED}❌ Authenticated request failed${NC}" echo "Check API Gateway logs for errors" exit 1 fi