#!/bin/bash # BAMS API Test Script set -e API_URL="http://localhost:8080" GREEN='\033[0;32m' RED='\033[0;31m' YELLOW='\033[1;33m' NC='\033[0m' # No Color echo "==========================================" echo "BAMS API Test Suite" echo "==========================================" echo "" # Test 1: Health Check echo -e "${YELLOW}Test 1: Health Check${NC}" response=$(curl -s "$API_URL/health") if echo "$response" | grep -q "ok"; then echo -e "${GREEN}✓ Health check passed${NC}" echo "Response: $response" else echo -e "${RED}✗ Health check failed${NC}" exit 1 fi echo "" # Test 2: Dashboard echo -e "${YELLOW}Test 2: Dashboard${NC}" response=$(curl -s "$API_URL/api/v1/dashboard") if echo "$response" | grep -q "disk"; then echo -e "${GREEN}✓ Dashboard endpoint works${NC}" else echo -e "${RED}✗ Dashboard endpoint failed${NC}" fi echo "" # Test 3: List Repositories echo -e "${YELLOW}Test 3: List Repositories${NC}" response=$(curl -s "$API_URL/api/v1/disk/repositories") echo -e "${GREEN}✓ List repositories works${NC}" echo "Response: $response" echo "" # Test 4: Validation - Invalid Repository Name echo -e "${YELLOW}Test 4: Validation - Invalid Repository Name${NC}" response=$(curl -s -X POST "$API_URL/api/v1/disk/repositories" \ -H "Content-Type: application/json" \ -d '{"name":"","size":"1G","type":"lvm","vg_name":"test-vg"}') if echo "$response" | grep -q "error"; then echo -e "${GREEN}✓ Validation works (empty name rejected)${NC}" else echo -e "${RED}✗ Validation failed${NC}" fi echo "" # Test 5: Validation - Invalid IQN echo -e "${YELLOW}Test 5: Validation - Invalid IQN${NC}" response=$(curl -s -X POST "$API_URL/api/v1/iscsi/targets" \ -H "Content-Type: application/json" \ -d '{"iqn":"invalid-iqn","portals":["192.168.1.1:3260"],"initiators":[]}') if echo "$response" | grep -q "error"; then echo -e "${GREEN}✓ IQN validation works${NC}" else echo -e "${RED}✗ IQN validation failed${NC}" fi echo "" # Test 6: Validation - Invalid Portal echo -e "${YELLOW}Test 6: Validation - Invalid Portal${NC}" response=$(curl -s -X POST "$API_URL/api/v1/iscsi/targets" \ -H "Content-Type: application/json" \ -d '{"iqn":"iqn.2024-12.com.example:test","portals":["invalid"],"initiators":[]}') if echo "$response" | grep -q "error"; then echo -e "${GREEN}✓ Portal validation works${NC}" else echo -e "${RED}✗ Portal validation failed${NC}" fi echo "" # Test 7: List iSCSI Targets echo -e "${YELLOW}Test 7: List iSCSI Targets${NC}" response=$(curl -s "$API_URL/api/v1/iscsi/targets") echo -e "${GREEN}✓ List targets works${NC}" echo "Response: $response" echo "" # Test 8: List Tape Library echo -e "${YELLOW}Test 8: Tape Library Status${NC}" response=$(curl -s "$API_URL/api/v1/tape/library") echo -e "${GREEN}✓ Tape library endpoint works${NC}" echo "Response: $response" echo "" # Test 9: Bacula Status echo -e "${YELLOW}Test 9: Bacula Status${NC}" response=$(curl -s "$API_URL/api/v1/bacula/status") echo -e "${GREEN}✓ Bacula status endpoint works${NC}" echo "Response: $response" echo "" # Test 10: CORS Headers echo -e "${YELLOW}Test 10: CORS Headers${NC}" headers=$(curl -s -I -X OPTIONS "$API_URL/api/v1/dashboard") if echo "$headers" | grep -q "Access-Control-Allow-Origin"; then echo -e "${GREEN}✓ CORS headers present${NC}" else echo -e "${RED}✗ CORS headers missing${NC}" fi echo "" echo "==========================================" echo -e "${GREEN}All tests completed!${NC}" echo "=========================================="