| 
									
										
										
										
											2020-04-20 20:27:53 +02:00
										 |  |  | let | 
					
						
							|  |  |  |   cert = pkgs: pkgs.runCommandNoCC "selfSignedCerts" { buildInputs = [ pkgs.openssl ]; } ''
 | 
					
						
							|  |  |  |     openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -nodes -subj '/CN=example.com/CN=uploads.example.com/CN=conference.example.com' | 
					
						
							|  |  |  |     mkdir -p $out | 
					
						
							|  |  |  |     cp key.pem cert.pem $out | 
					
						
							|  |  |  |   '';
 | 
					
						
							|  |  |  |   createUsers = pkgs: pkgs.writeScriptBin "create-prosody-users" ''
 | 
					
						
							|  |  |  |     #!${pkgs.bash}/bin/bash | 
					
						
							|  |  |  |     set -e | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Creates and set password for the 2 xmpp test users. | 
					
						
							|  |  |  |     # | 
					
						
							|  |  |  |     # Doing that in a bash script instead of doing that in the test | 
					
						
							|  |  |  |     # script allow us to easily provision the users when running that | 
					
						
							|  |  |  |     # test interactively. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     prosodyctl register cthon98 example.com nothunter2 | 
					
						
							|  |  |  |     prosodyctl register azurediamond example.com hunter2 | 
					
						
							|  |  |  |   '';
 | 
					
						
							|  |  |  |   delUsers = pkgs: pkgs.writeScriptBin "delete-prosody-users" ''
 | 
					
						
							|  |  |  |     #!${pkgs.bash}/bin/bash | 
					
						
							|  |  |  |     set -e | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Deletes the test users. | 
					
						
							|  |  |  |     # | 
					
						
							|  |  |  |     # Doing that in a bash script instead of doing that in the test | 
					
						
							|  |  |  |     # script allow us to easily provision the users when running that | 
					
						
							|  |  |  |     # test interactively. | 
					
						
							| 
									
										
										
										
											2018-03-21 14:27:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-20 20:27:53 +02:00
										 |  |  |     prosodyctl deluser cthon98@example.com | 
					
						
							|  |  |  |     prosodyctl deluser azurediamond@example.com | 
					
						
							|  |  |  |   '';
 | 
					
						
							|  |  |  | in import ../make-test-python.nix { | 
					
						
							|  |  |  |   name = "prosody"; | 
					
						
							| 
									
										
										
										
											2019-06-15 12:41:50 +03:00
										 |  |  |   nodes = { | 
					
						
							| 
									
										
										
										
											2020-04-20 20:27:53 +02:00
										 |  |  |     client = { nodes, pkgs, config, ... }: { | 
					
						
							|  |  |  |       security.pki.certificateFiles = [ "${cert pkgs}/cert.pem" ]; | 
					
						
							|  |  |  |       console.keyMap = "fr-bepo"; | 
					
						
							|  |  |  |       networking.extraHosts = ''
 | 
					
						
							|  |  |  |         ${nodes.server.config.networking.primaryIPAddress} example.com | 
					
						
							|  |  |  |         ${nodes.server.config.networking.primaryIPAddress} conference.example.com | 
					
						
							|  |  |  |         ${nodes.server.config.networking.primaryIPAddress} uploads.example.com | 
					
						
							|  |  |  |       '';
 | 
					
						
							| 
									
										
										
										
											2019-06-15 12:41:50 +03:00
										 |  |  |       environment.systemPackages = [ | 
					
						
							|  |  |  |         (pkgs.callPackage ./xmpp-sendmessage.nix { connectTo = nodes.server.config.networking.primaryIPAddress; }) | 
					
						
							|  |  |  |       ]; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     server = { config, pkgs, ... }: { | 
					
						
							| 
									
										
										
										
											2020-04-20 20:27:53 +02:00
										 |  |  |       security.pki.certificateFiles = [ "${cert pkgs}/cert.pem" ]; | 
					
						
							|  |  |  |       console.keyMap = "fr-bepo"; | 
					
						
							| 
									
										
										
										
											2019-06-15 12:41:50 +03:00
										 |  |  |       networking.extraHosts = ''
 | 
					
						
							|  |  |  |         ${config.networking.primaryIPAddress} example.com | 
					
						
							| 
									
										
										
										
											2020-04-20 20:27:53 +02:00
										 |  |  |         ${config.networking.primaryIPAddress} conference.example.com | 
					
						
							|  |  |  |         ${config.networking.primaryIPAddress} uploads.example.com | 
					
						
							| 
									
										
										
										
											2018-09-23 10:46:22 +02:00
										 |  |  |       '';
 | 
					
						
							| 
									
										
										
										
											2019-06-15 12:41:50 +03:00
										 |  |  |       networking.firewall.enable = false; | 
					
						
							| 
									
										
										
										
											2020-04-20 20:27:53 +02:00
										 |  |  |       environment.systemPackages = [ | 
					
						
							|  |  |  |         (createUsers pkgs) | 
					
						
							|  |  |  |         (delUsers pkgs) | 
					
						
							|  |  |  |       ]; | 
					
						
							| 
									
										
										
										
											2019-06-15 12:41:50 +03:00
										 |  |  |       services.prosody = { | 
					
						
							|  |  |  |         enable = true; | 
					
						
							| 
									
										
										
										
											2020-04-20 20:27:53 +02:00
										 |  |  |         ssl.cert = "${cert pkgs}/cert.pem"; | 
					
						
							|  |  |  |         ssl.key = "${cert pkgs}/key.pem"; | 
					
						
							|  |  |  |         virtualHosts.example = { | 
					
						
							| 
									
										
										
										
											2019-06-15 12:41:50 +03:00
										 |  |  |           domain = "example.com"; | 
					
						
							|  |  |  |           enabled = true; | 
					
						
							| 
									
										
										
										
											2020-04-20 20:27:53 +02:00
										 |  |  |           ssl.cert = "${cert pkgs}/cert.pem"; | 
					
						
							|  |  |  |           ssl.key = "${cert pkgs}/key.pem"; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         muc = [ | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             domain = "conference.example.com"; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  |         uploadHttp = { | 
					
						
							|  |  |  |           domain = "uploads.example.com"; | 
					
						
							| 
									
										
										
										
											2019-06-15 12:41:50 +03:00
										 |  |  |         }; | 
					
						
							| 
									
										
										
										
											2019-04-17 23:36:07 +02:00
										 |  |  |       }; | 
					
						
							| 
									
										
										
										
											2018-03-21 14:27:20 +01:00
										 |  |  |     }; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-15 12:41:50 +03:00
										 |  |  |   testScript = { nodes, ... }: ''
 | 
					
						
							| 
									
										
										
										
											2019-11-24 13:04:11 +01:00
										 |  |  |     server.wait_for_unit("prosody.service") | 
					
						
							|  |  |  |     server.succeed('prosodyctl status | grep "Prosody is running"') | 
					
						
							| 
									
										
										
										
											2018-03-21 14:27:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-20 20:27:53 +02:00
										 |  |  |     server.succeed("create-prosody-users") | 
					
						
							| 
									
										
										
										
											2021-02-11 18:46:07 +01:00
										 |  |  |     client.succeed("send-message") | 
					
						
							| 
									
										
										
										
											2020-04-20 20:27:53 +02:00
										 |  |  |     server.succeed("delete-prosody-users") | 
					
						
							| 
									
										
										
										
											2018-03-21 14:27:20 +01:00
										 |  |  |   '';
 | 
					
						
							|  |  |  | } |