forked from fediversity/fediversity
		
	Compare commits
	
		
			8 commits
		
	
	
		
			main
			...
			pixelfed-c
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 51e6bc7ca6 | |||
| 8e001c5dc6 | |||
| 1f67866982 | |||
| 54735f1bc5 | |||
| 7645c9e225 | |||
| d988def944 | |||
| ae10086005 | |||
| e888db9f4b | 
					 3 changed files with 41 additions and 18 deletions
				
			
		|  | @ -14,3 +14,9 @@ jobs: | |||
|     steps: | ||||
|       - uses: actions/checkout@v4 | ||||
|       - run: nix build .#checks.x86_64-linux.pre-commit -L | ||||
| 
 | ||||
|   check-pixelfed-garage: | ||||
|     runs-on: native | ||||
|     steps: | ||||
|       - uses: actions/checkout@v4 | ||||
|       - run: nix build .#checks.x86_64-linux.pixelfed-garage -L | ||||
|  |  | |||
|  | @ -13,6 +13,14 @@ in | |||
| }: | ||||
| 
 | ||||
| lib.mkIf (config.fediversity.enable && config.fediversity.pixelfed.enable) { | ||||
| 
 | ||||
|   ## Pixelfed as packaged in nixpkgs has a permission issue that prevents Nginx | ||||
|   ## from being able to serving the images. We fix it here, but this should be | ||||
|   ## upstreamed. See https://github.com/NixOS/nixpkgs/issues/235147 | ||||
|   services.pixelfed.package = pkgs.pixelfed.overrideAttrs (old: { | ||||
|     patches = (old.patches or [ ]) ++ [ ./pixelfed-group-permissions.patch ]; | ||||
|   }); | ||||
| 
 | ||||
|   services.garage = { | ||||
|     ensureBuckets = { | ||||
|       pixelfed = { | ||||
|  | @ -61,6 +69,8 @@ lib.mkIf (config.fediversity.enable && config.fediversity.pixelfed.enable) { | |||
|     }; | ||||
|   }; | ||||
| 
 | ||||
|   users.users.nginx.extraGroups = [ "pixelfed" ]; | ||||
| 
 | ||||
|   services.pixelfed.settings = { | ||||
|     ## NOTE: This depends on the targets, eg. universities might want control | ||||
|     ## over who has an account. We probably want a universal | ||||
|  |  | |||
|  | @ -8,23 +8,25 @@ let | |||
|   email = "test@test.com"; | ||||
|   password = "testtest"; | ||||
| 
 | ||||
|   testImage = pkgs.copyPathToStore ./green.png; | ||||
|   testImageColour = "#00FF00"; | ||||
| 
 | ||||
|   # FIXME: Replace all the By.XPATH by By.CSS_SELECTOR. | ||||
| 
 | ||||
|   seleniumImports = '' | ||||
|     import sys | ||||
|     from selenium import webdriver | ||||
|     from selenium.webdriver.common.by import By | ||||
|     from selenium.webdriver.chrome.options import Options | ||||
|     from selenium.webdriver.firefox.options import Options | ||||
|   ''; | ||||
| 
 | ||||
|   seleniumSetup = '' | ||||
|     print("Create and configure driver...", file=sys.stderr) | ||||
|     options = Options() | ||||
|     # options.add_argument("--headless=new") | ||||
|     service = webdriver.ChromeService(executable_path="${lib.getExe pkgs.chromedriver}")  # noqa: E501 | ||||
|     driver = webdriver.Chrome(options=options, service=service) | ||||
|     options.add_argument("--headless") | ||||
|     service = webdriver.FirefoxService(executable_path="${lib.getExe pkgs.geckodriver}")  # noqa: E501 | ||||
|     driver = webdriver.Firefox(options=options, service=service) | ||||
|     driver.implicitly_wait(30) | ||||
|     driver.set_window_size(1280, 960) | ||||
|   ''; | ||||
| 
 | ||||
|   seleniumPixelfedLogin = '' | ||||
|  | @ -56,27 +58,23 @@ let | |||
|     pkgs.writers.writePython3Bin "selenium-script-post-picture" | ||||
|       { libraries = with pkgs.python3Packages; [ selenium ]; } | ||||
|       '' | ||||
|         import os | ||||
|         import time | ||||
| 
 | ||||
|         ${seleniumImports} | ||||
|         from selenium.webdriver.support.wait import WebDriverWait | ||||
| 
 | ||||
|         ${seleniumSetup} | ||||
|         ${seleniumPixelfedLogin} | ||||
|         time.sleep(3) | ||||
| 
 | ||||
|         media_path = os.environ['POST_MEDIA'] | ||||
| 
 | ||||
|         # Find the new post form, fill it in with our pictureand a caption. | ||||
|         print("Click on “Create New Post”...", file=sys.stderr) | ||||
|         driver.find_element(By.LINK_TEXT, "Create New Post").click() | ||||
|         print("Add file to input element...", file=sys.stderr) | ||||
|         driver.find_element(By.XPATH, "//input[@type='file']").send_keys(media_path) | ||||
|         driver.find_element(By.XPATH, "//input[@type='file']").send_keys("${testImage}")  # noqa E501 | ||||
|         print("Add a caption", file=sys.stderr) | ||||
|         driver.find_element(By.CSS_SELECTOR, ".media-body textarea").send_keys( | ||||
|             "Fediversity test of image upload to pixelfed with garage storage." | ||||
|         ) | ||||
|         time.sleep(3) | ||||
|         print("Click on “Post” button...", file=sys.stderr) | ||||
|         driver.find_element(By.LINK_TEXT, "Post").click() | ||||
| 
 | ||||
|  | @ -90,7 +88,11 @@ let | |||
|         WebDriverWait(driver, timeout=10).until( | ||||
|             lambda d: d.execute_script("return arguments[0].complete", img) | ||||
|         ) | ||||
|         time.sleep(3) | ||||
| 
 | ||||
|         # FIXME: Sometimes, it takes some time for the picture to show on the | ||||
|         # screenshot, even after it has completed loaded. Not sure what a | ||||
|         # better test would be. | ||||
|         time.sleep(60) | ||||
| 
 | ||||
|         ${seleniumTakeScreenshot "\"/home/selenium/screenshot.png\""} | ||||
|         ${seleniumQuit}''; | ||||
|  | @ -146,12 +148,13 @@ pkgs.nixosTest { | |||
|           fediversity | ||||
|           ../vm/garage-vm.nix | ||||
|           ../vm/pixelfed-vm.nix | ||||
|           ../vm/interactive-vm.nix | ||||
|         ]; | ||||
|         # TODO: pair down | ||||
|         environment.systemPackages = with pkgs; [ | ||||
|           python3 | ||||
|           chromium | ||||
|           chromedriver | ||||
|           firefox-unwrapped | ||||
|           geckodriver | ||||
|           xh | ||||
|           seleniumScriptPostPicture | ||||
|           seleniumScriptGetSrc | ||||
|  | @ -159,13 +162,12 @@ pkgs.nixosTest { | |||
|           imagemagick | ||||
|         ]; | ||||
|         environment.variables = { | ||||
|           POST_MEDIA = ./fediversity.png; | ||||
|           AWS_ACCESS_KEY_ID = config.services.garage.ensureKeys.pixelfed.id; | ||||
|           AWS_SECRET_ACCESS_KEY = config.services.garage.ensureKeys.pixelfed.secret; | ||||
|           ## without this we get frivolous errors in the logs | ||||
|           MC_REGION = "garage"; | ||||
|         }; | ||||
|         # chrome does not like being run as root | ||||
|         # Do not run Selenium scripts as root | ||||
|         users.users.selenium = { | ||||
|           isNormalUser = true; | ||||
|         }; | ||||
|  | @ -176,6 +178,7 @@ pkgs.nixosTest { | |||
|     { nodes, ... }: | ||||
|     '' | ||||
|       import re | ||||
|       import time | ||||
| 
 | ||||
|       server.start() | ||||
| 
 | ||||
|  | @ -195,7 +198,7 @@ pkgs.nixosTest { | |||
|         server.copy_from_vm("/home/selenium/screenshot.png", "") | ||||
|         displayed_colors = server.succeed("magick /home/selenium/screenshot.png -define histogram:unique-colors=true -format %c histogram:info:") | ||||
|         # check that the green image displayed somewhere | ||||
|         image_check = re.match(".*#FF0500.*", displayed_colors, re.S) | ||||
|         image_check = re.match(".*${testImageColour}.*", displayed_colors, re.S) | ||||
|         if image_check is None: | ||||
|           raise Exception("cannot detect the uploaded image on pixelfed page.") | ||||
| 
 | ||||
|  | @ -203,6 +206,10 @@ pkgs.nixosTest { | |||
|         server.succeed("mc alias set garage ${nodes.server.fediversity.internal.garage.api.url} --api s3v4 --path off $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY") | ||||
|         server.succeed("mc ls garage/pixelfed") | ||||
| 
 | ||||
|       # FIXME: Need to find something more robust. We need to do this because | ||||
|       # Pixelfed always takes some time before sending things to Garage. | ||||
|       time.sleep(60) | ||||
| 
 | ||||
|       with subtest("access image in garage"): | ||||
|         image = server.succeed("mc find garage --regex '\\.png' --ignore '*_thumb.png'") | ||||
|         image = image.rstrip() | ||||
|  | @ -210,7 +217,7 @@ pkgs.nixosTest { | |||
|           raise Exception("image posted to Pixelfed did not get stored in garage") | ||||
|         server.succeed(f"mc cat {image} >/garage-image.png") | ||||
|         garage_image_hash = server.succeed("identify -quiet -format '%#' /garage-image.png") | ||||
|         image_hash = server.succeed("identify -quiet -format '%#' $POST_MEDIA") | ||||
|         image_hash = server.succeed("identify -quiet -format '%#' ${testImage}") | ||||
|         if garage_image_hash != image_hash: | ||||
|           raise Exception("image stored in garage did not match image uploaded") | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue