make_post_sell/test_monero_auth.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

122 lines
3.9 KiB
Python

#!/usr/bin/env python3
"""
Test script to debug Monero RPC authentication issues.
This helps isolate whether the problem is with credentials or authentication method.
"""
import urllib.request
import urllib.error
import json
import base64
import os
def test_basic_auth(rpc_url, rpc_user, rpc_pass):
"""Test Basic authentication (old method)"""
print("Testing Basic Authentication...")
payload = {"jsonrpc": "2.0", "id": 1, "method": "get_height"}
data = json.dumps(payload).encode()
# Basic auth header
auth = f"{rpc_user}:{rpc_pass}".encode()
headers = {
"Content-Type": "application/json",
"Authorization": "Basic " + base64.b64encode(auth).decode(),
}
req = urllib.request.Request(rpc_url, data=data, headers=headers)
try:
with urllib.request.urlopen(req, timeout=15) as resp:
result = json.loads(resp.read())
print("✓ Basic auth SUCCESS:", result)
return True
except urllib.error.HTTPError as e:
print(f"✗ Basic auth FAILED: HTTP {e.code} {e.reason}")
return False
except Exception as e:
print(f"✗ Basic auth ERROR: {e}")
return False
def test_digest_auth(rpc_url, rpc_user, rpc_pass):
"""Test Digest authentication (new method)"""
print("Testing Digest Authentication...")
payload = {"jsonrpc": "2.0", "id": 1, "method": "get_height"}
data = json.dumps(payload).encode()
# Digest auth setup
password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
password_mgr.add_password(None, rpc_url, rpc_user, rpc_pass)
auth_handler = urllib.request.HTTPDigestAuthHandler(password_mgr)
opener = urllib.request.build_opener(auth_handler)
req = urllib.request.Request(
rpc_url, data=data, headers={"Content-Type": "application/json"}
)
try:
with opener.open(req, timeout=15) as resp:
result = json.loads(resp.read())
print("✓ Digest auth SUCCESS:", result)
return True
except urllib.error.HTTPError as e:
print(f"✗ Digest auth FAILED: HTTP {e.code} {e.reason}")
return False
except Exception as e:
print(f"✗ Digest auth ERROR: {e}")
return False
def test_no_auth(rpc_url):
"""Test no authentication"""
print("Testing No Authentication...")
payload = {"jsonrpc": "2.0", "id": 1, "method": "get_height"}
data = json.dumps(payload).encode()
req = urllib.request.Request(
rpc_url, data=data, headers={"Content-Type": "application/json"}
)
try:
with urllib.request.urlopen(req, timeout=15) as resp:
result = json.loads(resp.read())
print("✓ No auth SUCCESS:", result)
return True
except urllib.error.HTTPError as e:
print(f"✗ No auth FAILED: HTTP {e.code} {e.reason}")
return False
except Exception as e:
print(f"✗ No auth ERROR: {e}")
return False
if __name__ == "__main__":
# Configuration from environment or defaults
rpc_url = os.environ.get("MPS_MONERO_RPC_URL", "http://127.0.0.1:18083/json_rpc")
rpc_user = os.environ.get("MPS_MONERO_RPC_USER", "")
rpc_pass = os.environ.get("MPS_MONERO_RPC_PASS", "")
print("=== Monero RPC Authentication Test ===")
print(f"URL: {rpc_url}")
print(f"User: {rpc_user!r}")
print(f"Pass: {'*' * len(rpc_pass) if rpc_pass else '(empty)'}")
print()
if not rpc_user or not rpc_pass:
print("⚠️ No credentials found in environment variables")
print("Set MPS_MONERO_RPC_USER and MPS_MONERO_RPC_PASS")
print()
# Test all three methods
test_no_auth(rpc_url)
print()
if rpc_user and rpc_pass:
test_basic_auth(rpc_url, rpc_user, rpc_pass)
print()
test_digest_auth(rpc_url, rpc_user, rpc_pass)
else:
print("Skipping credential tests - no username/password provided")