From bb0207f68bbf25bac81148ffe1a12e0182f2fb46 Mon Sep 17 00:00:00 2001 From: Jason Luong Date: Fri, 13 Oct 2023 16:11:46 +0100 Subject: [PATCH] fix: failing smoke tests --- .github/workflows/smoke_tests.yaml | 218 +++++++++--------- .../cypress/integration/cypress-test.spec.js | 3 +- test/the.spec.ts | 4 +- 3 files changed, 112 insertions(+), 113 deletions(-) diff --git a/.github/workflows/smoke_tests.yaml b/.github/workflows/smoke_tests.yaml index d887cab..8f69788 100644 --- a/.github/workflows/smoke_tests.yaml +++ b/.github/workflows/smoke_tests.yaml @@ -1,109 +1,109 @@ - name: Smoke Tests - on: - push: - branches: - - master - pull_request: - - jobs: - smoke_tests: - name: Smoke tests @ Nexus ${{ matrix.nexus_version }} - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - nexus_version: [3.34.1] - - steps: - - name: Fetch sources - uses: actions/checkout@v2 - - - name: Setup JDK 8 - uses: actions/setup-java@v1 - with: - java-version: 8 - - - name: Cache local Maven repository - uses: actions/cache@v2 - with: - path: | - ~/.m2/repository - ~/.m2/wrapper - key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-m2 - - - name: Configure build metadata - id: metadata - run: echo ::set-output name=tag::1.0.0 - - # - name: Install Cypress - # run: npm install -g cypress@9.7.0 - - # - name: Build plugin - # env: - # TEST_SNYK_TOKEN: ${{ secrets.TEST_SNYK_TOKEN }} - # TEST_SNYK_ORG: ${{ secrets.TEST_SNYK_ORG }} - # run: | - # ./mvnw clean verify -DskipTests --show-version --batch-mode --errors -PbuildKar -Drevision=${{ steps.metadata.outputs.tag }} - # ls -la ${GITHUB_WORKSPACE}/plugin/target/nexus-snyk-security-plugin-bundle.kar - - # - name: Start the Nexus container with Snyk plugin mounted - # run: docker run -d --name nexus -p 8081:8081 -v ${GITHUB_WORKSPACE}/plugin/target/nexus-snyk-security-plugin-bundle.kar:/opt/sonatype/nexus/deploy/nexus-snyk-security-plugin-bundle.kar sonatype/nexus3 - - # - name: Wait for Nexus start - # run: npx wait-on --timeout 120000 --interval 2000 http://localhost:8081/ - - # - name: Wait for API status endpoint - # run: npx wait-on --timeout 120000 --interval 2000 http://localhost:8081/service/rest/v1/status/writable - - # - name: Run Cypress to log in to Nexus and set up Snyk plugin - # working-directory: test/smoke - # run: | - # docker exec nexus cat /nexus-data/admin.password > /tmp/password - # export NEXUS_PASS=$(cat /tmp/password) - # echo $NEXUS_PASS - # cat /tmp/password - # cypress run - # env: - # TEST_SNYK_TOKEN: ${{ secrets.TEST_SNYK_TOKEN }} - # TEST_SNYK_ORG: ${{ secrets.TEST_SNYK_ORG }} - - - name: Setup npm - run: npm install - - # - name: Lint Node.js - # run: npm run lint:formatting - - - name: Run Jest tests against running Nexus - run: | - export NEXUS_PASS=$(cat /tmp/password) - npm run test - - - uses: actions/upload-artifact@v2 - if: always() - with: - name: screenshots - path: /home/runner/work/nexus-snyk-security-plugin/nexus-snyk-security-plugin/test/smoke/cypress/screenshots/cypress-test.spec.js/ - retention-days: 1 - - - uses: actions/upload-artifact@v2 - if: always() - with: - name: video - path: /home/runner/work/nexus-snyk-security-plugin/nexus-snyk-security-plugin/test/smoke/cypress/videos/cypress-test.spec.js.mp4 - retention-days: 1 - - - name: Save docker logs to file - uses: jwalton/gh-docker-logs@v1 - with: - dest: "./logs" - - - name: Find any Snyk plugin errors in docker logs - run: "! grep -Hrni snyk ./logs | grep -i error" - - - name: Dump docker logs (on success) - uses: jwalton/gh-docker-logs@v1 - - - name: Dump docker logs (on failure) - if: failure() - uses: jwalton/gh-docker-logs@v1 +name: Smoke Tests +on: + push: + branches: + - master + pull_request: + +jobs: + smoke_tests: + name: Smoke tests @ Nexus ${{ matrix.nexus_version }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + nexus_version: [3.34.1] + + steps: + - name: Fetch sources + uses: actions/checkout@v2 + + - name: Setup JDK 8 + uses: actions/setup-java@v1 + with: + java-version: 8 + + - name: Cache local Maven repository + uses: actions/cache@v2 + with: + path: | + ~/.m2/repository + ~/.m2/wrapper + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-m2 + + - name: Configure build metadata + id: metadata + run: echo ::set-output name=tag::1.0.0 + + - name: Install Cypress + run: npm install -g cypress@9.7.0 + + - name: Build plugin + env: + TEST_SNYK_TOKEN: ${{ secrets.TEST_SNYK_TOKEN }} + TEST_SNYK_ORG: ${{ secrets.TEST_SNYK_ORG }} + run: | + ./mvnw clean verify -DskipTests --show-version --batch-mode --errors -PbuildKar -Drevision=${{ steps.metadata.outputs.tag }} + ls -la ${GITHUB_WORKSPACE}/plugin/target/nexus-snyk-security-plugin-bundle.kar + + - name: Start the Nexus container with Snyk plugin mounted + run: docker run -d --name nexus -p 8081:8081 -v ${GITHUB_WORKSPACE}/plugin/target/nexus-snyk-security-plugin-bundle.kar:/opt/sonatype/nexus/deploy/nexus-snyk-security-plugin-bundle.kar sonatype/nexus3 + + - name: Wait for Nexus start + run: npx wait-on --timeout 120000 --interval 2000 http://localhost:8081/ + + - name: Wait for API status endpoint + run: npx wait-on --timeout 120000 --interval 2000 http://localhost:8081/service/rest/v1/status/writable + + - name: Run Cypress to log in to Nexus and set up Snyk plugin + working-directory: test/smoke + run: | + docker exec nexus cat /nexus-data/admin.password > /tmp/password + export NEXUS_PASS=$(cat /tmp/password) + echo $NEXUS_PASS + cat /tmp/password + cypress run --headless --browser chrome + env: + TEST_SNYK_TOKEN: ${{ secrets.TEST_SNYK_TOKEN }} + TEST_SNYK_ORG: ${{ secrets.TEST_SNYK_ORG }} + + - name: Setup npm + run: npm install + + - name: Lint Node.js + run: npm run lint:formatting + + - name: Run Jest tests against running Nexus + run: | + export NEXUS_PASS=$(cat /tmp/password) + npm run test + + - uses: actions/upload-artifact@v2 + if: always() + with: + name: screenshots + path: /home/runner/work/nexus-snyk-security-plugin/nexus-snyk-security-plugin/test/smoke/cypress/screenshots/cypress-test.spec.js/ + retention-days: 1 + + - uses: actions/upload-artifact@v2 + if: always() + with: + name: video + path: /home/runner/work/nexus-snyk-security-plugin/nexus-snyk-security-plugin/test/smoke/cypress/videos/cypress-test.spec.js.mp4 + retention-days: 1 + + - name: Save docker logs to file + uses: jwalton/gh-docker-logs@v1 + with: + dest: "./logs" + + - name: Find any Snyk plugin errors in docker logs + run: "! grep -Hrni snyk ./logs | grep -i error" + + - name: Dump docker logs (on success) + uses: jwalton/gh-docker-logs@v1 + + - name: Dump docker logs (on failure) + if: failure() + uses: jwalton/gh-docker-logs@v1 diff --git a/test/smoke/cypress/integration/cypress-test.spec.js b/test/smoke/cypress/integration/cypress-test.spec.js index b57a713..51da83b 100644 --- a/test/smoke/cypress/integration/cypress-test.spec.js +++ b/test/smoke/cypress/integration/cypress-test.spec.js @@ -17,7 +17,7 @@ describe("test", () => { "This wizard will help you complete required setup tasks." ).should("be.visible"); - // Go through the mandatory wizard to set a new password (same as the old password) + // Go through the mandatory wizard to set a new password (same as the old password) cy.get("body").then(($body) => { if ($body.find('div[role="dialog"]').length) { cy.log("found the wizard"); @@ -82,6 +82,7 @@ describe("test", () => { cy.get('a[data-qtip="Server administration and configuration"]').click(); cy.contains('td[role="gridcell"]', "System").click(); cy.contains('div[role="option"]', "Capabilities").click(); + cy.contains("Loading").should("not.be.visible"); cy.contains('a[role="button"]', "Create capability").click(); cy.contains("Loading").should("not.be.visible"); cy.contains("Select Capability Type").should("be.visible"); diff --git a/test/the.spec.ts b/test/the.spec.ts index fc7101a..bd0bf07 100644 --- a/test/the.spec.ts +++ b/test/the.spec.ts @@ -36,7 +36,7 @@ it('can download a non-vulnerable package', async () => { expect(res.status).toBe(200); }); -it.only('throws when trying to download a vulnerable package', async () => { +it('throws when trying to download a vulnerable package', async () => { const url = buildNexusArtifactDownloadUrl( 'com.fasterxml.jackson.core', 'jackson-databind', @@ -56,7 +56,5 @@ it.only('throws when trying to download a vulnerable package', async () => { capturedErr = err; } - console.log('****', 'res ****\n', JSON.stringify(res, null, 2), '\n'); - console.log('****', 'capturedErr ****\n', JSON.stringify(capturedErr, null, 2), '\n'); expect(capturedErr.response.status).toEqual(500); });