AutoPercenty3/test/ch_test.py

48 lines
1.7 KiB
Python

# test_change_password.py
import os
from supabase import create_client, ClientOptions
# 1. 환경변수 또는 직접 하드코딩으로 설정
SUPABASE_URL = "http://146.56.101.199:8000"
SUPABASE_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJhbm9uIiwKICAgICJpc3MiOiAic3VwYWJhc2UtZGVtbyIsCiAgICAiaWF0IjogMTY0MTc2OTIwMCwKICAgICJleHAiOiAxNzk5NTM1NjAwCn0.dc_X5iR_VP_qT0zsiyj_I_OZ2T9FtRU2BBNWN8Bu4GE"
TEST_EMAIL = "leensoo1nt@gmail.com"
CURRENT_PW = "Gytkd9570!"
NEW_PW = "Gytkd9570!!!"
def test_change_password():
opts = ClientOptions(
postgrest_client_timeout=60, # PostgREST API 호출 타임아웃 설정
storage_client_timeout=60, # Storage API 호출 타임아웃 설정
# Edge Functions 호출 시엔:
# function_client_timeout=60,
auto_refresh_token=True,
persist_session=True
)
supabase = create_client(SUPABASE_URL, SUPABASE_KEY, options=opts)
print("1) sign in with current password...")
auth_res = supabase.auth.sign_in_with_password({
"email": TEST_EMAIL,
"password": CURRENT_PW
})
session = auth_res.session
if not session or not session.access_token:
print("→ ❌ sign_in_with_password failed (invalid current password)")
return
print("✅ Re-authentication successful.")
print("2) trying update_user with new password...")
update_res = supabase.auth.update_user(
{"password": NEW_PW}
)
if getattr(update_res, "user", None):
print("✅ Password changed successfully!")
else:
print("→ ❌ update_user did not return .user", update_res)
if __name__ == "__main__":
test_change_password()