From 44896b15cb8c355c701681c67ae7701648500a82 Mon Sep 17 00:00:00 2001 From: Victor Engmark Date: Thu, 7 Dec 2023 15:45:29 +1300 Subject: [PATCH] aws-azure-login: Link Puppeteer to Chromium Closes #272544. The test verifies that the command fails for the *right* reason, rather than the original issue: > Error: Could not find expected browser (chrome) locally. Run `npm > install` to download the correct Chromium revision (982053). --- pkgs/by-name/aw/aws-azure-login/package.nix | 20 +++++++++++------ pkgs/by-name/aw/aws-azure-login/tests.nix | 24 +++++++++++++++++++++ 2 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 pkgs/by-name/aw/aws-azure-login/tests.nix diff --git a/pkgs/by-name/aw/aws-azure-login/package.nix b/pkgs/by-name/aw/aws-azure-login/package.nix index a98eb443107f..099726ba9e8d 100644 --- a/pkgs/by-name/aw/aws-azure-login/package.nix +++ b/pkgs/by-name/aw/aws-azure-login/package.nix @@ -1,5 +1,7 @@ { lib +, callPackage , stdenv +, chromium , fetchFromGitHub , fetchYarnDeps , makeWrapper @@ -7,24 +9,23 @@ , prefetch-yarn-deps , yarn }: - -stdenv.mkDerivation rec { +stdenv.mkDerivation (finalAttrs: { pname = "aws-azure-login"; version = "3.6.1"; src = fetchFromGitHub { owner = "aws-azure-login"; repo = "aws-azure-login"; - rev = "v${version}"; + rev = "v${finalAttrs.version}"; hash = "sha256-PvPnqaKD98h3dCjEOwF+Uc86xCJzn2b9XNHHn13h/2Y="; }; offlineCache = fetchYarnDeps { - yarnLock = "${src}/yarn.lock"; + yarnLock = "${finalAttrs.src}/yarn.lock"; hash = "sha256-SXQPRzF6b1FJl5HkyXNm3kGoNSDXux+0RYXBX93mOts="; }; - nativeBuildInputs = [ + nativeBuildInputs = [ makeWrapper nodejs prefetch-yarn-deps @@ -60,11 +61,16 @@ stdenv.mkDerivation rec { cp -r . "$out/lib/node_modules/aws-azure-login" makeWrapper "${nodejs}/bin/node" "$out/bin/aws-azure-login" \ - --add-flags "$out/lib/node_modules/aws-azure-login/lib/index.js" + --add-flags "$out/lib/node_modules/aws-azure-login/lib/index.js" \ + --set PUPPETEER_EXECUTABLE_PATH "${lib.getExe chromium}" runHook postInstall ''; + passthru.tests.aws-azure-login = callPackage ./tests.nix { + package = finalAttrs.finalPackage; + }; + meta = { description = "Use Azure AD SSO to log into the AWS via CLI"; homepage = "https://github.com/aws-azure-login/aws-azure-login"; @@ -73,4 +79,4 @@ stdenv.mkDerivation rec { maintainers = with lib.maintainers; [ l0b0 ]; platforms = lib.platforms.all; }; -} +}) diff --git a/pkgs/by-name/aw/aws-azure-login/tests.nix b/pkgs/by-name/aw/aws-azure-login/tests.nix new file mode 100644 index 000000000000..694492322c86 --- /dev/null +++ b/pkgs/by-name/aw/aws-azure-login/tests.nix @@ -0,0 +1,24 @@ +{ lib +, runCommand +, package +}: + runCommand "${package.pname}-tests" + { + HOME = "/tmp/home"; + } '' + mkdir -p "''${HOME}/.aws" + cat > "''${HOME}/.aws/config" <<'EOF' + [profile my-profile] + azure_tenant_id=3f03e308-ada1-45f7-9cc3-ab777eaba2d3 + azure_app_id_uri=4fbf61f5-7302-42e5-9585-b18ad0e4649d + azure_default_username=user@example.org + azure_default_role_arn= + azure_default_duration_hours=1 + azure_default_remember_me=false + EOF + + ! ${lib.getExe package} --profile=my-profile 2> stderr + [[ "$(cat stderr)" == 'Unable to recognize page state! A screenshot has been dumped to aws-azure-login-unrecognized-state.png. If this problem persists, try running with --mode=gui or --mode=debug' ]] + + touch $out + ''