From 9db7ecb1766d2dccdd14d92105d1c8ffeb7e9835 Mon Sep 17 00:00:00 2001 From: Brandon Mitchell Date: Wed, 16 Oct 2024 10:42:14 -0400 Subject: [PATCH] Fix: Handle special characters in the inputs Signed-off-by: Brandon Mitchell --- .github/workflows/test-action.yml | 35 +++++++++++++++++++++++++++++-- regctl-login/action.yml | 10 ++++++++- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-action.yml b/.github/workflows/test-action.yml index a7afc3f..72cf38b 100644 --- a/.github/workflows/test-action.yml +++ b/.github/workflows/test-action.yml @@ -8,8 +8,11 @@ jobs: name: Test regctl install strategy: matrix: - version: ["latest", "main", "v0.4.7"] + version: ["latest", "main", "v0.5.7"] os: [macos-latest, ubuntu-latest, windows-latest] + env: + example_user: "demo$user" + example_pass: "example$pass\\word'\"with#special&chars" runs-on: ${{ matrix.os }} steps: - name: Check out code @@ -37,7 +40,15 @@ jobs: - name: Login uses: ./regctl-login/ - - name: Check root directory + - name: Login + uses: ./regctl-login/ + with: + registry: "localhost:5000" + username: "${{ env.example_user }}" + password: "${{ env.example_pass }}" + options: "--skip-check" + + - name: Check the git working directory shell: bash run: | if [[ $(git diff --stat) != '' ]]; then @@ -46,3 +57,23 @@ jobs: else exit 0 fi + + - name: Verify credentials were set + shell: bash + env: + expect_gh_user: ${{ github.actor }} + expect_gh_token: ${{ github.token }} + run: | + gh_user="$(jq -r '.hosts."ghcr.io".user' <~/.regctl/config.json)" + gh_token="$(jq -r '.hosts."ghcr.io".pass' <~/.regctl/config.json)" + echo "::add-mask::$gh_token" + if [ "$gh_user" != "$expect_gh_user" ] || [ "$gh_token" != "$expect_gh_token" ]; then + echo "default login did not save expected values" >&2 + exit 1 + fi + local_user="$(jq -r '.hosts."localhost:5000".user' <~/.regctl/config.json)" + local_pass="$(jq -r '.hosts."localhost:5000".pass' <~/.regctl/config.json)" + if [ "$local_user" != "$example_user" ] || [ "$local_pass" != "${example_pass}" ]; then + echo "localhost:5000 login did not save expected values" >&2 + exit 1 + fi diff --git a/regctl-login/action.yml b/regctl-login/action.yml index 6dc9459..3fd4095 100644 --- a/regctl-login/action.yml +++ b/regctl-login/action.yml @@ -17,9 +17,17 @@ inputs: description: password to login with required: false default: ${{ github.token }} + options: + description: options for regctl registry login, e.g. --skip-check + required: false runs: using: 'composite' steps: - shell: bash + env: + REGISTRY: ${{ inputs.registry }} + USERNAME: ${{ inputs.username }} + PASSWORD: ${{ inputs.password }} run: | - echo "${{ inputs.password }}" | regctl registry login "${{ inputs.registry }}" -u "${{ inputs.username }}" --pass-stdin + echo "::add-mask::${PASSWORD}" + echo "${PASSWORD}" | regctl registry login "${REGISTRY}" -u "${USERNAME}" --pass-stdin ${{ inputs.options }}