1
0
mirror of https://github.com/Mailu/Mailu.git synced 2024-12-12 10:45:38 +02:00

add tests

This commit is contained in:
Florent Daigniere 2023-04-20 16:14:01 +02:00
parent 107b0ab5ff
commit d35ed1c400
3 changed files with 34 additions and 6 deletions

View File

@ -3,7 +3,8 @@
import imaplib
import poplib
import smtplib
import os
import sys
import managesieve
SERVER='localhost'
USERNAME='user@mailu.io'
@ -26,7 +27,7 @@ def test_imap(server, username, password):
with imaplib.IMAP4(server) as conn:
conn.login(username, password)
print(f'Authenticating to imap://{username}:{password}@{server}:143/ worked without STARTTLS!')
os.exit(102)
sys.exit(102)
except imaplib.IMAP4.error:
print('NOK - expected')
@ -54,7 +55,7 @@ def test_pop3(server, username, password):
conn.pass_(password)
conn.close()
print(f'Authenticating to pop3://{username}:{password}@{server}:110/ worked without STARTTLS!')
os.exit(103)
sys.exit(103)
except poplib.error_proto:
print('NOK - expected')
@ -77,7 +78,7 @@ def test_SMTP(server, username, password):
conn.ehlo()
conn.login(username, password)
print(f'Authenticating to smtp://{username}:{password}@{server}:587/ worked!')
os.exit(104)
sys.exit(104)
except smtplib.SMTPNotSupportedError:
print('NOK - expected')
#port 25 should fail
@ -89,7 +90,7 @@ def test_SMTP(server, username, password):
conn.ehlo()
conn.login(username, password)
print(f'Authenticating to smtps://{username}:{password}@{server}:25/ worked!')
os.exit(105)
sys.exit(105)
except smtplib.SMTPNotSupportedError:
print('NOK - expected')
try:
@ -98,11 +99,36 @@ def test_SMTP(server, username, password):
conn.ehlo()
conn.login(username, password)
print(f'Authenticating to smtp://{username}:{password}@{server}:25/ worked without STARTTLS!')
os.exit(106)
sys.exit(106)
except smtplib.SMTPNotSupportedError:
print('NOK - expected')
def test_managesieve(server, username, password):
print(f'Authenticating to sieve://{username}:{password}@{server}:4190/')
m=managesieve.MANAGESIEVE(server)
try:
m.login('PLAIN', username, password)
print(f'Worked without STARTTLS!')
sys.exit(107)
except managesieve.MANAGESIEVE.abort:
pass
m=managesieve.MANAGESIEVE(server, use_tls=True)
if m.login('', username, 'wrongpass') != 'NO':
print(f'Authenticating to sieve://{username}:{password}@{server}:4190/ with wrong creds has worked!')
sys.exit(108)
if m.login('', username, password) != 'OK':
print(f'Authenticating to sieve://{username}:{password}@{server}:4190/ has failed!')
sys.exit(109)
if m.listscripts()[0] != 'OK':
print(f'Listing scripts failed!')
sys.exit(110)
print('OK')
if __name__ == '__main__':
test_imap(SERVER, USERNAME, PASSWORD)
test_pop3(SERVER, USERNAME, PASSWORD)
test_SMTP(SERVER, USERNAME, PASSWORD)
test_managesieve(SERVER, USERNAME, PASSWORD)

View File

@ -30,6 +30,7 @@ services:
- "127.0.0.1:995:995"
- "127.0.0.1:143:143"
- "127.0.0.1:993:993"
- "127.0.0.1:4190:4190"
volumes:
- "/mailu/certs:/certs"

View File

@ -1,2 +1,3 @@
docker==4.2.2
colorama==0.4.3
managesieve==0.7.1