Compare commits

...
Sign in to create a new pull request.

8 commits

3 changed files with 41 additions and 18 deletions

View file

@ -14,3 +14,9 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- run: nix build .#checks.x86_64-linux.pre-commit -L - 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

View file

@ -13,6 +13,14 @@ in
}: }:
lib.mkIf (config.fediversity.enable && config.fediversity.pixelfed.enable) { 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 = { services.garage = {
ensureBuckets = { ensureBuckets = {
pixelfed = { pixelfed = {
@ -61,6 +69,8 @@ lib.mkIf (config.fediversity.enable && config.fediversity.pixelfed.enable) {
}; };
}; };
users.users.nginx.extraGroups = [ "pixelfed" ];
services.pixelfed.settings = { services.pixelfed.settings = {
## NOTE: This depends on the targets, eg. universities might want control ## NOTE: This depends on the targets, eg. universities might want control
## over who has an account. We probably want a universal ## over who has an account. We probably want a universal

View file

@ -8,23 +8,25 @@ let
email = "test@test.com"; email = "test@test.com";
password = "testtest"; password = "testtest";
testImage = pkgs.copyPathToStore ./green.png;
testImageColour = "#00FF00";
# FIXME: Replace all the By.XPATH by By.CSS_SELECTOR. # FIXME: Replace all the By.XPATH by By.CSS_SELECTOR.
seleniumImports = '' seleniumImports = ''
import sys import sys
from selenium import webdriver from selenium import webdriver
from selenium.webdriver.common.by import By from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options from selenium.webdriver.firefox.options import Options
''; '';
seleniumSetup = '' seleniumSetup = ''
print("Create and configure driver...", file=sys.stderr) print("Create and configure driver...", file=sys.stderr)
options = Options() options = Options()
# options.add_argument("--headless=new") options.add_argument("--headless")
service = webdriver.ChromeService(executable_path="${lib.getExe pkgs.chromedriver}") # noqa: E501 service = webdriver.FirefoxService(executable_path="${lib.getExe pkgs.geckodriver}") # noqa: E501
driver = webdriver.Chrome(options=options, service=service) driver = webdriver.Firefox(options=options, service=service)
driver.implicitly_wait(30) driver.implicitly_wait(30)
driver.set_window_size(1280, 960)
''; '';
seleniumPixelfedLogin = '' seleniumPixelfedLogin = ''
@ -56,27 +58,23 @@ let
pkgs.writers.writePython3Bin "selenium-script-post-picture" pkgs.writers.writePython3Bin "selenium-script-post-picture"
{ libraries = with pkgs.python3Packages; [ selenium ]; } { libraries = with pkgs.python3Packages; [ selenium ]; }
'' ''
import os
import time import time
${seleniumImports} ${seleniumImports}
from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support.wait import WebDriverWait
${seleniumSetup} ${seleniumSetup}
${seleniumPixelfedLogin} ${seleniumPixelfedLogin}
time.sleep(3)
media_path = os.environ['POST_MEDIA']
# Find the new post form, fill it in with our pictureand a caption. # Find the new post form, fill it in with our pictureand a caption.
print("Click on Create New Post...", file=sys.stderr) print("Click on Create New Post...", file=sys.stderr)
driver.find_element(By.LINK_TEXT, "Create New Post").click() driver.find_element(By.LINK_TEXT, "Create New Post").click()
print("Add file to input element...", file=sys.stderr) 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) print("Add a caption", file=sys.stderr)
driver.find_element(By.CSS_SELECTOR, ".media-body textarea").send_keys( driver.find_element(By.CSS_SELECTOR, ".media-body textarea").send_keys(
"Fediversity test of image upload to pixelfed with garage storage." "Fediversity test of image upload to pixelfed with garage storage."
) )
time.sleep(3)
print("Click on Post button...", file=sys.stderr) print("Click on Post button...", file=sys.stderr)
driver.find_element(By.LINK_TEXT, "Post").click() driver.find_element(By.LINK_TEXT, "Post").click()
@ -90,7 +88,11 @@ let
WebDriverWait(driver, timeout=10).until( WebDriverWait(driver, timeout=10).until(
lambda d: d.execute_script("return arguments[0].complete", img) 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\""} ${seleniumTakeScreenshot "\"/home/selenium/screenshot.png\""}
${seleniumQuit}''; ${seleniumQuit}'';
@ -146,12 +148,13 @@ pkgs.nixosTest {
fediversity fediversity
../vm/garage-vm.nix ../vm/garage-vm.nix
../vm/pixelfed-vm.nix ../vm/pixelfed-vm.nix
../vm/interactive-vm.nix
]; ];
# TODO: pair down # TODO: pair down
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [
python3 python3
chromium firefox-unwrapped
chromedriver geckodriver
xh xh
seleniumScriptPostPicture seleniumScriptPostPicture
seleniumScriptGetSrc seleniumScriptGetSrc
@ -159,13 +162,12 @@ pkgs.nixosTest {
imagemagick imagemagick
]; ];
environment.variables = { environment.variables = {
POST_MEDIA = ./fediversity.png;
AWS_ACCESS_KEY_ID = config.services.garage.ensureKeys.pixelfed.id; AWS_ACCESS_KEY_ID = config.services.garage.ensureKeys.pixelfed.id;
AWS_SECRET_ACCESS_KEY = config.services.garage.ensureKeys.pixelfed.secret; AWS_SECRET_ACCESS_KEY = config.services.garage.ensureKeys.pixelfed.secret;
## without this we get frivolous errors in the logs ## without this we get frivolous errors in the logs
MC_REGION = "garage"; MC_REGION = "garage";
}; };
# chrome does not like being run as root # Do not run Selenium scripts as root
users.users.selenium = { users.users.selenium = {
isNormalUser = true; isNormalUser = true;
}; };
@ -176,6 +178,7 @@ pkgs.nixosTest {
{ nodes, ... }: { nodes, ... }:
'' ''
import re import re
import time
server.start() server.start()
@ -195,7 +198,7 @@ pkgs.nixosTest {
server.copy_from_vm("/home/selenium/screenshot.png", "") 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:") 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 # 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: if image_check is None:
raise Exception("cannot detect the uploaded image on pixelfed page.") 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 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") 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"): with subtest("access image in garage"):
image = server.succeed("mc find garage --regex '\\.png' --ignore '*_thumb.png'") image = server.succeed("mc find garage --regex '\\.png' --ignore '*_thumb.png'")
image = image.rstrip() image = image.rstrip()
@ -210,7 +217,7 @@ pkgs.nixosTest {
raise Exception("image posted to Pixelfed did not get stored in garage") raise Exception("image posted to Pixelfed did not get stored in garage")
server.succeed(f"mc cat {image} >/garage-image.png") server.succeed(f"mc cat {image} >/garage-image.png")
garage_image_hash = server.succeed("identify -quiet -format '%#' /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: if garage_image_hash != image_hash:
raise Exception("image stored in garage did not match image uploaded") raise Exception("image stored in garage did not match image uploaded")