Skip to content

Commit f9b20d8

Browse files
committed
Add MySQL session type acceptance tests
1 parent d6ecd9d commit f9b20d8

File tree

4 files changed

+641
-0
lines changed

4 files changed

+641
-0
lines changed
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
name: Acceptance
2+
3+
# Optional, enabling concurrency limits: https://docs.github.com/en/actions/using-jobs/using-concurrency
4+
#concurrency:
5+
# group: ${{ github.ref }}-${{ github.workflow }}
6+
# cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
7+
8+
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions
9+
permissions:
10+
actions: none
11+
checks: none
12+
contents: none
13+
deployments: none
14+
id-token: none
15+
issues: none
16+
discussions: none
17+
packages: none
18+
pages: none
19+
pull-requests: none
20+
repository-projects: none
21+
security-events: none
22+
statuses: none
23+
24+
on:
25+
push:
26+
branches-ignore:
27+
- gh-pages
28+
- metakitty
29+
pull_request:
30+
branches:
31+
- '*'
32+
paths:
33+
- 'metsploit-framework.gemspec'
34+
- 'Gemfile.lock'
35+
- '**/**mysql**'
36+
- 'spec/acceptance/**'
37+
- 'spec/support/acceptance/**'
38+
- 'spec/acceptance_spec_helper.rb'
39+
# Example of running as a cron, to weed out flaky tests
40+
# schedule:
41+
# - cron: '*/15 * * * *'
42+
43+
jobs:
44+
mysql:
45+
runs-on: ${{ matrix.os }}
46+
timeout-minutes: 40
47+
48+
services:
49+
mysql:
50+
image: ${{ matrix.target.version }}
51+
ports: ["3306:3306"]
52+
env:
53+
MYSQL_ROOT_PASSWORD: password
54+
options: >-
55+
--health-cmd "${{ matrix.target.health_cmd }}"
56+
--health-interval 10s
57+
--health-timeout 10s
58+
--health-retries 5
59+
strategy:
60+
fail-fast: true
61+
matrix:
62+
ruby:
63+
- '3.2'
64+
os:
65+
- ubuntu-latest
66+
target:
67+
- { version: "mariadb:latest", health_cmd: "mariadb -uroot -ppassword -e 'SELECT version()'" }
68+
- { version: "mariadb:5.5.42", health_cmd: "mysql -uroot -ppassword -e 'SELECT version()'" }
69+
- { version: "mysql:latest", health_cmd: "mysql -uroot -ppassword -e 'SELECT version()'" }
70+
- { version: "mysql:5.5.42", health_cmd: "mysql -uroot -ppassword -e 'SELECT version()'" }
71+
72+
env:
73+
RAILS_ENV: test
74+
75+
name: ${{ matrix.target.version }} - ${{ matrix.os }} - Ruby ${{ matrix.ruby }}
76+
steps:
77+
- name: Install system dependencies
78+
run: sudo apt-get install -y --no-install-recommends libpcap-dev graphviz
79+
80+
- name: Checkout code
81+
uses: actions/checkout@v4
82+
83+
- name: Setup Ruby
84+
env:
85+
BUNDLE_WITHOUT: "coverage development pcap"
86+
# Nokogiri doesn't release pre-compiled binaries for preview versions of Ruby; So force compilation with BUNDLE_FORCE_RUBY_PLATFORM
87+
BUNDLE_FORCE_RUBY_PLATFORM: "${{ contains(matrix.ruby, 'preview') && 'true' || 'false' }}"
88+
uses: ruby/setup-ruby@v1
89+
with:
90+
ruby-version: '${{ matrix.ruby }}'
91+
bundler-cache: true
92+
93+
- name: Extract runtime version
94+
run: |
95+
echo "RUNTIME_VERSION=$(echo $DOCKER_IMAGE | awk -F: '{ print $2 }')" >> $GITHUB_ENV
96+
echo "DOCKER_IMAGE_FILENAME=$(echo $DOCKER_IMAGE | tr -d ':')" >> $GITHUB_ENV
97+
env:
98+
DOCKER_IMAGE: ${{ matrix.target.version }}
99+
OS: ${{ matrix.os }}
100+
101+
- name: acceptance
102+
env:
103+
SPEC_HELPER_LOAD_METASPLOIT: false
104+
SPEC_OPTS: "--tag acceptance --require acceptance_spec_helper.rb --color --format documentation --format AllureRspec::RSpecFormatter"
105+
RUNTIME_VERSION: ${{ env.RUNTIME_VERSION }}
106+
# Unix run command:
107+
# SPEC_HELPER_LOAD_METASPLOIT=false bundle exec ./spec/acceptance
108+
# Windows cmd command:
109+
# set SPEC_HELPER_LOAD_METASPLOIT=false
110+
# bundle exec rspec .\spec\acceptance
111+
# Note: rspec retry is intentionally not used, as it can cause issues with allure's reporting
112+
# Additionally - flakey tests should be fixed or marked as flakey instead of silently retried
113+
run: |
114+
bundle exec rspec spec/acceptance/mysql_spec.rb
115+
116+
- name: Archive results
117+
if: always()
118+
uses: actions/upload-artifact@v4
119+
with:
120+
# Provide a unique artifact for each matrix os, otherwise race conditions can lead to corrupt zips
121+
name: ${{ env.DOCKER_IMAGE_FILENAME }}-${{ matrix.os }}
122+
path: tmp/allure-raw-data
123+
124+
# Generate a final report from the previous test results
125+
report:
126+
name: Generate report
127+
needs:
128+
- mysql
129+
runs-on: ubuntu-latest
130+
if: always()
131+
132+
steps:
133+
- name: Checkout code
134+
uses: actions/checkout@v4
135+
if: always()
136+
137+
- name: Install system dependencies (Linux)
138+
if: always()
139+
run: sudo apt-get -y --no-install-recommends install libpcap-dev graphviz
140+
141+
- name: Setup Ruby
142+
if: always()
143+
env:
144+
BUNDLE_WITHOUT: "coverage development"
145+
BUNDLE_FORCE_RUBY_PLATFORM: true
146+
uses: ruby/setup-ruby@v1
147+
with:
148+
ruby-version: '${{ matrix.ruby }}'
149+
bundler-cache: true
150+
cache-version: 4
151+
# Github actions with Ruby requires Bundler 2.2.18+
152+
# https://github.com/ruby/setup-ruby/tree/d2b39ad0b52eca07d23f3aa14fdf2a3fcc1f411c#windows
153+
bundler: 2.2.33
154+
155+
- uses: actions/download-artifact@v4
156+
id: download
157+
if: always()
158+
with:
159+
# Note: Not specifying a name will download all artifacts from the previous workflow jobs
160+
path: raw-data
161+
162+
- name: allure generate
163+
if: always()
164+
run: |
165+
export VERSION=2.22.1
166+
167+
curl -o allure-$VERSION.tgz -Ls https://github.com/allure-framework/allure2/releases/download/$VERSION/allure-$VERSION.tgz
168+
tar -zxvf allure-$VERSION.tgz -C .
169+
170+
ls -la ${{steps.download.outputs.download-path}}
171+
./allure-$VERSION/bin/allure generate ${{steps.download.outputs.download-path}}/* -o ./allure-report
172+
173+
find ${{steps.download.outputs.download-path}}
174+
bundle exec ruby tools/dev/report_generation/support_matrix/generate.rb --allure-data ${{steps.download.outputs.download-path}} > ./allure-report/support_matrix.html
175+
176+
- name: archive results
177+
if: always()
178+
uses: actions/upload-artifact@v4
179+
with:
180+
name: final-report-${{ github.run_id }}
181+
path: |
182+
./allure-report

spec/acceptance/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ Run the test suite:
4747
POSTGRES_RPORT=9000 SPEC_OPTS='--tag acceptance' SPEC_HELPER_LOAD_METASPLOIT=false bundle exec rspec ./spec/acceptance/postgres_spec.rb
4848
```
4949

50+
### MySQL
51+
52+
Run a target:
53+
54+
```
55+
docker run -it --rm --publish 127.0.0.1:9001:3306 -e MYSQL_ROOT_PASSWORD=password mariadb:11.2.2
56+
```
57+
58+
Run the test suite:
59+
60+
```
61+
MYSQL_RPORT=9000 SPEC_OPTS='--tag acceptance' SPEC_HELPER_LOAD_METASPLOIT=false bundle exec rspec ./spec/acceptance/mysql_spec.rb
62+
```
63+
5064
#### Allure reports
5165

5266
Generate allure reports locally:

0 commit comments

Comments
 (0)