fake_auth_itests.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/usr/bin/env bash
  2. # Function to perform cleanup
  3. cleanup() {
  4. echo "Cleaning up..."
  5. echo "Killing the cdk mintd"
  6. kill -2 $cdk_mintd_pid
  7. wait $cdk_mintd_pid
  8. echo "Mint binary terminated"
  9. # Remove the temporary directory
  10. rm -rf "$cdk_itests"
  11. echo "Temp directory removed: $cdk_itests"
  12. unset cdk_itests
  13. unset cdk_itests_mint_addr
  14. unset cdk_itests_mint_port
  15. }
  16. # Set up trap to call cleanup on script exit
  17. trap cleanup EXIT
  18. # Create a temporary directory
  19. export cdk_itests=$(mktemp -d)
  20. export cdk_itests_mint_addr="127.0.0.1";
  21. export cdk_itests_mint_port=8087;
  22. # Check if the temporary directory was created successfully
  23. if [[ ! -d "$cdk_itests" ]]; then
  24. echo "Failed to create temp directory"
  25. exit 1
  26. fi
  27. echo "Temp directory created: $cdk_itests"
  28. export MINT_DATABASE="$1";
  29. export OPENID_DISCOVERY="$2";
  30. cargo build -p cdk-integration-tests
  31. export CDK_MINTD_URL="http://$cdk_itests_mint_addr:$cdk_itests_mint_port";
  32. export CDK_MINTD_WORK_DIR="$cdk_itests";
  33. export CDK_MINTD_LISTEN_HOST=$cdk_itests_mint_addr;
  34. export CDK_MINTD_LISTEN_PORT=$cdk_itests_mint_port;
  35. export CDK_MINTD_LN_BACKEND="fakewallet";
  36. export CDK_MINTD_FAKE_WALLET_SUPPORTED_UNITS="sat";
  37. export CDK_MINTD_MNEMONIC="eye survey guilt napkin crystal cup whisper salt luggage manage unveil loyal";
  38. export CDK_MINTD_FAKE_WALLET_FEE_PERCENT="0";
  39. export CDK_MINTD_FAKE_WALLET_RESERVE_FEE_MIN="1";
  40. export CDK_MINTD_DATABASE=$MINT_DATABASE;
  41. # Auth configuration
  42. export CDK_TEST_OIDC_USER="cdk-test";
  43. export CDK_TEST_OIDC_PASSWORD="cdkpassword";
  44. export CDK_MINTD_AUTH_OPENID_DISCOVERY=$OPENID_DISCOVERY;
  45. export CDK_MINTD_AUTH_OPENID_CLIENT_ID="cashu-client";
  46. export CDK_MINTD_AUTH_MINT_MAX_BAT="50";
  47. export CDK_MINTD_AUTH_ENABLED_MINT="true";
  48. export CDK_MINTD_AUTH_ENABLED_MELT="true";
  49. export CDK_MINTD_AUTH_ENABLED_SWAP="true";
  50. export CDK_MINTD_AUTH_ENABLED_CHECK_MINT_QUOTE="true";
  51. export CDK_MINTD_AUTH_ENABLED_CHECK_MELT_QUOTE="true";
  52. export CDK_MINTD_AUTH_ENABLED_RESTORE="true";
  53. export CDK_MINTD_AUTH_ENABLED_CHECK_PROOF_STATE="true";
  54. echo "Starting auth mintd";
  55. cargo run --bin cdk-mintd --features redb &
  56. cdk_mintd_pid=$!
  57. URL="http://$cdk_itests_mint_addr:$cdk_itests_mint_port/v1/info"
  58. TIMEOUT=100
  59. START_TIME=$(date +%s)
  60. # Loop until the endpoint returns a 200 OK status or timeout is reached
  61. while true; do
  62. # Get the current time
  63. CURRENT_TIME=$(date +%s)
  64. # Calculate the elapsed time
  65. ELAPSED_TIME=$((CURRENT_TIME - START_TIME))
  66. # Check if the elapsed time exceeds the timeout
  67. if [ $ELAPSED_TIME -ge $TIMEOUT ]; then
  68. echo "Timeout of $TIMEOUT seconds reached. Exiting..."
  69. exit 1
  70. fi
  71. # Make a request to the endpoint and capture the HTTP status code
  72. HTTP_STATUS=$(curl -o /dev/null -s -w "%{http_code}" $URL)
  73. # Check if the HTTP status is 200 OK
  74. if [ "$HTTP_STATUS" -eq 200 ]; then
  75. echo "Received 200 OK from $URL"
  76. break
  77. else
  78. echo "Waiting for 200 OK response, current status: $HTTP_STATUS"
  79. sleep 2 # Wait for 2 seconds before retrying
  80. fi
  81. done
  82. # Run cargo test
  83. cargo test -p cdk-integration-tests --test fake_auth
  84. # Capture the exit status of cargo test
  85. test_status=$?
  86. # Exit with the status of the test
  87. exit $test_status