1
0
mirror of https://github.com/Mailu/Mailu.git synced 2024-12-14 10:53:30 +02:00
Mailu/tests/compose/core/05_connectivity.py

109 lines
3.6 KiB
Python
Raw Normal View History

2023-04-08 10:22:09 +02:00
#!/usr/bin/env python3
import imaplib
import poplib
import smtplib
import os
SERVER='localhost'
2023-04-08 10:26:22 +02:00
USERNAME='user@mailu.io'
2023-04-08 10:22:09 +02:00
PASSWORD='password'
def test_imap(server, username, password):
2023-04-08 10:26:22 +02:00
print(f'Authenticating to imaps://{username}:{password}@{server}:993/')
2023-04-08 10:22:09 +02:00
with imaplib.IMAP4_SSL(server) as conn:
conn.login(username, password)
2023-04-08 10:26:22 +02:00
conn.noop()
print('OK')
print(f'Authenticating to imaps://{username}:{password}@{server}:143/')
2023-04-08 10:22:09 +02:00
with imaplib.IMAP4(server) as conn:
conn.starttls()
conn.login(username, password)
2023-04-08 10:26:22 +02:00
conn.noop()
print('OK')
print(f'Authenticating to imap://{username}:{password}@{server}:143/')
2023-04-08 10:22:09 +02:00
try:
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)
2023-04-08 10:26:22 +02:00
except imaplib.IMAP4.error:
2023-04-08 12:47:41 +02:00
print('NOK - expected')
2023-04-08 10:22:09 +02:00
def test_pop3(server, username, password):
print(f'Authenticating to pop3s://{username}:{password}@{server}:995/')
conn = poplib.POP3_SSL(server)
conn.capa()
conn.user(username)
conn.pass_(password)
conn.close()
2023-04-08 10:26:22 +02:00
print('OK')
2023-04-08 10:22:09 +02:00
print(f'Authenticating to pop3s://{username}:{password}@{server}:110/')
conn = poplib.POP3(server)
conn.stls()
conn.capa()
conn.user(username)
conn.pass_(password)
conn.close()
2023-04-08 10:26:22 +02:00
print('OK')
2023-04-08 10:22:09 +02:00
print(f'Authenticating to pop3://{username}:{password}@{server}:110/')
try:
conn = poplib.POP3(server)
conn.capa()
conn.user(username)
conn.pass_(password)
conn.close()
print(f'Authenticating to pop3://{username}:{password}@{server}:110/ worked without STARTTLS!')
os.exit(103)
except poplib.error_proto:
2023-04-08 12:47:41 +02:00
print('NOK - expected')
2023-04-08 10:22:09 +02:00
def test_SMTP(server, username, password):
2023-04-08 10:26:22 +02:00
print(f'Authenticating to smtps://{username}:{password}@{server}:465/')
2023-04-08 10:22:09 +02:00
with smtplib.SMTP_SSL(server) as conn:
conn.ehlo()
conn.login(username, password)
2023-04-08 10:26:22 +02:00
print('OK')
print(f'Authenticating to smtps://{username}:{password}@{server}:587/')
with smtplib.SMTP(server, 587) as conn:
2023-04-08 10:22:09 +02:00
conn.ehlo()
conn.starttls()
conn.ehlo()
conn.login(username, password)
2023-04-08 10:26:22 +02:00
print('OK')
2023-04-08 10:22:09 +02:00
try:
2023-04-08 10:26:22 +02:00
print(f'Authenticating to smtp://{username}:{password}@{server}:587/')
with smtplib.SMTP(server, 587) as conn:
conn.ehlo()
conn.login(username, password)
2023-04-08 12:47:41 +02:00
print(f'Authenticating to smtp://{username}:{password}@{server}:587/ worked!')
2023-04-08 13:23:28 +02:00
os.exit(104)
2023-04-08 10:26:22 +02:00
except smtplib.SMTPNotSupportedError:
2023-04-08 12:47:41 +02:00
print('NOK - expected')
2023-04-08 10:26:22 +02:00
#port 25 should fail
try:
print(f'Authenticating to smtps://{username}:{password}@{server}:25/')
with smtplib.SMTP(server) as conn:
conn.ehlo()
conn.starttls()
conn.ehlo()
conn.login(username, password)
2023-04-08 12:47:41 +02:00
print(f'Authenticating to smtps://{username}:{password}@{server}:25/ worked!')
2023-04-08 13:23:28 +02:00
os.exit(105)
2023-04-08 10:26:22 +02:00
except smtplib.SMTPNotSupportedError:
2023-04-08 12:47:41 +02:00
print('NOK - expected')
2023-04-08 10:26:22 +02:00
try:
print(f'Authenticating to smtp://{username}:{password}@{server}:25/')
2023-04-08 10:22:09 +02:00
with smtplib.SMTP(server) as conn:
conn.ehlo()
conn.login(username, password)
2023-04-08 12:47:41 +02:00
print(f'Authenticating to smtp://{username}:{password}@{server}:25/ worked without STARTTLS!')
2023-04-08 13:23:28 +02:00
os.exit(106)
2023-04-08 10:22:09 +02:00
except smtplib.SMTPNotSupportedError:
2023-04-08 12:47:41 +02:00
print('NOK - expected')
2023-04-08 10:22:09 +02:00
if __name__ == '__main__':
test_imap(SERVER, USERNAME, PASSWORD)
test_pop3(SERVER, USERNAME, PASSWORD)
test_SMTP(SERVER, USERNAME, PASSWORD)