From cbb5b21e6c4ff83d847882ba962e716684b3a65e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Arroba?= <19954079+cesararroba@users.noreply.github.com> Date: Tue, 22 Jul 2025 17:49:23 +0200 Subject: [PATCH] chore(gha): e2e tests pipeline with API services (#8338) --- .github/workflows/ui-pull-request.yml | 51 +++++++++++++++++-- .../backend/api/fixtures/dev/0_dev_users.json | 13 +++++ .../api/fixtures/dev/1_dev_tenants.json | 19 +++++++ .../backend/api/fixtures/dev/6_dev_rbac.json | 27 ++++++++++ 4 files changed, 107 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ui-pull-request.yml b/.github/workflows/ui-pull-request.yml index e82b892f48..c67014dc73 100644 --- a/.github/workflows/ui-pull-request.yml +++ b/.github/workflows/ui-pull-request.yml @@ -52,11 +52,49 @@ jobs: AUTH_SECRET: 'fallback-ci-secret-for-testing' AUTH_TRUST_HOST: true NEXTAUTH_URL: http://localhost:3000 + PROWLER_API_PORT: 8080 + NEXT_PUBLIC_API_BASE_URL: http://localhost:8080/api/v1 steps: - name: Checkout repository uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: persist-credentials: false + - name: Start needed services with docker compose + run: | + docker compose up -d api worker worker-beat + - name: Wait for prowler-api to respond + run: | + echo "Waiting for prowler-api..." + for i in {1..30}; do + if curl -s http://localhost:${PROWLER_API_PORT}/api/v1/docs >/dev/null 2>&1; then + echo "Prowler API is ready!" + break + fi + echo "Waiting for prowler-api... (attempt $i/30)" + sleep 3 + done + - name: Run database migrations + run: | + echo "Running Django migrations..." + docker compose exec -T api sh -c ' + poetry run python manage.py migrate --database admin + ' + echo "Database migrations completed!" + - name: Copy local fixtures into API container + run: | + docker cp ./api/src/backend/api/fixtures/dev/. prowler-api-1:/home/prowler/backend/api/fixtures/dev + - name: Load database fixtures for e2e tests + run: | + docker compose exec -T api sh -c ' + echo "Loading all fixtures from api/fixtures/dev/..." + for fixture in api/fixtures/dev/*.json; do + if [ -f "$fixture" ]; then + echo "Loading $fixture" + poetry run python manage.py loaddata "$fixture" --database admin + fi + done + echo "All database fixtures loaded successfully!" + ' - name: Setup Node.js uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 with: @@ -66,6 +104,9 @@ jobs: - name: Install dependencies working-directory: ./ui run: npm ci + - name: Build the application + working-directory: ./ui + run: npm run build - name: Cache Playwright browsers uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3 id: playwright-cache @@ -78,9 +119,6 @@ jobs: working-directory: ./ui if: steps.playwright-cache.outputs.cache-hit != 'true' run: npm run test:e2e:install - - name: Build the application - working-directory: ./ui - run: npm run build - name: Run Playwright tests working-directory: ./ui run: npm run test:e2e @@ -92,6 +130,13 @@ jobs: path: ui/playwright-report/ retention-days: 30 + - name: Cleanup services + if: always() + run: | + echo "Shutting down services..." + docker-compose down -v || true + echo "Cleanup completed" + test-container-build: runs-on: ubuntu-latest steps: diff --git a/api/src/backend/api/fixtures/dev/0_dev_users.json b/api/src/backend/api/fixtures/dev/0_dev_users.json index 61fb0bd883..bd61994982 100644 --- a/api/src/backend/api/fixtures/dev/0_dev_users.json +++ b/api/src/backend/api/fixtures/dev/0_dev_users.json @@ -24,5 +24,18 @@ "is_active": true, "date_joined": "2024-09-18T09:04:20.850Z" } + }, + { + "model": "api.user", + "pk": "6d4f8a91-3c2e-4b5a-8f7d-1e9c5b2a4d6f", + "fields": { + "password": "pbkdf2_sha256$870000$Z63pGJ7nre48hfcGbk5S0O$rQpKczAmijs96xa+gPVJifpT3Fetb8DOusl5Eq6gxac=", + "last_login": null, + "name": "E2E Test User", + "email": "e2e@prowler.com", + "company_name": "Prowler E2E Tests", + "is_active": true, + "date_joined": "2024-01-01T00:00:00.850Z" + } } ] diff --git a/api/src/backend/api/fixtures/dev/1_dev_tenants.json b/api/src/backend/api/fixtures/dev/1_dev_tenants.json index dd89b100d4..1b5cdfa314 100644 --- a/api/src/backend/api/fixtures/dev/1_dev_tenants.json +++ b/api/src/backend/api/fixtures/dev/1_dev_tenants.json @@ -46,5 +46,24 @@ "role": "member", "date_joined": "2024-09-19T11:03:59.712Z" } + }, + { + "model": "api.tenant", + "pk": "7c8f94a3-e2d1-4b3a-9f87-2c4d5e6f1a2b", + "fields": { + "inserted_at": "2024-01-01T00:00:00Z", + "updated_at": "2024-01-01T00:00:00Z", + "name": "E2E Test Tenant" + } + }, + { + "model": "api.membership", + "pk": "9b1a2c3d-4e5f-6789-abc1-23456789def0", + "fields": { + "user": "6d4f8a91-3c2e-4b5a-8f7d-1e9c5b2a4d6f", + "tenant": "7c8f94a3-e2d1-4b3a-9f87-2c4d5e6f1a2b", + "role": "owner", + "date_joined": "2024-01-01T00:00:00.000Z" + } } ] diff --git a/api/src/backend/api/fixtures/dev/6_dev_rbac.json b/api/src/backend/api/fixtures/dev/6_dev_rbac.json index 84ce439fa5..ccd1816301 100644 --- a/api/src/backend/api/fixtures/dev/6_dev_rbac.json +++ b/api/src/backend/api/fixtures/dev/6_dev_rbac.json @@ -149,5 +149,32 @@ "user": "8b38e2eb-6689-4f1e-a4ba-95b275130200", "inserted_at": "2024-11-20T15:36:14.302Z" } + }, + { + "model": "api.role", + "pk": "a5b6c7d8-9e0f-1234-5678-90abcdef1234", + "fields": { + "tenant": "7c8f94a3-e2d1-4b3a-9f87-2c4d5e6f1a2b", + "name": "e2e_admin", + "manage_users": true, + "manage_account": true, + "manage_billing": true, + "manage_providers": true, + "manage_integrations": true, + "manage_scans": true, + "unlimited_visibility": true, + "inserted_at": "2024-01-01T00:00:00.000Z", + "updated_at": "2024-01-01T00:00:00.000Z" + } + }, + { + "model": "api.userrolerelationship", + "pk": "f1e2d3c4-b5a6-9876-5432-10fedcba9876", + "fields": { + "tenant": "7c8f94a3-e2d1-4b3a-9f87-2c4d5e6f1a2b", + "role": "a5b6c7d8-9e0f-1234-5678-90abcdef1234", + "user": "6d4f8a91-3c2e-4b5a-8f7d-1e9c5b2a4d6f", + "inserted_at": "2024-01-01T00:00:00.000Z" + } } ]