| 
									
										
										
										
											2020-04-11 12:00:00 +00:00
										 |  |  | { system ? builtins.currentSystem, | 
					
						
							|  |  |  |   config ? {}, | 
					
						
							|  |  |  |   pkgs ? import ../.. { inherit system config; } | 
					
						
							|  |  |  | }: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-16 17:08:32 +02:00
										 |  |  | let | 
					
						
							| 
									
										
										
										
											2020-04-11 12:00:00 +00:00
										 |  |  |   inherit (import ../lib/testing-python.nix { inherit system pkgs; }) makeTest; | 
					
						
							|  |  |  |   f = backend: makeTest { | 
					
						
							| 
									
										
										
										
											2020-01-05 12:00:00 +00:00
										 |  |  |     name = "ihatemoney-${backend}"; | 
					
						
							|  |  |  |     machine = { lib, ... }: { | 
					
						
							|  |  |  |       services.ihatemoney = { | 
					
						
							|  |  |  |         enable = true; | 
					
						
							|  |  |  |         enablePublicProjectCreation = true; | 
					
						
							|  |  |  |         inherit backend; | 
					
						
							|  |  |  |         uwsgiConfig = { | 
					
						
							|  |  |  |           http = ":8000"; | 
					
						
							| 
									
										
										
										
											2019-09-16 17:08:32 +02:00
										 |  |  |         }; | 
					
						
							| 
									
										
										
										
											2020-01-05 12:00:00 +00:00
										 |  |  |       }; | 
					
						
							|  |  |  |       boot.cleanTmpDir = true; | 
					
						
							| 
									
										
										
										
											2019-09-16 17:08:32 +02:00
										 |  |  |       # ihatemoney needs a local smtp server otherwise project creation just crashes | 
					
						
							|  |  |  |       services.opensmtpd = { | 
					
						
							|  |  |  |         enable = true; | 
					
						
							|  |  |  |         serverConfiguration = ''
 | 
					
						
							|  |  |  |           listen on lo | 
					
						
							|  |  |  |           action foo relay | 
					
						
							|  |  |  |           match from any for any action foo | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     testScript = ''
 | 
					
						
							| 
									
										
										
										
											2020-01-26 16:54:53 +01:00
										 |  |  |       machine.wait_for_open_port(8000) | 
					
						
							|  |  |  |       machine.wait_for_unit("uwsgi.service") | 
					
						
							| 
									
										
										
										
											2020-06-25 12:00:00 +00:00
										 |  |  |       machine.wait_until_succeeds("curl http://localhost:8000") | 
					
						
							| 
									
										
										
										
											2020-01-26 16:54:53 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       assert '"yay"' in machine.succeed( | 
					
						
							| 
									
										
										
										
											2020-06-25 12:00:00 +00:00
										 |  |  |           "curl -X POST http://localhost:8000/api/projects -d 'name=yay&id=yay&password=yay&contact_email=yay@example.com'" | 
					
						
							| 
									
										
										
										
											2020-01-26 16:54:53 +01:00
										 |  |  |       ) | 
					
						
							|  |  |  |       owner, timestamp = machine.succeed( | 
					
						
							|  |  |  |           "stat --printf %U:%G___%Y /var/lib/ihatemoney/secret_key" | 
					
						
							|  |  |  |       ).split("___") | 
					
						
							|  |  |  |       assert "ihatemoney:ihatemoney" == owner | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       with subtest("Restart machine and service"): | 
					
						
							|  |  |  |           machine.shutdown() | 
					
						
							|  |  |  |           machine.start() | 
					
						
							|  |  |  |           machine.wait_for_open_port(8000) | 
					
						
							|  |  |  |           machine.wait_for_unit("uwsgi.service") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       with subtest("check that the database is really persistent"): | 
					
						
							|  |  |  |           machine.succeed("curl --basic -u yay:yay http://localhost:8000/api/projects/yay") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       with subtest("check that the secret key is really persistent"): | 
					
						
							|  |  |  |           timestamp2 = machine.succeed("stat --printf %Y /var/lib/ihatemoney/secret_key") | 
					
						
							|  |  |  |           assert timestamp == timestamp2 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       assert "ihatemoney" in machine.succeed("curl http://localhost:8000") | 
					
						
							| 
									
										
										
										
											2019-09-16 17:08:32 +02:00
										 |  |  |     '';
 | 
					
						
							| 
									
										
										
										
											2020-04-11 12:00:00 +00:00
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2020-01-26 16:54:53 +01:00
										 |  |  | in { | 
					
						
							|  |  |  |   ihatemoney-sqlite = f "sqlite"; | 
					
						
							|  |  |  |   ihatemoney-postgresql = f "postgresql"; | 
					
						
							|  |  |  | } |