From b746c6c8cda56b4c18b0079210b550949484e99a Mon Sep 17 00:00:00 2001 From: Callahan Date: Fri, 4 Oct 2024 15:31:17 -0500 Subject: [PATCH] tests: add spread tests for registries (#5091) Add a spread test for `edit-registries` and `list-registries`. Fixes #5054 Signed-off-by: Callahan Kovacs --- tests/spread/store/registries/editor.sh | 12 ++++++ tests/spread/store/registries/task.yaml | 42 ++++++++++++++++++++ tests/spread/store/validation-sets/task.yaml | 4 +- 3 files changed, 55 insertions(+), 3 deletions(-) create mode 100755 tests/spread/store/registries/editor.sh create mode 100644 tests/spread/store/registries/task.yaml diff --git a/tests/spread/store/registries/editor.sh b/tests/spread/store/registries/editor.sh new file mode 100755 index 0000000000..46b07515a4 --- /dev/null +++ b/tests/spread/store/registries/editor.sh @@ -0,0 +1,12 @@ +#! /bin/bash + +registries_file="$1" + +# flip-flop between 'access' being read and write +if grep -q "^ *access:.*read" "$registries_file"; then + access="write" +else + access="read" +fi + +sed -i "s/^\([[:space:]]*\)access:.*/\1access: $access/g" "$registries_file" diff --git a/tests/spread/store/registries/task.yaml b/tests/spread/store/registries/task.yaml new file mode 100644 index 0000000000..8441a863c2 --- /dev/null +++ b/tests/spread/store/registries/task.yaml @@ -0,0 +1,42 @@ +summary: test the registries commands + +environment: + SNAPCRAFT_ASSERTION_KEY: "$(HOST: echo ${SNAPCRAFT_ASSERTION_KEY})" + SNAPCRAFT_STORE_CREDENTIALS: "$(HOST: echo ${SNAPCRAFT_STORE_CREDENTIALS_STAGING})" + +prepare: | + if [[ -z "$SNAPCRAFT_STORE_CREDENTIALS" ]]; then + ERROR "No credentials set in env SNAPCRAFT_STORE_CREDENTIALS" + fi + + if [[ -z "$SNAPCRAFT_ASSERTION_KEY" ]]; then + ERROR "No gpg key set in env SNAPCRAFT_ASSERTION_KEY" + fi + + # setup snap gpg dir + mkdir -p "$HOME/.snap/gnupg" + chmod 700 "$HOME/.snap/gnupg" + + # import a registered key + gpg --homedir "$HOME/.snap/gnupg" --import <(echo "$SNAPCRAFT_ASSERTION_KEY" | base64 --decode) + + snap install yq + # registries only available in edge + snap refresh snapd --edge + +execute: | + # ensure snapcraft is logged in and can access the store + snapcraft whoami + + # snapcraft will use a fake file editor + export EDITOR="$PWD/editor.sh" + + snapcraft edit-registries "$(snapcraft whoami | yq .id)" testset --key-name testspreadkey + + snapcraft list-registries | MATCH testset + +restore: | + rm -rf "$HOME/.snap/gnupg" + + snap remove --purge yq + snap refresh snapd --stable diff --git a/tests/spread/store/validation-sets/task.yaml b/tests/spread/store/validation-sets/task.yaml index 277ee9d8e1..599f01aad6 100644 --- a/tests/spread/store/validation-sets/task.yaml +++ b/tests/spread/store/validation-sets/task.yaml @@ -18,9 +18,7 @@ prepare: | chmod 700 "$HOME/.snap/gnupg" # import a registered key - echo "$SNAPCRAFT_ASSERTION_KEY" | base64 --decode > store-key.txt - gpg --homedir "$HOME/.snap/gnupg" --import store-key.txt - rm -f store-key.txt + gpg --homedir "$HOME/.snap/gnupg" --import <(echo "$SNAPCRAFT_ASSERTION_KEY" | base64 --decode) snap install yq