| 
									
										
										
										
											2020-08-02 19:25:04 +10:00
										 |  |  | let | 
					
						
							| 
									
										
										
										
											2020-07-06 03:37:56 +02:00
										 |  |  |   certs = import ./common/acme/server/snakeoil-certs.nix; | 
					
						
							| 
									
										
										
										
											2020-06-19 20:27:46 +01:00
										 |  |  |   domain = certs.domain; | 
					
						
							| 
									
										
										
										
											2020-07-06 03:37:56 +02:00
										 |  |  | in | 
					
						
							|  |  |  | import ./make-test-python.nix { | 
					
						
							|  |  |  |   name = "postfix"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   machine = { pkgs, ... }: { | 
					
						
							|  |  |  |     imports = [ common/user-account.nix ]; | 
					
						
							|  |  |  |     services.postfix = { | 
					
						
							|  |  |  |       enable = true; | 
					
						
							|  |  |  |       enableSubmission = true; | 
					
						
							|  |  |  |       enableSubmissions = true; | 
					
						
							| 
									
										
										
										
											2020-08-02 03:46:09 +02:00
										 |  |  |       tlsTrustedAuthorities = "${certs.ca.cert}"; | 
					
						
							|  |  |  |       sslCert = "${certs.${domain}.cert}"; | 
					
						
							|  |  |  |       sslKey = "${certs.${domain}.key}"; | 
					
						
							| 
									
										
										
										
											2020-07-06 03:37:56 +02:00
										 |  |  |       submissionsOptions = { | 
					
						
							|  |  |  |           smtpd_sasl_auth_enable = "yes"; | 
					
						
							|  |  |  |           smtpd_client_restrictions = "permit"; | 
					
						
							|  |  |  |           milter_macro_daemon_name = "ORIGINATING"; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     security.pki.certificateFiles = [ | 
					
						
							|  |  |  |       certs.ca.cert | 
					
						
							|  |  |  |     ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     networking.extraHosts = ''
 | 
					
						
							| 
									
										
										
										
											2020-06-19 20:27:46 +01:00
										 |  |  |       127.0.0.1 ${domain} | 
					
						
							| 
									
										
										
										
											2020-07-06 03:37:56 +02:00
										 |  |  |     '';
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     environment.systemPackages = let | 
					
						
							|  |  |  |       sendTestMail = pkgs.writeScriptBin "send-testmail" ''
 | 
					
						
							|  |  |  |         #!${pkgs.python3.interpreter} | 
					
						
							|  |  |  |         import smtplib | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-19 20:27:46 +01:00
										 |  |  |         with smtplib.SMTP('${domain}') as smtp: | 
					
						
							| 
									
										
										
										
											2020-07-06 03:37:56 +02:00
										 |  |  |           smtp.sendmail('root@localhost', 'alice@localhost', 'Subject: Test\n\nTest data.') | 
					
						
							|  |  |  |           smtp.quit() | 
					
						
							|  |  |  |       '';
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       sendTestMailStarttls = pkgs.writeScriptBin "send-testmail-starttls" ''
 | 
					
						
							|  |  |  |         #!${pkgs.python3.interpreter} | 
					
						
							|  |  |  |         import smtplib | 
					
						
							|  |  |  |         import ssl | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ctx = ssl.create_default_context() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-19 20:27:46 +01:00
										 |  |  |         with smtplib.SMTP('${domain}') as smtp: | 
					
						
							| 
									
										
										
										
											2020-07-06 03:37:56 +02:00
										 |  |  |           smtp.ehlo() | 
					
						
							|  |  |  |           smtp.starttls(context=ctx) | 
					
						
							|  |  |  |           smtp.ehlo() | 
					
						
							|  |  |  |           smtp.sendmail('root@localhost', 'alice@localhost', 'Subject: Test STARTTLS\n\nTest data.') | 
					
						
							|  |  |  |           smtp.quit() | 
					
						
							|  |  |  |       '';
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       sendTestMailSmtps = pkgs.writeScriptBin "send-testmail-smtps" ''
 | 
					
						
							|  |  |  |         #!${pkgs.python3.interpreter} | 
					
						
							|  |  |  |         import smtplib | 
					
						
							|  |  |  |         import ssl | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ctx = ssl.create_default_context() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-19 20:27:46 +01:00
										 |  |  |         with smtplib.SMTP_SSL(host='${domain}', context=ctx) as smtp: | 
					
						
							| 
									
										
										
										
											2020-07-06 03:37:56 +02:00
										 |  |  |           smtp.sendmail('root@localhost', 'alice@localhost', 'Subject: Test SMTPS\n\nTest data.') | 
					
						
							|  |  |  |           smtp.quit() | 
					
						
							|  |  |  |       '';
 | 
					
						
							|  |  |  |     in [ sendTestMail sendTestMailStarttls sendTestMailSmtps ]; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   testScript = ''
 | 
					
						
							|  |  |  |     machine.wait_for_unit("postfix.service") | 
					
						
							|  |  |  |     machine.succeed("send-testmail") | 
					
						
							|  |  |  |     machine.succeed("send-testmail-starttls") | 
					
						
							|  |  |  |     machine.succeed("send-testmail-smtps") | 
					
						
							|  |  |  |   '';
 | 
					
						
							|  |  |  | } |