mirror of
				https://github.com/optim-enterprises-bv/Mailu-OIDC.git
				synced 2025-11-03 19:48:07 +00:00 
			
		
		
		
	add tests
This commit is contained in:
		@@ -3,7 +3,8 @@
 | 
				
			|||||||
import imaplib
 | 
					import imaplib
 | 
				
			||||||
import poplib
 | 
					import poplib
 | 
				
			||||||
import smtplib
 | 
					import smtplib
 | 
				
			||||||
import os
 | 
					import sys
 | 
				
			||||||
 | 
					import managesieve
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SERVER='localhost'
 | 
					SERVER='localhost'
 | 
				
			||||||
USERNAME='user@mailu.io'
 | 
					USERNAME='user@mailu.io'
 | 
				
			||||||
@@ -26,7 +27,7 @@ def test_imap(server, username, password):
 | 
				
			|||||||
        with imaplib.IMAP4(server) as conn:
 | 
					        with imaplib.IMAP4(server) as conn:
 | 
				
			||||||
            conn.login(username, password)
 | 
					            conn.login(username, password)
 | 
				
			||||||
        print(f'Authenticating to imap://{username}:{password}@{server}:143/ worked without STARTTLS!')
 | 
					        print(f'Authenticating to imap://{username}:{password}@{server}:143/ worked without STARTTLS!')
 | 
				
			||||||
        os.exit(102)
 | 
					        sys.exit(102)
 | 
				
			||||||
    except imaplib.IMAP4.error:
 | 
					    except imaplib.IMAP4.error:
 | 
				
			||||||
        print('NOK - expected')
 | 
					        print('NOK - expected')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -54,7 +55,7 @@ def test_pop3(server, username, password):
 | 
				
			|||||||
        conn.pass_(password)
 | 
					        conn.pass_(password)
 | 
				
			||||||
        conn.close()
 | 
					        conn.close()
 | 
				
			||||||
        print(f'Authenticating to pop3://{username}:{password}@{server}:110/ worked without STARTTLS!')
 | 
					        print(f'Authenticating to pop3://{username}:{password}@{server}:110/ worked without STARTTLS!')
 | 
				
			||||||
        os.exit(103)
 | 
					        sys.exit(103)
 | 
				
			||||||
    except poplib.error_proto:
 | 
					    except poplib.error_proto:
 | 
				
			||||||
        print('NOK - expected')
 | 
					        print('NOK - expected')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -77,7 +78,7 @@ def test_SMTP(server, username, password):
 | 
				
			|||||||
            conn.ehlo()
 | 
					            conn.ehlo()
 | 
				
			||||||
            conn.login(username, password)
 | 
					            conn.login(username, password)
 | 
				
			||||||
            print(f'Authenticating to smtp://{username}:{password}@{server}:587/ worked!')
 | 
					            print(f'Authenticating to smtp://{username}:{password}@{server}:587/ worked!')
 | 
				
			||||||
            os.exit(104)
 | 
					            sys.exit(104)
 | 
				
			||||||
    except smtplib.SMTPNotSupportedError:
 | 
					    except smtplib.SMTPNotSupportedError:
 | 
				
			||||||
        print('NOK - expected')
 | 
					        print('NOK - expected')
 | 
				
			||||||
    #port 25 should fail
 | 
					    #port 25 should fail
 | 
				
			||||||
@@ -89,7 +90,7 @@ def test_SMTP(server, username, password):
 | 
				
			|||||||
            conn.ehlo()
 | 
					            conn.ehlo()
 | 
				
			||||||
            conn.login(username, password)
 | 
					            conn.login(username, password)
 | 
				
			||||||
            print(f'Authenticating to smtps://{username}:{password}@{server}:25/ worked!')
 | 
					            print(f'Authenticating to smtps://{username}:{password}@{server}:25/ worked!')
 | 
				
			||||||
            os.exit(105)
 | 
					            sys.exit(105)
 | 
				
			||||||
    except smtplib.SMTPNotSupportedError:
 | 
					    except smtplib.SMTPNotSupportedError:
 | 
				
			||||||
        print('NOK - expected')
 | 
					        print('NOK - expected')
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
@@ -98,11 +99,36 @@ def test_SMTP(server, username, password):
 | 
				
			|||||||
            conn.ehlo()
 | 
					            conn.ehlo()
 | 
				
			||||||
            conn.login(username, password)
 | 
					            conn.login(username, password)
 | 
				
			||||||
            print(f'Authenticating to smtp://{username}:{password}@{server}:25/ worked without STARTTLS!')
 | 
					            print(f'Authenticating to smtp://{username}:{password}@{server}:25/ worked without STARTTLS!')
 | 
				
			||||||
            os.exit(106)
 | 
					            sys.exit(106)
 | 
				
			||||||
    except smtplib.SMTPNotSupportedError:
 | 
					    except smtplib.SMTPNotSupportedError:
 | 
				
			||||||
        print('NOK - expected')
 | 
					        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__':
 | 
					if __name__ == '__main__':
 | 
				
			||||||
    test_imap(SERVER, USERNAME, PASSWORD)
 | 
					    test_imap(SERVER, USERNAME, PASSWORD)
 | 
				
			||||||
    test_pop3(SERVER, USERNAME, PASSWORD)
 | 
					    test_pop3(SERVER, USERNAME, PASSWORD)
 | 
				
			||||||
    test_SMTP(SERVER, USERNAME, PASSWORD)
 | 
					    test_SMTP(SERVER, USERNAME, PASSWORD)
 | 
				
			||||||
 | 
					    test_managesieve(SERVER, USERNAME, PASSWORD)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -30,6 +30,7 @@ services:
 | 
				
			|||||||
      - "127.0.0.1:995:995"
 | 
					      - "127.0.0.1:995:995"
 | 
				
			||||||
      - "127.0.0.1:143:143"
 | 
					      - "127.0.0.1:143:143"
 | 
				
			||||||
      - "127.0.0.1:993:993"
 | 
					      - "127.0.0.1:993:993"
 | 
				
			||||||
 | 
					      - "127.0.0.1:4190:4190"
 | 
				
			||||||
    volumes:
 | 
					    volumes:
 | 
				
			||||||
      - "/mailu/certs:/certs"
 | 
					      - "/mailu/certs:/certs"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,2 +1,3 @@
 | 
				
			|||||||
docker==4.2.2
 | 
					docker==4.2.2
 | 
				
			||||||
colorama==0.4.3
 | 
					colorama==0.4.3
 | 
				
			||||||
 | 
					managesieve==0.7.1
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user