Skip to content

Commit a7542af

Browse files
Run TLS tests on Actions, expand test matrix, borrow org ideas from rabbitmqadmin v2
1 parent 2459e08 commit a7542af

File tree

4 files changed

+163
-14
lines changed

4 files changed

+163
-14
lines changed

.github/workflows/ci.yml

Lines changed: 148 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,180 @@ on:
1010

1111
jobs:
1212
test:
13+
name: Ruby ${{ matrix.ruby }} / RabbitMQ ${{ matrix.rabbitmq }}
1314
runs-on: ubuntu-latest
1415

1516
strategy:
17+
fail-fast: false
1618
matrix:
17-
ruby-version:
19+
ruby:
1820
- "3.4"
1921
- "3.3"
2022
- "3.2"
2123
- "3.1"
24+
rabbitmq:
25+
- "4.2"
26+
- "4.1"
27+
- "4.0"
28+
- "3.13"
2229

2330
env:
2431
CI: true
25-
RUNS: 5
2632

2733
services:
2834
rabbitmq:
29-
image: rabbitmq:4-management
35+
image: rabbitmq:${{ matrix.rabbitmq }}-management
3036
ports:
3137
- 15672:15672
3238
- 5672:5672
3339

3440
steps:
3541
- uses: actions/checkout@v4
36-
- name: Set up Ruby ${{ matrix.ruby-version }}
42+
43+
- name: Set up Ruby ${{ matrix.ruby }}
3744
uses: ruby/setup-ruby@v1
3845
with:
39-
ruby-version: ${{ matrix.ruby-version }}
46+
ruby-version: ${{ matrix.ruby }}
47+
4048
- name: Install dependencies
4149
run: bundle install
4250

51+
- name: Wait for RabbitMQ to start
52+
run: sleep 10
53+
4354
- name: Configure RabbitMQ
4455
run: BUNNY_RABBITMQCTL=DOCKER:${{job.services.rabbitmq.id}} BUNNY_RABBITMQ_PLUGINS=DOCKER:${{job.services.rabbitmq.id}} bin/ci/before_build.sh
4556

4657
- name: Run tests
47-
run: bundle exec rspec -c -fd spec/higher_level_api spec/lower_level_api spec/issues
58+
run: bundle exec rspec --require rspec/retry -c -fd spec/higher_level_api spec/lower_level_api spec/issues
59+
env:
60+
RSPEC_RETRY_COUNT: 2
61+
62+
tls-tests:
63+
name: TLS Tests (Ruby ${{ matrix.ruby }} / RabbitMQ ${{ matrix.rabbitmq }})
64+
runs-on: ubuntu-latest
65+
66+
strategy:
67+
fail-fast: false
68+
matrix:
69+
ruby:
70+
- "3.4"
71+
- "3.3"
72+
rabbitmq:
73+
- "4.1"
74+
- "4.0"
75+
76+
env:
77+
CI: true
78+
79+
steps:
80+
- uses: actions/checkout@v4
81+
82+
- name: Set up Ruby ${{ matrix.ruby }}
83+
uses: ruby/setup-ruby@v1
84+
with:
85+
ruby-version: ${{ matrix.ruby }}
86+
87+
- name: Install dependencies
88+
run: bundle install
89+
90+
- name: Clone tls-gen
91+
run: git clone --depth 1 https://github.com/rabbitmq/tls-gen.git target/tls-gen
92+
93+
- name: Generate TLS certificates
94+
run: |
95+
cd target/tls-gen/basic
96+
make CN=localhost
97+
98+
- name: Copy certificates
99+
run: |
100+
cp target/tls-gen/basic/result/ca_certificate.pem spec/tls/
101+
cp target/tls-gen/basic/result/server_localhost_certificate.pem spec/tls/server_certificate.pem
102+
cp target/tls-gen/basic/result/server_localhost_key.pem spec/tls/server_key.pem
103+
cp target/tls-gen/basic/result/client_localhost_certificate.pem spec/tls/client_certificate.pem
104+
cp target/tls-gen/basic/result/client_localhost_key.pem spec/tls/client_key.pem
105+
chmod o+r spec/tls/*
106+
chmod g+r spec/tls/*
107+
108+
- name: Create RabbitMQ TLS configuration
109+
run: |
110+
cat > spec/tls/rabbitmq.conf << 'EOF'
111+
listeners.ssl.default = 5671
112+
ssl_options.cacertfile = /certs/ca_certificate.pem
113+
ssl_options.certfile = /certs/server_certificate.pem
114+
ssl_options.keyfile = /certs/server_key.pem
115+
ssl_options.verify = verify_none
116+
loopback_users = none
117+
EOF
118+
sed -i 's/^[[:space:]]*//' spec/tls/rabbitmq.conf
119+
echo -n "rabbitmq-test-cookie" > spec/tls/.erlang.cookie
120+
chmod 600 spec/tls/.erlang.cookie
121+
122+
- name: Start RabbitMQ with TLS
123+
run: |
124+
docker run -d --name rabbitmq-tls \
125+
-p 5671:5671 \
126+
-p 5672:5672 \
127+
-p 15672:15672 \
128+
-v ${{ github.workspace }}/spec/tls/.erlang.cookie:/var/lib/rabbitmq/.erlang.cookie \
129+
-v ${{ github.workspace }}/spec/tls:/certs:ro \
130+
-v ${{ github.workspace }}/spec/tls/rabbitmq.conf:/etc/rabbitmq/conf.d/10-tls.conf:ro \
131+
rabbitmq:${{ matrix.rabbitmq }}-management
132+
133+
- name: Wait for RabbitMQ to start
134+
run: |
135+
for i in $(seq 1 30); do
136+
if docker exec rabbitmq-tls rabbitmqctl await_startup --timeout 60; then
137+
echo "RabbitMQ is ready"
138+
exit 0
139+
fi
140+
echo "Waiting for container... ($i/30)"
141+
sleep 2
142+
done
143+
echo "RabbitMQ failed to start. Container logs:"
144+
docker logs rabbitmq-tls
145+
exit 1
146+
147+
- name: Verify TLS listener
148+
run: |
149+
docker exec rabbitmq-tls rabbitmq-diagnostics listeners
150+
151+
- name: Configure broker
152+
run: BUNNY_RABBITMQCTL="docker exec rabbitmq-tls rabbitmqctl" BUNNY_RABBITMQ_PLUGINS="docker exec rabbitmq-tls rabbitmq-plugins" bin/ci/before_build.sh
153+
154+
- name: Run TLS tests
155+
run: bundle exec rspec --require rspec/retry -c -fd spec/higher_level_api/integration/tls_connection_spec.rb
156+
env:
157+
RSPEC_RETRY_COUNT: 2
158+
RUN_TLS_TESTS: "true"
159+
160+
- name: Stop RabbitMQ container
161+
if: always()
162+
run: docker stop rabbitmq-tls && docker rm rabbitmq-tls || true
163+
164+
unit:
165+
name: Unit Tests (Ruby ${{ matrix.ruby }})
166+
runs-on: ubuntu-latest
167+
168+
strategy:
169+
fail-fast: false
170+
matrix:
171+
ruby:
172+
- "3.4"
173+
- "3.3"
174+
175+
steps:
176+
- uses: actions/checkout@v4
177+
178+
- name: Set up Ruby ${{ matrix.ruby }}
179+
uses: ruby/setup-ruby@v1
180+
with:
181+
ruby-version: ${{ matrix.ruby }}
182+
183+
- name: Install dependencies
184+
run: bundle install
185+
186+
- name: Run unit tests
187+
run: bundle exec rspec --require rspec/retry -c -fd spec/unit
188+
env:
189+
RSPEC_RETRY_COUNT: 2

CONTRIBUTING.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,9 @@ It is possible to run all tests:
130130
It is possible to run only integration and regression tests but exclude unit and stress tests:
131131

132132
CI=true bundle exec rspec spec/higher_level_api/ spec/lower_level_api spec/issues spec/higher_level_api/integration/connection_recovery_spec.rb
133+
134+
To run TLS connection tests locally, set the `RUN_TLS_TESTS` environment variable:
135+
136+
RUN_TLS_TESTS=true bundle exec rspec spec/higher_level_api/integration/tls_connection_spec.rb
137+
138+
TLS tests require a RabbitMQ node configured with TLS certificates. See the "Using a locally installed RabbitMQ node" section above for certificate setup instructions

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ end
3030

3131
group :test do
3232
gem "rspec", "~> 3.13.0"
33+
gem "rspec-retry", "~> 0.6"
3334
gem "sorted_set", '~> 1', '>= 1.0.2'
3435
gem "base64"
3536
gem "rabbitmq_http_api_client", "~> 2.2.0", require: "rabbitmq/http/client"

spec/higher_level_api/integration/tls_connection_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
puts "Will use certificates from #{CERTIFICATE_DIR}"
88

99
shared_examples_for "successful TLS connection" do
10-
it "succeeds", skip: ENV["CI"] do
10+
it "succeeds", skip: !ENV["RUN_TLS_TESTS"] do
1111
expect(subject).to be_tls
1212
ch = subject.create_channel
1313
ch.confirm_select
@@ -39,7 +39,7 @@ def local_hostname
3939
ENV.fetch("BUNNY_RABBITMQ_HOSTNAME", "localhost")
4040
end
4141

42-
context "initialized with tls: true", skip: ENV["CI"] do
42+
context "initialized with tls: true", skip: !ENV["RUN_TLS_TESTS"] do
4343
let(:subject) do
4444
Bunny.new(
4545
hostname: local_hostname(),
@@ -80,7 +80,7 @@ def local_hostname
8080
end
8181
end
8282

83-
describe "TLS connection to RabbitMQ with client certificates", skip: ENV["CI"] do
83+
describe "TLS connection to RabbitMQ with client certificates", skip: !ENV["RUN_TLS_TESTS"] do
8484
let(:subject) do
8585
c = Bunny.new(
8686
hostname: local_hostname(),
@@ -105,7 +105,7 @@ def local_hostname
105105
end
106106

107107

108-
describe "TLS connection to RabbitMQ without client certificates", skip: ENV["CI"] do
108+
describe "TLS connection to RabbitMQ without client certificates", skip: !ENV["RUN_TLS_TESTS"] do
109109
let(:subject) do
110110
c = Bunny.new(
111111
hostname: local_hostname(),
@@ -128,7 +128,7 @@ def local_hostname
128128
end
129129

130130

131-
describe "TLS connection to RabbitMQ with a connection string", skip: ENV["CI"] do
131+
describe "TLS connection to RabbitMQ with a connection string", skip: !ENV["RUN_TLS_TESTS"] do
132132
let(:subject) do
133133
c = Bunny.new("amqps://bunny_gem:bunny_password@#{local_hostname()}/bunny_testbed",
134134
tls_protocol: :TLSv1_2,
@@ -164,7 +164,7 @@ def local_hostname
164164
end
165165

166166

167-
describe "TLS connection to RabbitMQ with a connection string and w/o client certificate and key", skip: ENV["CI"] do
167+
describe "TLS connection to RabbitMQ with a connection string and w/o client certificate and key", skip: !ENV["RUN_TLS_TESTS"] do
168168
let(:subject) do
169169
c = Bunny.new("amqps://bunny_gem:bunny_password@#{local_hostname()}/bunny_testbed",
170170
tls_ca_certificates: ["#{CERTIFICATE_DIR}/ca_certificate.pem"],
@@ -201,7 +201,7 @@ def local_hostname
201201
end
202202
end
203203

204-
describe "TLS connection to RabbitMQ w/o client certificate", skip: ENV["CI"] do
204+
describe "TLS connection to RabbitMQ w/o client certificate", skip: !ENV["RUN_TLS_TESTS"] do
205205
let(:subject) do
206206
c = Bunny.new("amqps://bunny_gem:bunny_password@#{local_hostname()}/bunny_testbed",
207207
tls_ca_certificates: ["#{CERTIFICATE_DIR}/ca_certificate.pem"],
@@ -230,7 +230,7 @@ def local_hostname
230230
end
231231

232232

233-
describe "TLS connection to RabbitMQ with client certificates provided inline", skip: ENV["CI"] do
233+
describe "TLS connection to RabbitMQ with client certificates provided inline", skip: !ENV["RUN_TLS_TESTS"] do
234234
let(:subject) do
235235
c = Bunny.new(
236236
hostname: local_hostname(),

0 commit comments

Comments
 (0)