|
| 1 | +name: Integration Tests |
| 2 | +on: push |
| 3 | + |
| 4 | +jobs: |
| 5 | + # Label of the container job |
| 6 | + integration-tests: |
| 7 | + strategy: |
| 8 | + matrix: |
| 9 | + sslmode: ["nossl", "ssl"] |
| 10 | + |
| 11 | + # Containers must run in Linux based operating systems |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + steps: |
| 15 | + #----------------------------------------------------------- |
| 16 | + # 1‑‑‑‑ Check out your code & set up Node |
| 17 | + #----------------------------------------------------------- |
| 18 | + - name: Check out repository code |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Use Node.js 18 |
| 22 | + uses: actions/setup-node@v3 |
| 23 | + with: |
| 24 | + node-version: '18' |
| 25 | + |
| 26 | + #----------------------------------------------------------- |
| 27 | + # 2‑‑‑‑ Generate a local CA + server cert / key |
| 28 | + #----------------------------------------------------------- |
| 29 | + - name: Generate self-signed certificates |
| 30 | + if: matrix.sslmode == 'ssl' |
| 31 | + run: | |
| 32 | + set -euo pipefail |
| 33 | + mkdir -p certs |
| 34 | +
|
| 35 | + # CA ─────────────────────────────────────────────────── |
| 36 | + openssl req -x509 -newkey rsa:2048 -nodes \ |
| 37 | + -keyout certs/ca.key \ |
| 38 | + -out certs/ca.crt \ |
| 39 | + -days 365 \ |
| 40 | + -subj "/CN=Test-CA" |
| 41 | +
|
| 42 | + # Server key & CSR ──────────────────────────────────── |
| 43 | + openssl req -newkey rsa:2048 -nodes \ |
| 44 | + -keyout certs/server.key \ |
| 45 | + -out certs/server.csr \ |
| 46 | + -subj "/CN=localhost" |
| 47 | +
|
| 48 | + # Sign the server cert with the CA ──────────────────── |
| 49 | + openssl x509 -req -in certs/server.csr \ |
| 50 | + -CA certs/ca.crt -CAkey certs/ca.key -CAcreateserial \ |
| 51 | + -out certs/server.crt \ |
| 52 | + -days 365 |
| 53 | +
|
| 54 | + # For RabbitMQ the key file must be 0600 |
| 55 | + chmod 644 certs/* |
| 56 | + chmod 755 certs |
| 57 | +
|
| 58 | + # list the certs |
| 59 | + echo $PWD |
| 60 | + ls -l certs |
| 61 | +
|
| 62 | + #----------------------------------------------------------- |
| 63 | + # 3‑‑‑‑ Write a minimal rabbitmq.conf that enables TLS only |
| 64 | + #----------------------------------------------------------- |
| 65 | + - name: Write rabbitmq.conf |
| 66 | + if: matrix.sslmode == 'ssl' |
| 67 | + run: | |
| 68 | + cat > rabbitmq.conf <<'EOF' |
| 69 | + ## disable plain AMQP |
| 70 | + listeners.tcp = none |
| 71 | +
|
| 72 | + ## TLS listener on 5671 |
| 73 | + listeners.ssl.default = 5671 |
| 74 | +
|
| 75 | + ssl_options.cacertfile = /etc/rabbitmq/certs/ca.crt |
| 76 | + ssl_options.certfile = /etc/rabbitmq/certs/server.crt |
| 77 | + ssl_options.keyfile = /etc/rabbitmq/certs/server.key |
| 78 | + ssl_options.verify = verify_none |
| 79 | + ssl_options.fail_if_no_peer_cert = false |
| 80 | +
|
| 81 | + ## (optional) secure the management UI on 15671 |
| 82 | + management.ssl.port = 15671 |
| 83 | + management.ssl.cacertfile = /etc/rabbitmq/certs/ca.crt |
| 84 | + management.ssl.certfile = /etc/rabbitmq/certs/server.crt |
| 85 | + management.ssl.keyfile = /etc/rabbitmq/certs/server.key |
| 86 | + EOF |
| 87 | +
|
| 88 | + #----------------------------------------------------------- |
| 89 | + # 4a‑‑‑ Launch RabbitMQ with the certs + config bind‑mounted |
| 90 | + #----------------------------------------------------------- |
| 91 | + - name: Start RabbitMQ in SSL Mode (via Docker) |
| 92 | + if: matrix.sslmode == 'ssl' |
| 93 | + run: | |
| 94 | + docker run -d --name rabbitmq \ |
| 95 | + --user rabbitmq \ |
| 96 | + -e RABBITMQ_ERLANG_COOKIE="your_secret_cookie" \ |
| 97 | + -v "$PWD/certs":/etc/rabbitmq/certs:ro \ |
| 98 | + -v "$PWD/rabbitmq.conf":/etc/rabbitmq/rabbitmq.conf:ro \ |
| 99 | + -p 5671:5671 -p 15671:15671 \ |
| 100 | + rabbitmq:3-management |
| 101 | + # cat /etc/rabbitmq/certs/server.key from inside the container |
| 102 | + docker exec rabbitmq ls -l /etc/rabbitmq/certs |
| 103 | +
|
| 104 | + #----------------------------------------------------------- |
| 105 | + # 4b‑‑‑ Launch RabbitMQ without certs (plain AMQP) |
| 106 | + #----------------------------------------------------------- |
| 107 | + - name: Start RabbitMQ in NoSSL Mode (via Docker) |
| 108 | + if: matrix.sslmode == 'nossl' |
| 109 | + run: | |
| 110 | + docker run -d --name rabbitmq \ |
| 111 | + --user rabbitmq \ |
| 112 | + -e RABBITMQ_ERLANG_COOKIE="your_secret_cookie" \ |
| 113 | + -p 5672:5672 -p 15672:15672 \ |
| 114 | + rabbitmq:3-management |
| 115 | +
|
| 116 | + #----------------------------------------------------------- |
| 117 | + # 5‑‑‑‑ Wait until the broker is healthy |
| 118 | + #----------------------------------------------------------- |
| 119 | + - name: Wait for RabbitMQ to be ready |
| 120 | + run: | |
| 121 | + set -e |
| 122 | + if [ "${{ matrix.sslmode }}" = "ssl" ]; then |
| 123 | + SCHEME="https" |
| 124 | + PORT=15671 |
| 125 | + else |
| 126 | + SCHEME="http" |
| 127 | + PORT=15672 |
| 128 | + fi |
| 129 | + # wait for RabbitMQ to be healthy |
| 130 | + for i in {1..5}; do |
| 131 | + if docker exec rabbitmq rabbitmq-diagnostics -q ping; then |
| 132 | + if curl -kI "${SCHEME}://localhost:${PORT}/api/auth"; then |
| 133 | + echo "RabbitMQ is ready" |
| 134 | + exit 0 |
| 135 | + fi |
| 136 | + fi |
| 137 | + sleep 3 |
| 138 | + done |
| 139 | + echo "RabbitMQ never became ready" && exit 1 |
| 140 | +
|
| 141 | + #----------------------------------------------------------- |
| 142 | + # 6‑‑‑‑ Install dependencies & run the test suite |
| 143 | + #----------------------------------------------------------- |
| 144 | + - name: Install dependencies |
| 145 | + run: npm install |
| 146 | + |
| 147 | + - name: Run the test suite |
| 148 | + env: |
| 149 | + RABBITMQ_HOST: localhost # inside the runner |
| 150 | + RABBITMQ_PORT: ${{ matrix.sslmode == 'ssl' && 5671 || 5672 }} |
| 151 | + RABBITMQ_MANAGEMENT_PORT: ${{ matrix.sslmode == 'ssl' && 15671 || 15672 }} |
| 152 | + RABBITMQ_SSL_MODE: ${{ matrix.sslmode == 'ssl' && 'true' || 'false' }} |
| 153 | + NODE_TLS_REJECT_UNAUTHORIZED: '0' # ignore the self‑signed CA (tests only!) |
| 154 | + run: npm run test:e2e |
| 155 | + |
| 156 | + #----------------------------------------------------------- |
| 157 | + # 7‑‑‑‑ (optional) Show logs if the job failed |
| 158 | + #----------------------------------------------------------- |
| 159 | + - name: Print RabbitMQ logs on failure |
| 160 | + if: failure() |
| 161 | + run: docker logs rabbitmq |
0 commit comments