From 7645c9e225fa44ef27b1eb1bf9d15858709b5ab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20=E2=80=9CNiols=E2=80=9D=20Jeannerod?= Date: Sat, 16 Nov 2024 22:30:57 +0000 Subject: [PATCH] Fix media not being available in the VM when sandboxed --- services/tests/pixelfed-garage.nix | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/services/tests/pixelfed-garage.nix b/services/tests/pixelfed-garage.nix index 86b81d63..0125a18d 100644 --- a/services/tests/pixelfed-garage.nix +++ b/services/tests/pixelfed-garage.nix @@ -8,6 +8,9 @@ let email = "test@test.com"; password = "testtest"; + testImage = pkgs.copyPathToStore ./fediversity.png; + testImageColour = "#FF0500"; + # FIXME: Replace all the By.XPATH by By.CSS_SELECTOR. seleniumImports = '' @@ -56,20 +59,17 @@ let pkgs.writers.writePython3Bin "selenium-script-post-picture" { libraries = with pkgs.python3Packages; [ selenium ]; } '' - import os ${seleniumImports} from selenium.webdriver.support.wait import WebDriverWait ${seleniumSetup} ${seleniumPixelfedLogin} - 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." @@ -156,7 +156,6 @@ 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 @@ -192,7 +191,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.") @@ -207,7 +206,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")