From b38ec1a62a5f1603cd43b8c4d94bab7108301e7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20=E2=80=9CNiols=E2=80=9D=20Jeannerod?= Date: Mon, 9 Sep 2024 14:09:54 +0200 Subject: [PATCH] Cleanup --- tests/pixelfed-garage.nix | 84 ++++++--------------------------------- 1 file changed, 13 insertions(+), 71 deletions(-) diff --git a/tests/pixelfed-garage.nix b/tests/pixelfed-garage.nix index c16a370b..21d4b4bb 100644 --- a/tests/pixelfed-garage.nix +++ b/tests/pixelfed-garage.nix @@ -12,13 +12,13 @@ let from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.chrome.options import Options - print("starting selenium script") + print("Starting selenium script...") email = sys.argv[1] password = sys.argv[2] green_path = "${./green.png}" - screenshot_path = "/home/seleniumUser/screenshot.png" + screenshot_path = "/home/selenium/screenshot.png" # Create and configure driver. It is important to set the window size such that # the “Create New Post” button is visible. @@ -28,7 +28,7 @@ let service = webdriver.ChromeService(executable_path="${lib.getExe pkgs.chromedriver}") # noqa: E501 driver = webdriver.Chrome(options=options, service=service) driver.implicitly_wait(10) - driver.set_window_size(1920, 1200) + driver.set_window_size(1280, 960) # FIXME: Replace the By.XPATH by By.CSS_SELECTOR. @@ -67,6 +67,7 @@ let if not driver.save_screenshot(screenshot_path): raise Exception("selenium could not save screenshot") + # All done ^-^ print("Quitting...") driver.quit() print("All done!") @@ -81,10 +82,10 @@ pkgs.nixosTest { memorySize = lib.mkVMOverride 8192; cores = 8; }; - imports = with self.nixosModules; [ - garage - pixelfed - pixelfed-vm + imports = with self.nixosModules; [ + garage + pixelfed + pixelfed-vm ]; # TODO: pair down environment.systemPackages = with pkgs; [ @@ -102,7 +103,7 @@ pkgs.nixosTest { # AWS_SECRET_ACCESS_KEY = config.services.garage.ensureKeys.pixelfed.secret; }; # chrome does not like being run as root - users.users.seleniumUser = { + users.users.selenium = { isNormalUser = true; }; }; @@ -110,84 +111,25 @@ pkgs.nixosTest { testScript = '' import re - # import time + import subprocess server.start() with subtest("Pixelfed starts"): server.wait_for_unit("phpfpm-pixelfed.service") - # make sure pixelfed is fully up and running before we interact with it - # TODO: is there a way to test for this? - # REVIEW: this is copied from the Mastodon test; Pixelfed might be faster to start up. - # time.sleep(180) - - # # REVIEW: not sure why necessary. if it is, could we push this into the installation? - # # FIXME: this is an interactive command; look into flags to make it non-interactive - # with subtest("Passport install"): - # server.succeed("pixelfed-manage passport:install") - with subtest("Account creation"): password = "testtest" server.succeed(f"pixelfed-manage user:create --name=test --username=test --email=test@test.com --password={password} --confirm_email=1") - # # REVIEW: do we actually need TTY? - # with subtest("TTY Login"): - # server.wait_until_tty_matches("1", "login: ") - # server.send_chars("root\n"); - - # with subtest("Log in with toot"): - # # toot doesn't provide a way to just specify our login details as arguments, so we have to pretend we're typing them in at the prompt - # server.send_chars("toot login_cli --instance http://mastodon.localhost:55001 --email test@test.com\n") - # server.wait_until_tty_matches("1", "Password: ") - # server.send_chars(password + "\n") - # server.wait_until_tty_matches("1", "Successfully logged in.") - - # with subtest("post text"): - # server.succeed("echo 'hello mastodon' | toot post") - - # with subtest("post image"): - # server.succeed("toot post --media $POST_MEDIA") - - # with subtest("access garage"): - # server.succeed("mc alias set pixelfed http://s3.garage.localhost:3900 --api s3v4 --path off $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY") - # server.succeed("mc ls garage/pixelfed") - - # with subtest("access image in garage"): - # image = server.succeed("mc find garage --regex original") - # image = image.rstrip() - # if image == "": - # raise Exception("image posted to pixelfed did not get stored in garage") - # server.succeed(f"mc cat {image} >/garage-image.webp") - # garage_image_hash = server.succeed("identify -quiet -format '%#' /garage-image.webp") - # image_hash = server.succeed("identify -quiet -format '%#' $POST_MEDIA") - # if garage_image_hash != image_hash: - # raise Exception("image stored in garage did not match image uploaded") - - # with subtest("Content security policy allows garage images"): - # headers = server.succeed("xh -h http://mastodon.localhost:55001/public/local") - # csp_match = None - # # I can't figure out re.MULTILINE - # for header in headers.split("\n"): - # csp_match = re.match('^Content-Security-Policy: (.*)$', header) - # if csp_match is not None: - # break - # if csp_match is None: - # raise Exception("pixelfed did not send a content security policy header") - # csp = csp_match.group(1) - # # the img-src content security policy should include the garage server - # garage_csp = re.match(".*; img-src[^;]*web\.garage\.localhost:3902.*", csp) - # if garage_csp is None: - # raise Exception("Pixelfed's content security policy does not include garage server. image will not be displayed properly on pixelfed.") - # NOTE: This could in theory give a false positive if pixelfed changes it's # colorscheme to include pure green. (see same problem in pixelfed-garage.nix). # TODO: For instance: post a red image and check that the green pixel IS NOT # there, then post a green image and check that the green pixel IS there. - with subtest("image displays"): - server.succeed(f"su - seleniumUser -c 'selenium-script test@test.com {password}'") - server.copy_from_vm("/home/seleniumUser/screenshot.png", "") + with subtest("Image displays"): + server.succeed(f"su - selenium -c 'selenium-script test@test.com {password}'") + server.copy_from_vm("/home/selenium/screenshot.png", "") displayed_colors = server.succeed("convert /screenshot.png -define histogram:unique-colors=true -format %c histogram:info:") # check that the green image displayed somewhere green_check = re.match(".*#00FF00.*", displayed_colors, re.S)