75 lines
2.7 KiB
Python
75 lines
2.7 KiB
Python
"""수정된 backend 파일 서버 패치 + E2E 재검증"""
|
|
import paramiko, sys, time
|
|
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
|
|
c = paramiko.SSHClient(); c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect('101.79.17.164', username='root', password='1q2w3e!Q', timeout=15)
|
|
sftp = c.open_sftp()
|
|
|
|
def run(label, cmd, timeout=30):
|
|
print(f'\n[{label}]')
|
|
_, o, _ = c.exec_command(cmd, timeout=timeout)
|
|
print(o.read().decode('utf-8','replace').strip()[:600])
|
|
|
|
# 파일 전송
|
|
for fn in ['imap_client.py', 'smtp_client.py', 'main.py']:
|
|
sftp.put(f'C:/GUARDiA/workspace/zioinfo-mail/backend/{fn}', f'/opt/mail/backend/{fn}')
|
|
print(f' ✅ {fn}')
|
|
|
|
run('서비스 재기동', 'systemctl restart zioinfo-mail && sleep 3 && systemctl is-active zioinfo-mail')
|
|
time.sleep(2)
|
|
|
|
# E2E: 로그인 → 폴더 → 메일 발송 → Sent 확인
|
|
test = """
|
|
import urllib.request, json, time
|
|
|
|
BASE = "http://localhost:8026"
|
|
|
|
def req(url, data=None, headers={}):
|
|
r = urllib.request.Request(BASE + url, data=data, headers=headers)
|
|
return json.loads(urllib.request.urlopen(r, timeout=15).read())
|
|
|
|
# 1. ythong 로그인
|
|
t = req("/api/auth/login",
|
|
data=json.dumps({"username":"ythong@zioinfo.co.kr","password":"1q2w3e!Q"}).encode(),
|
|
headers={"Content-Type":"application/json"})
|
|
token_y = t["access_token"]
|
|
Hy = {"Authorization": "Bearer " + token_y}
|
|
print("1. ythong 로그인 OK")
|
|
|
|
# 2. 폴더 목록
|
|
folders = req("/api/mail/folders", headers=Hy)
|
|
for f in folders:
|
|
print(f" {f['display']}({f['name']}) 총:{f['total']} 미읽음:{f['unread']}")
|
|
|
|
# 3. 메일 발송 (ythong → info)
|
|
r = req("/api/mail/send",
|
|
data=json.dumps({
|
|
"to": "info@zioinfo.co.kr",
|
|
"subject": "테스트 발송",
|
|
"body": "웹메일 테스트 메시지입니다."
|
|
}).encode(),
|
|
headers={**Hy, "Content-Type":"application/json"})
|
|
print("3. 발송:", r)
|
|
time.sleep(2)
|
|
|
|
# 4. ythong Sent 폴더 확인
|
|
sent = req("/api/mail/messages?folder=Sent", headers=Hy)
|
|
print(f"4. Sent 폴더 총:{sent.get('total')} 건")
|
|
for m in sent.get("messages", [])[:2]:
|
|
print(f" [{m['uid']}] {m['subject']} → {m['sender_addr']}")
|
|
|
|
# 5. info 로그인 → INBOX 확인
|
|
t2 = req("/api/auth/login",
|
|
data=json.dumps({"username":"info@zioinfo.co.kr","password":"1q2w3e!Q"}).encode(),
|
|
headers={"Content-Type":"application/json"})
|
|
Hi = {"Authorization": "Bearer " + t2["access_token"]}
|
|
inbox = req("/api/mail/messages?folder=INBOX", headers=Hi)
|
|
print(f"5. info INBOX 총:{inbox.get('total')} 건")
|
|
for m in inbox.get("messages", [])[:3]:
|
|
print(f" [{m['uid']}] {m['subject']} - from:{m['sender']}")
|
|
"""
|
|
with sftp.open('/tmp/e2e.py', 'w') as f: f.write(test)
|
|
run('E2E 테스트', 'python3 /tmp/e2e.py 2>&1; rm /tmp/e2e.py', timeout=30)
|
|
|
|
sftp.close(); c.close()
|