fake_auth_itests.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/usr/bin/env bash
  2. # Function to perform cleanup
  3. cleanup() {
  4. echo "Cleaning up..."
  5. if [ -n "$FAKE_AUTH_MINT_PID" ]; then
  6. echo "Killing the fake auth mint process"
  7. kill -2 $FAKE_AUTH_MINT_PID 2>/dev/null || true
  8. wait $FAKE_AUTH_MINT_PID 2>/dev/null || true
  9. fi
  10. echo "Mint binary terminated"
  11. # Remove the temporary directory
  12. if [ -n "$CDK_ITESTS_DIR" ] && [ -d "$CDK_ITESTS_DIR" ]; then
  13. rm -rf "$CDK_ITESTS_DIR"
  14. echo "Temp directory removed: $CDK_ITESTS_DIR"
  15. fi
  16. # Unset all environment variables
  17. unset CDK_ITESTS_DIR
  18. unset CDK_ITESTS_MINT_ADDR
  19. unset CDK_ITESTS_MINT_PORT
  20. unset FAKE_AUTH_MINT_PID
  21. }
  22. # Set up trap to call cleanup on script exit
  23. trap cleanup EXIT INT TERM
  24. # Create a temporary directory
  25. export CDK_ITESTS_DIR=$(mktemp -d)
  26. export CDK_ITESTS_MINT_ADDR="127.0.0.1"
  27. export CDK_ITESTS_MINT_PORT=8087
  28. # Check if the temporary directory was created successfully
  29. if [[ ! -d "$CDK_ITESTS_DIR" ]]; then
  30. echo "Failed to create temp directory"
  31. exit 1
  32. fi
  33. echo "Temp directory created: $CDK_ITESTS_DIR"
  34. # Check if a database type was provided as first argument, default to sqlite
  35. export MINT_DATABASE="${1:-sqlite}"
  36. # Check if OPENID_DISCOVERY was provided as second argument, default to a test value
  37. export OPENID_DISCOVERY="${2:-http://127.0.0.1:8080/realms/cdk-test-realm/.well-known/openid-configuration}"
  38. # Build the project
  39. cargo build -p cdk-integration-tests
  40. # Auth configuration
  41. export CDK_TEST_OIDC_USER="cdk-test"
  42. export CDK_TEST_OIDC_PASSWORD="cdkpassword"
  43. # Start the fake auth mint in the background
  44. echo "Starting fake auth mint with discovery URL: $OPENID_DISCOVERY"
  45. echo "Using temp directory: $CDK_ITESTS_DIR"
  46. cargo run -p cdk-integration-tests --bin start_fake_auth_mint -- --enable-logging "$MINT_DATABASE" "$CDK_ITESTS_DIR" "$OPENID_DISCOVERY" "$CDK_ITESTS_MINT_PORT" &
  47. # Store the PID of the mint process
  48. FAKE_AUTH_MINT_PID=$!
  49. # Wait a moment for the mint to start
  50. sleep 5
  51. # Check if the mint is running
  52. if ! kill -0 $FAKE_AUTH_MINT_PID 2>/dev/null; then
  53. echo "Failed to start fake auth mint"
  54. exit 1
  55. fi
  56. echo "Fake auth mint started with PID: $FAKE_AUTH_MINT_PID"
  57. # Run cargo test
  58. echo "Running fake auth integration tests..."
  59. cargo test -p cdk-integration-tests --test fake_auth
  60. # Capture the exit status of cargo test
  61. test_status=$?
  62. # Exit with the status of the test
  63. exit $test_status