From fdac0ff8de77fe75a38d98786300abbc5a00ee34 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Thu, 30 Jan 2025 16:48:46 -0600 Subject: [PATCH] Add basic pki and pki-server CLI tests The CI tests have been updated to check some basic operations of pki and pki-server CLIs for displaying help messages, showing version number, and handling subcommands. --- .github/workflows/ca-existing-ds-test.yml | 27 ++++---- .github/workflows/pki-basic-test.yml | 70 +++++++++++++++++++++ .github/workflows/server-basic-test.yml | 59 ++++++++++------- .github/workflows/server-https-nss-test.yml | 27 ++++---- .github/workflows/tools-tests.yml | 5 ++ 5 files changed, 139 insertions(+), 49 deletions(-) create mode 100644 .github/workflows/pki-basic-test.yml diff --git a/.github/workflows/ca-existing-ds-test.yml b/.github/workflows/ca-existing-ds-test.yml index b1ac92e325b..b24e687976b 100644 --- a/.github/workflows/ca-existing-ds-test.yml +++ b/.github/workflows/ca-existing-ds-test.yml @@ -124,6 +124,19 @@ jobs: --cert admin.crt \ caadmin + - name: Check pki-server ca CLI help message + run: | + docker exec pki pki-server ca + docker exec pki pki-server ca --help + + # TODO: validate output + + - name: Check pki-server ca-create CLI help message + run: | + docker exec pki pki-server ca-create --help + + # TODO: validate output + - name: Create CA subsystem run: | docker exec pki pki-server ca-create -v @@ -402,17 +415,3 @@ jobs: if: always() run: | docker exec pki find /var/lib/pki/pki-tomcat/logs/ca -name "debug.*" -exec cat {} \; - - - name: Gather artifacts - if: always() - run: | - tests/bin/ds-artifacts-save.sh ds - tests/bin/pki-artifacts-save.sh pki - continue-on-error: true - - - name: Upload artifacts - if: always() - uses: actions/upload-artifact@v4 - with: - name: ca-existing-ds - path: /tmp/artifacts diff --git a/.github/workflows/pki-basic-test.yml b/.github/workflows/pki-basic-test.yml new file mode 100644 index 00000000000..88befcfc1a2 --- /dev/null +++ b/.github/workflows/pki-basic-test.yml @@ -0,0 +1,70 @@ +name: Basic PKI CLI +# https://github.com/dogtagpki/pki/wiki/PKI-CLI + +on: workflow_call + +env: + DS_IMAGE: ${{ vars.DS_IMAGE || 'quay.io/389ds/dirsrv' }} + +jobs: + test: + name: Test + runs-on: ubuntu-latest + env: + SHARED: /tmp/workdir/pki + steps: + - name: Clone repository + uses: actions/checkout@v4 + + - name: Retrieve PKI images + uses: actions/cache@v4 + with: + key: pki-images-${{ github.sha }} + path: pki-images.tar + + - name: Load PKI images + run: docker load --input pki-images.tar + + - name: Set up runner container + run: | + tests/bin/runner-init.sh \ + --hostname=pki.example.com \ + pki + + - name: Check pki CLI help message + run: | + docker exec pki pki + docker exec pki pki --help + + # TODO: validate output + + - name: Check pki CLI version + run: | + docker exec pki pki --version + + # TODO: validate output + + - name: Check pki CLI with wrong option + run: | + docker exec pki pki --wrong \ + > >(tee stdout) 2> >(tee stderr >&2) || true + + # TODO: validate output + + - name: Check pki CLI with wrong sub-command + run: | + docker exec pki pki wrong \ + > >(tee stdout) 2> >(tee stderr >&2) || true + + cat > expected << EOF + ERROR: Invalid module "wrong". + EOF + + diff expected stderr + + - name: Check pki nss CLI help message + run: | + docker exec pki pki nss + docker exec pki pki nss --help + + # TODO: validate output diff --git a/.github/workflows/server-basic-test.yml b/.github/workflows/server-basic-test.yml index dea38c2291d..a78e755bd2c 100644 --- a/.github/workflows/server-basic-test.yml +++ b/.github/workflows/server-basic-test.yml @@ -1,4 +1,5 @@ name: Basic server +# https://github.com/dogtagpki/pki/wiki/PKI-Server-CLI on: workflow_call @@ -37,6 +38,43 @@ jobs: - name: Connect server container to network run: docker network connect example pki --alias pki.example.com + - name: Check pki-server CLI help message + run: | + docker exec pki pki-server + docker exec pki pki-server --help + + # TODO: validate output + + - name: Check pki-server CLI version + run: | + docker exec pki pki-server --version + + # TODO: validate output + + - name: Check pki-server CLI with wrong option + run: | + docker exec pki pki-server --wrong \ + > >(tee stdout) 2> >(tee stderr >&2) || true + + # TODO: validate output + + - name: Check pki-server CLI with wrong sub-command + run: | + docker exec pki pki-server wrong \ + > >(tee stdout) 2> >(tee stderr >&2) || true + + cat > expected << EOF + ERROR: Invalid module "wrong". + EOF + + diff expected stderr + + - name: Check pki-server create CLI help message + run: | + docker exec pki pki-server create --help + + # TODO: validate output + - name: Create pki-tomcat server run: | docker exec pki pki-server create -v @@ -412,24 +450,3 @@ jobs: EOF diff expected output - - - name: Gather artifacts from server container - if: always() - run: | - tests/bin/pki-artifacts-save.sh pki - - docker exec pki ls -la /var/lib/tomcats/pki/conf - mkdir -p /tmp/artifacts/pki/var/lib/tomcats/pki/conf - docker cp pki:/var/lib/tomcats/pki/conf/* /tmp/artifacts/var/lib/tomcats/pki/conf - - docker exec pki ls -la /var/lib/tomcats/pki/logs - mkdir -p /tmp/artifacts/pki/var/lib/tomcats/pki/logs - docker cp pki:/var/lib/tomcats/pki/logs/* /tmp/artifacts/var/lib/tomcats/pki/logs - continue-on-error: true - - - name: Upload artifacts from server container - if: always() - uses: actions/upload-artifact@v4 - with: - name: server-basic-test - path: /tmp/artifacts diff --git a/.github/workflows/server-https-nss-test.yml b/.github/workflows/server-https-nss-test.yml index f8763b4dea6..6cf9d6b0f2e 100644 --- a/.github/workflows/server-https-nss-test.yml +++ b/.github/workflows/server-https-nss-test.yml @@ -41,6 +41,19 @@ jobs: run: | docker exec pki pki-server create -v + - name: Check pki-server nss CLI help message + run: | + docker exec pki pki-server nss + docker exec pki pki-server nss --help + + # TODO: validate output + + - name: Check pki-server nss-create CLI help message + run: | + docker exec pki pki-server nss-create --help + + # TODO: validate output + - name: Create NSS database in PKI server run: | docker exec pki pki-server nss-create --no-password @@ -371,17 +384,3 @@ jobs: if: always() run: | docker exec pki find /var/lib/pki/pki-tomcat/logs/pki -name "debug.*" -exec cat {} \; - - - name: Gather artifacts from server container - if: always() - run: | - tests/bin/pki-artifacts-save.sh pki - continue-on-error: true - - - name: Upload artifacts from server container - if: always() - uses: actions/upload-artifact@v4 - with: - name: server-https-nss-test - path: | - /tmp/artifacts/pki diff --git a/.github/workflows/tools-tests.yml b/.github/workflows/tools-tests.yml index 1527f874560..a4d69b869a3 100644 --- a/.github/workflows/tools-tests.yml +++ b/.github/workflows/tools-tests.yml @@ -8,6 +8,11 @@ jobs: uses: ./.github/workflows/wait-for-build.yml secrets: inherit + pki-basic-test: + name: Basic PKI CLI + needs: build + uses: ./.github/workflows/pki-basic-test.yml + PKICertImport-test: name: PKICertImport needs: build