add STAT test

This commit is contained in:
Balakrishnan Balasubramanian 2023-06-10 23:28:45 -04:00
parent 02f3068626
commit 5fbbb4c163
2 changed files with 60 additions and 16 deletions

View File

@ -1,30 +1,74 @@
import unittest
import asyncio
import logging
import tempfile
import time
import os
from .pop3 import create_pop_server
from .config import User
from pathlib import Path
class TestPop3(unittest.IsolatedAsyncioTestCase):
def setUp(self) -> None:
logging.basicConfig(level=logging.DEBUG)
async def asyncSetUp(self) -> None:
logging.debug("at asyncSetUp")
test_hash = "".join((l.strip() for l in """
TEST_HASH = "".join(c for c in """
AFTY5EVN7AX47ZL7UMH3BETYWFBTAV3XHR73CEFAJBPN2NIHPWD
ZHV2UQSMSPHSQQ2A2BFQBNC77VL7F2UKATQNJZGYLCSU6C43UQD
AQXWXSWNGAEPGIMG2F3QDKBXL3MRHY6K2BPID64ZR6LABLPVSF
""".splitlines()))
users = [
User(username="foobar", password_hash=test_hash, mbox="mails")
]
""" if not c.isspace())
TEST_USER = 'foobar'
TEST_MBOX = 'foobar_mails'
USERS = [User(username=TEST_USER, password_hash=TEST_HASH, mbox=TEST_MBOX)]
MAILS_PATH: Path
TESTMAIL = b"""Message-ID: <N01BwLnh8dGBoD9gVz@msn.com>\r
From: from@msn.com\r
To: MddK0ftkv@outlook.com\r
Subject: hello lorem ipsum foo bar\r
Date: Mon, 24 Oct 2002 00:42:02 +0000\r
MIME-Version: 1.0\r
Content-Type: text/plain;\r
charset="windows-1251";\r
Content-Transfer-Encoding: 7bit\r
X-Peer: ('2.2.1.9', 64593)\r
X-MailFrom: from@msn.com\r
X-RcptTo: MddK0ftkv@outlook.com\r
\r
Hello bro\r
IlzVOJqu9Zp7twFAtzcV\r
yQVk36B0mGU2gtWxXLr\r
PeF0RtbI0mAuVPLQDHCi\r
\r\n"""
def setUpModule() -> None:
global MAILS_PATH
logging.basicConfig(level=logging.CRITICAL)
td = tempfile.TemporaryDirectory(prefix="m41.pop.")
unittest.addModuleCleanup(td.cleanup)
MAILS_PATH = Path(td.name)
os.mkdir(MAILS_PATH / TEST_MBOX)
for md in ('new', 'cur', 'tmp'):
os.mkdir(MAILS_PATH / TEST_MBOX / md)
with open(MAILS_PATH / TEST_MBOX/ 'new/msg1.eml', 'wb') as f:
f.write(TESTMAIL)
with open(MAILS_PATH / TEST_MBOX/ 'new/msg2.eml', 'wb') as f:
f.write(TESTMAIL)
print(MAILS_PATH)
def tearDownModule():
pass
class TestPop3(unittest.IsolatedAsyncioTestCase):
async def asyncSetUp(self) -> None:
logging.debug("at asyncSetUp")
pop_server = await create_pop_server(host='127.0.0.1',
port=7995,
mails_path=Path('w.tmp'),
users=users)
mails_path=MAILS_PATH,
users=USERS)
self.task = asyncio.create_task(pop_server.serve_forever())
self.reader, self.writer = await asyncio.open_connection(
'127.0.0.1', 7995)
@ -96,7 +140,7 @@ class TestPop3(unittest.IsolatedAsyncioTestCase):
await self.do_login()
dialog = """
C: STAT
S: +OK Bye
S: +OK 2 872
"""
await self.dialog_checker(dialog)

View File

@ -16,11 +16,11 @@ class TestPWHash(unittest.TestCase):
"check pass with wrong password")
def test_hardcoded_hash(self):
test_hash = "".join((l.strip() for l in """
test_hash = "".join(c for c in """
AFTY5EVN7AX47ZL7UMH3BETYWFBTAV3XHR73CEFAJBPN2NIHPWD
ZHV2UQSMSPHSQQ2A2BFQBNC77VL7F2UKATQNJZGYLCSU6C43UQD
AQXWXSWNGAEPGIMG2F3QDKBXL3MRHY6K2BPID64ZR6LABLPVSF
""".splitlines()))
""" if not c.isspace())
pwinfo = parse_hash(test_hash)
self.assertTrue(check_pass("helloworld", pwinfo),
"check pass with correct password")