Fix media not being available in the VM when sandboxed

This commit is contained in:
Nicolas Jeannerod 2024-11-16 22:30:57 +00:00
parent d988def944
commit 7645c9e225
Signed by untrusted user: Niols
GPG key ID: 35DB9EC8886E1CB8

View file

@ -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")