Skip to content

Latest commit

 

History

History
374 lines (268 loc) · 12.1 KB

File metadata and controls

374 lines (268 loc) · 12.1 KB

NiFi Docker Test Environment

Docker-based test environment for both custom NiFi processors: the MultiIssuerJWTTokenAuthenticator (FlowFile-based JWT validation) and the RestApiGateway (the primary flow group — an HTTP gateway with JWT auth). Provides containerized NiFi (HTTPS) and Keycloak instances for testing with real JWT tokens.

Exposed NiFi ports: 9095/9443 (NiFi HTTPS UI/API and the gateway’s embedded HTTPS listener) and 7777 (the HandleHttpRequest flow pipeline). Keycloak is on 9085 (HTTPS) and 9086 (management/health).

1. Prerequisites

  • Docker with Compose plugin (docker compose)

  • curl (for health check scripts)

  • Maven (or use the included ./mvnw wrapper)

2. Quick Start

# 1. Build NAR and start containers (Keycloak + NiFi)
./integration-testing/src/main/docker/run-and-deploy.sh

# 2. Access services
#    NiFi UI:       https://localhost:9095/nifi/  (testUser / drowssap)
#    Keycloak HTTPS: https://localhost:9085/admin/ (admin / admin)

# 3. Stop containers
./integration-testing/src/main/docker/stop-test-container.sh

3. Service Configuration

3.1. NiFi

Setting Value

URL

https://localhost:9095/nifi/

API

https://localhost:9095/nifi-api/

Protocol

HTTPS (self-signed certificate, port 8443 internal → 9095 host)

Authentication

SingleUserLoginIdentityProvider

Credentials

testUser / drowssap

Base image

apache/nifi:2.10.0

NAR mount

repo-root target/nifi-deploy//opt/nifi/nifi-current/nar_extensions (docker-compose mounts ../../../../target/nifi-deploy, i.e. the reactor root, not a directory under integration-testing/)

Custom configuration files are copied from src/main/docker/nifi/conf/ into the container at build time.

3.2. Keycloak

Setting Value

HTTPS Admin

https://localhost:9085 (port 8443 internal)

Health endpoint

https://localhost:9086/health/ready (port 9000 internal)

Admin credentials

admin / admin

Image

quay.io/keycloak/keycloak:26.2.5

Database

In-memory (KC_DB=dev-mem)

3.2.1. Pre-configured Realm: oauth_integration_tests

Setting Value

Test users

testUser / drowssap (roles: user, read), limitedUser / drowssap (roles: user)

Test client ID

test_client

Client type

Public client (no secret required)

JWKS endpoint (from host)

https://localhost:9085/realms/oauth_integration_tests/protocol/openid-connect/certs

JWKS endpoint (container-to-container)

https://keycloak:8443/realms/oauth_integration_tests/protocol/openid-connect/certs

The realm is imported automatically from src/main/docker/keycloak/oauth_integration_tests-realm.json.

3.2.2. Pre-configured Realm: other_realm

Separate realm with its own RSA key pair, used for invalid-signature testing.

Setting Value

Test user

otherUser / drowssap (roles: user)

Test client ID

other_client

Client secret

otherClientSecretValue123456789

JWKS endpoint (from host)

https://localhost:9085/realms/other_realm/protocol/openid-connect/certs

The realm is imported automatically from src/main/docker/keycloak/other_realm-realm.json.

4. Scripts

All scripts are in src/main/docker/. They can be run from any directory.

4.1. Lifecycle Scripts

Script Description

run-and-deploy.sh

Full startup: always rebuilds NARs (mvnw package), copies to deploy dir, starts Keycloak (with health wait), starts NiFi (with health wait)

start-nifi.sh

Starts Keycloak first, then NiFi. Waits for both to be healthy (2-minute timeout). Does NOT build/deploy the NAR.

start-keycloak.sh

Starts Keycloak only and waits for health check via https://localhost:9086/health/ready (60-second timeout)

stop-test-container.sh

Runs docker compose down to stop and remove all containers

redeploy-nifi.sh

Rebuilds NAR, copies to deploy dir, restarts NiFi container (docker compose restart nifi)

wait-and-start-processors.sh

Waits for NiFi to be ready, then starts all flow processors via the NiFi REST API and verifies the flow pipeline bound to port 7777. Invoked by start-nifi.sh and redeploy-nifi.sh.

copy-deployment.sh

Copies both nifi-cuioss-api-nar and nifi-cuioss-nar to target/nifi-deploy/. Accepts --skip-build to skip the Maven build when NARs were already built by the Maven reactor (used by deploy-and-start.sh). Without the flag, always runs ./mvnw package -DskipTests to ensure fresh NARs.

4.2. Diagnostic Scripts

Script Description

check-status.sh

Fast health check of Docker containers and HTTP endpoints. Supports --timeout, --interval, --quiet, --verbose, and --help flags.

debug-containers.sh

Prints Docker system info, container status, logs, and resource usage

debug-nar-deployment.sh

Checks NAR file existence and deployment status in both host and container

4.3. Maintenance Scripts (in maintenance/)

Script Description

generate-certificates.sh

Generates self-signed certificates for NiFi (PKCS12) and Keycloak (PEM)

verify-certificates.sh

Validates certificate files and their usage

verify-login.sh

Tests NiFi authentication flow

setup-credentials.sh

Sets NiFi SingleUser credentials via nifi.sh set-single-user-credentials

5. Directory Structure

src/main/docker/
├── Dockerfile                     # NiFi container (based on apache/nifi:2.10.0)
├── docker-compose.yml             # NiFi + Keycloak orchestration
├── certificates/                  # Generated TLS certificates
│   ├── keystore.p12              #   NiFi keystore
│   ├── truststore.p12            #   NiFi truststore
│   ├── localhost.cer             #   Keycloak certificate (DER)
│   ├── localhost.crt             #   Keycloak certificate (PEM)
│   └── localhost.key             #   Keycloak private key
├── nifi/conf/                     # NiFi configuration (copied into container)
│   ├── nifi.properties           #   Main config (HTTPS on 8443)
│   ├── login-identity-providers.xml  # SingleUser: testUser/drowssap
│   ├── authorizers.xml           #   SingleUser authorizer
│   ├── keystore.p12 / truststore.p12 # TLS keystores
│   ├── flow.json / flow.json.gz  #   Pre-configured flow (JSON source + gzipped; the .gz is what NiFi loads)
│   ├── cui-nifi-extensions.properties  #   CUI extension static configuration
│   ├── test-jwks.json             #   JWKS test data for validation tests
│   └── bootstrap.conf / logback.xml / state-management.xml
├── keycloak/
│   ├── oauth_integration_tests-realm.json  # Primary realm import
│   └── other_realm-realm.json              # Secondary realm (signature testing)
├── maintenance/                   # Certificate and credential utilities
├── scripts/                       # Maven-invoked orchestration scripts
│   ├── deploy-and-start.sh       #   Pre-integration-test: copy NAR + start containers + wait
│   ├── wait-for-containers.sh    #   Health polling: containers → NiFi API → flow pipeline
│   └── stop-containers.sh        #   Post-integration-test: stop containers
├── run-and-deploy.sh             # Full build + start (always rebuilds NARs)
├── start-nifi.sh                 # Start Keycloak + NiFi
├── start-keycloak.sh             # Start Keycloak only
├── stop-test-container.sh        # Stop all containers
├── redeploy-nifi.sh              # Rebuild + restart NiFi (always rebuilds NARs)
├── copy-deployment.sh            # Build + copy NAR (--skip-build to skip Maven)
├── check-status.sh               # Health check
├── debug-containers.sh           # Container diagnostics
└── debug-nar-deployment.sh       # NAR deployment diagnostics

6. Development Workflow

6.1. Initial Setup

# Build NAR and start everything
./integration-testing/src/main/docker/run-and-deploy.sh

6.2. Code Change Cycle

# After modifying processor code or UI:
./integration-testing/src/main/docker/redeploy-nifi.sh

This rebuilds the NAR, copies it to the deploy directory, and restarts the NiFi container.

6.3. Testing the Processor

  1. Open NiFi at https://localhost:9095/nifi/ and log in with testUser / drowssap

  2. Drag a processor onto the canvas, search for MultiIssuerJWTTokenAuthenticator

  3. Configure the JWKS URL: https://keycloak:8443/realms/oauth_integration_tests/protocol/openid-connect/certs

  4. Obtain a test token from Keycloak:

    curl -sk -X POST https://localhost:9085/realms/oauth_integration_tests/protocol/openid-connect/token \
      -H 'Content-Type: application/x-www-form-urlencoded' \
      -d 'grant_type=password&client_id=test_client&username=testUser&password=drowssap'

7. Test Execution

7.1. Maven Integration Tests

When running via Maven (./mvnw verify -Pintegration-tests -pl integration-testing -am), the lifecycle is:

  1. Maven reactor builds all dependent modules (processors, UI WAR, NARs) via -am

  2. deploy-and-start.sh (pre-integration-test phase) copies NARs to deploy dir (skipping redundant Maven build via --skip-build), starts Docker containers, and waits for readiness

  3. Failsafe runs all IT classes with parallel class execution (3 concurrent threads)

  4. cleanup-containers (post-integration-test phase) collects logs and stops containers

7.2. Parallel Test Execution

Integration test classes run concurrently via junit-platform.properties:

  • Classes run in parallel (up to 3 concurrent threads)

  • Methods within a class run sequentially (preserves @Nested ordering)

  • All tests are read-only against shared containers, so parallel execution is safe

7.3. NAR Build Optimization

copy-deployment.sh accepts --skip-build to avoid redundant Maven builds:

  • Maven path (deploy-and-start.sh): passes --skip-build because the Maven reactor already built fresh NARs

  • Standalone path (run-and-deploy.sh, redeploy-nifi.sh): always rebuilds to pick up code changes

8. Certificate Configuration

Self-signed certificates for localhost with 1-year validity:

  • NiFi: PKCS12 format (keystore.p12, truststore.p12), password: password

  • Keycloak: PEM format (localhost.crt, localhost.key)

Certificates are checked into the repository. Regenerate if needed:

./integration-testing/src/main/docker/maintenance/generate-certificates.sh

9. Troubleshooting

9.1. Check Service Status

# Quick health check
./integration-testing/src/main/docker/check-status.sh

# Container status
docker compose -f integration-testing/src/main/docker/docker-compose.yml ps

9.2. View Logs

# NiFi logs
docker compose -f integration-testing/src/main/docker/docker-compose.yml logs nifi

# Follow NiFi application log
docker compose -f integration-testing/src/main/docker/docker-compose.yml exec nifi \
  tail -f /opt/nifi/nifi-current/logs/nifi-app.log

# Keycloak logs
docker compose -f integration-testing/src/main/docker/docker-compose.yml logs keycloak

9.3. Common Issues

Issue Resolution

Port conflict on 9085, 9086, 9095, 9443, or 7777

Stop other services using those ports, or check with lsof -i :9095 (also check :9443 for the gateway HTTPS listener and :7777 for the flow pipeline)

NiFi fails to start

Check logs; ensure certificates exist in nifi/conf/; run debug-containers.sh

Keycloak health check fails

Verify port 9086 is reachable: curl -k https://localhost:9086/health/ready

NAR not loaded

Run debug-nar-deployment.sh; verify target/nifi-deploy/ contains both NAR files (nifi-cuioss-api-nar and nifi-cuioss-nar)

Certificate errors in browser

Expected with self-signed certs — accept the warning. Regenerate with maintenance/generate-certificates.sh if expired.