make_post_sell/test_digest_auth_local.py
Russell Ballestrini 800b7965b5 Fix crypto watcher stuck payments and improve cart deactivation
- Exclude already-swept payments from watcher queue to prevent endless processing
- Mark swept payments as "swept" status to remove from future cycles
- Fix cart deactivation by ensuring shop/user objects are attached to session
- Add debug logging for cart deactivation to track behavior
- Resolves issue where confirmed payments were processed every 20 seconds indefinitely

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-23 12:35:56 -04:00

115 lines
3.2 KiB
Python

#!/usr/bin/env python3
"""
Test Digest authentication locally using monero-wallet-remote-auth target.
This script tests our Digest auth implementation against a real Monero wallet RPC
with authentication enabled, rather than the no-auth version.
"""
import sys
import os
# Add the current directory to path so we can import the module
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from make_post_sell.lib.crypto_clients import MoneroClient
def test_no_auth():
"""Test that requests fail without authentication"""
print("=== Testing No Authentication (should fail) ===")
client = MoneroClient("http://127.0.0.1:18083/json_rpc")
try:
height = client.get_height()
print(f"✗ UNEXPECTED SUCCESS: {height}")
print("(This means RPC authentication is not enabled)")
return False
except Exception as e:
print(f"✓ EXPECTED FAILURE: {e}")
return True
def test_wrong_credentials():
"""Test that requests fail with wrong credentials"""
print("=== Testing Wrong Credentials (should fail) ===")
client = MoneroClient("http://127.0.0.1:18083/json_rpc", "wrong_user", "wrong_pass")
try:
height = client.get_height()
print(f"✗ UNEXPECTED SUCCESS: {height}")
return False
except Exception as e:
print(f"✓ EXPECTED FAILURE: {e}")
return True
def test_correct_credentials():
"""Test that requests succeed with correct credentials"""
print("=== Testing Correct Credentials (should work) ===")
client = MoneroClient("http://127.0.0.1:18083/json_rpc", "test_user", "test_pass")
try:
height = client.get_height()
print(f"✓ SUCCESS: Current height = {height}")
return True
except Exception as e:
print(f"✗ FAILED: {e}")
return False
def test_curl_comparison():
"""Test the same credentials with curl to compare"""
print("=== Testing with curl for comparison ===")
import subprocess
curl_cmd = [
"curl",
"-X",
"POST",
"http://127.0.0.1:18083/json_rpc",
"-H",
"Content-Type: application/json",
"-d",
'{"jsonrpc":"2.0","id":1,"method":"get_height"}',
"--digest",
"-u",
"test_user:test_pass",
"--silent",
]
try:
result = subprocess.run(curl_cmd, capture_output=True, text=True, timeout=10)
if result.returncode == 0:
print(f"✓ curl SUCCESS: {result.stdout.strip()}")
else:
print(f"✗ curl FAILED: {result.stderr.strip()}")
except Exception as e:
print(f"✗ curl ERROR: {e}")
if __name__ == "__main__":
print("Local Digest Authentication Test")
print("=" * 50)
print()
print("IMPORTANT: Start the authenticated wallet RPC first:")
print(" make monero-wallet-remote-auth")
print()
# Run all tests
test_no_auth()
print()
test_wrong_credentials()
print()
test_correct_credentials()
print()
test_curl_comparison()
print("\n" + "=" * 50)
print("If authentication is working correctly:")
print("- No auth and wrong credentials should fail")
print("- Correct credentials should succeed")
print("- curl and Python should behave the same")