Skip to content

Commit 5269e2d

Browse files
authored
Merge pull request #1397 from rabbitmq/lukebakken/oauth2-gh-actions
Add workflow to test OAuth2
2 parents 55fc05a + 47878d7 commit 5269e2d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+613
-422
lines changed

.ci/gha-run-tests.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ if (Test-Path 'HKLM:\SOFTWARE\WOW6432Node\')
2121
$regPath = 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\RabbitMQ'
2222
}
2323
$rabbitmq_version = (Get-ItemProperty $regPath "DisplayVersion").DisplayVersion
24-
$rabbitmqctl_path = Join-Path -Path $rabbitmq_base_path -ChildPath "rabbitmq_server-$rabbitmq_version" | Join-Path -ChildPath 'sbin' | Join-Path -ChildPath 'rabbitmqctl.bat'
24+
$rabbitmqctl_path = Resolve-Path -LiteralPath (Join-Path -Path $rabbitmq_base_path -ChildPath "rabbitmq_server-$rabbitmq_version" | Join-Path -ChildPath 'sbin' | Join-Path -ChildPath 'rabbitmqctl.bat')
2525

2626
Write-Host "[INFO] Setting RABBITMQ_RABBITMQCTL_PATH to '$rabbitmqctl_path'..."
2727
$env:RABBITMQ_RABBITMQCTL_PATH = $rabbitmqctl_path
2828
[Environment]::SetEnvironmentVariable('RABBITMQ_RABBITMQCTL_PATH', $rabbitmqctl_path, 'Machine')
2929

30-
$build_csproj_file = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath 'Build.csproj'
31-
dotnet test $build_csproj_file --no-restore --no-build --logger "console;verbosity=detailed"
30+
$csproj_file = Resolve-Path -LiteralPath (Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath 'projects' | Join-Path -ChildPath 'Unit' | Join-Path -ChildPath 'Unit.csproj')
31+
dotnet test $csproj_file --no-restore --no-build --logger "console;verbosity=detailed"

.ci/oauth2/common.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
readonly docker_name_prefix='rabbitmq-dotnet-client-oauth2'
4+
5+
if [[ -d $GITHUB_WORKSPACE ]]
6+
then
7+
echo "[INFO] GITHUB_WORKSPACE is set: '$GITHUB_WORKSPACE'"
8+
else
9+
GITHUB_WORKSPACE="$(readlink --canonicalize-existing "$script_dir/../..")"
10+
echo "[INFO] set GITHUB_WORKSPACE to: '$GITHUB_WORKSPACE'"
11+
fi
12+
13+
set -o xtrace
14+
set -o nounset
15+
16+
readonly mode="${1:-uaa}"
17+
case $mode in
18+
keycloak|uaa)
19+
echo "[INFO] test mode is '$mode'";;
20+
*)
21+
echo "[ERROR] invalid test mode: '$mode'" 1>&2
22+
exit 64
23+
;;
24+
esac
25+

.ci/oauth2/setup.sh

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
#!/bin/bash
2+
3+
set -o errexit
4+
set -o pipefail
5+
6+
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
7+
readonly script_dir
8+
echo "[INFO] script_dir: '$script_dir'"
9+
10+
source "$script_dir/common.sh"
11+
12+
declare -r uaa_image_version='75.21.0'
13+
declare -r keycloak_image_version='20.0'
14+
declare -r docker_network="$docker_name_prefix-net"
15+
declare -r rabbitmq_docker_name="$docker_name_prefix-rabbitmq"
16+
17+
function err_todo
18+
{
19+
echo '[ERROR] TODO' 1>&2
20+
exit 69
21+
}
22+
23+
function mode_is_uaa
24+
{
25+
[[ $mode == 'uaa' ]]
26+
}
27+
28+
function mode_is_keycloak
29+
{
30+
[[ $mode == 'keycloak' ]]
31+
}
32+
33+
function create_network
34+
{
35+
docker network inspect "$docker_network" >/dev/null 2>&1 || docker network create "$docker_network"
36+
}
37+
38+
function oauth_service_is_not_running
39+
{
40+
if mode_is_uaa
41+
then
42+
[[ "$(curl -s localhost:8080/info | jq -r '.app.version')" != "$uaa_image_version" ]]
43+
else
44+
[[ "$(curl -s localhost:8080/health | jq -r '.status')" != 'UP' ]]
45+
fi
46+
}
47+
48+
function start_rabbitmq
49+
{
50+
docker rm --force "$rabbitmq_docker_name" 2>/dev/null || echo "[INFO] $rabbitmq_docker_name was not running"
51+
docker run --detach --name "$rabbitmq_docker_name" \
52+
--network "$docker_network" \
53+
--publish 5672:5672 \
54+
--publish 15672:15672 \
55+
--volume "$GITHUB_WORKSPACE/projects/OAuth2Test/enabled_plugins:/etc/rabbitmq/enabled_plugins" \
56+
--volume "$GITHUB_WORKSPACE/projects/OAuth2Test/$mode/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf:ro" \
57+
--volume "$GITHUB_WORKSPACE/projects/OAuth2Test/$mode/signing-key/signing-key.pem:/etc/rabbitmq/signing-key.pem:ro" \
58+
rabbitmq:3-management
59+
}
60+
61+
function wait_rabbitmq
62+
{
63+
set +o errexit
64+
set +o xtrace
65+
66+
declare -i count=12
67+
while (( count > 0 )) && [[ "$(docker inspect --format='{{.State.Running}}' "$rabbitmq_docker_name")" != 'true' ]]
68+
do
69+
echo '[WARNING] RabbitMQ container is not yet running...'
70+
sleep 5
71+
(( count-- ))
72+
done
73+
74+
declare -i count=12
75+
while (( count > 0 )) && ! docker exec "$rabbitmq_docker_name" epmd -names | grep -F 'name rabbit'
76+
do
77+
echo '[WARNING] epmd is not reporting rabbit name just yet...'
78+
sleep 5
79+
(( count-- ))
80+
done
81+
82+
docker exec "$rabbitmq_docker_name" rabbitmqctl await_startup
83+
84+
set -o errexit
85+
set -o xtrace
86+
}
87+
88+
function start_oauth_service
89+
{
90+
if mode_is_uaa
91+
then
92+
readonly uaa_docker_name="$docker_name_prefix-uaa"
93+
docker rm --force "$uaa_docker_name" 2>/dev/null || echo "[INFO] $uaa_docker_name was not running"
94+
docker run --detach --name "$uaa_docker_name" \
95+
--network "$docker_network" \
96+
--publish 8080:8080 \
97+
--env 'UAA_CONFIG_PATH=/uaa' \
98+
--env 'JAVA_OPTS=-Djava.security.egd=file:/dev/./urandom' \
99+
--volume "$GITHUB_WORKSPACE/projects/OAuth2Test/uaa:/uaa" \
100+
"cloudfoundry/uaa:$uaa_image_version"
101+
else
102+
readonly keycloak_docker_name="$docker_name_prefix-keycloak"
103+
docker rm --force "$keycloak_docker_name" 2>/dev/null || echo "[INFO] $keycloak_docker_name was not running"
104+
docker run --detach --name "$keycloak_docker_name" \
105+
--network "$docker_network" \
106+
--publish 8080:8080 \
107+
--env 'KEYCLOAK_ADMIN=admin' \
108+
--env 'KEYCLOAK_ADMIN_PASSWORD=admin' \
109+
--env KC_HEALTH_ENABLED=true \
110+
--volume "$GITHUB_WORKSPACE/projects/OAuth2Test/keycloak/import:/opt/keycloak/data/import" \
111+
"quay.io/keycloak/keycloak:$keycloak_image_version" start-dev --metrics-enabled=true --import-realm
112+
fi
113+
}
114+
115+
function wait_oauth_service
116+
{
117+
echo '[INFO] start waiting for OAuth service...'
118+
sleep 10
119+
120+
set +o errexit
121+
set +o xtrace
122+
123+
declare -i count=24
124+
while ((count > 0)) && oauth_service_is_not_running
125+
do
126+
echo '[WARNING] OAuth service is not yet running...'
127+
sleep 10
128+
(( count-- ))
129+
done
130+
131+
if (( count == 0 ))
132+
then
133+
if oauth_service_is_not_running
134+
then
135+
echo '[ERROR] OAUTH SERVICE DID NOT START' 1>&2
136+
docker ps --all
137+
exit 1
138+
fi
139+
fi
140+
141+
set -o errexit
142+
set -o xtrace
143+
}
144+
145+
create_network
146+
147+
start_rabbitmq &
148+
start_oauth_service &
149+
wait
150+
151+
wait_rabbitmq
152+
wait_oauth_service

.ci/oauth2/teardown.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
set -o errexit
4+
set -o pipefail
5+
6+
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
7+
readonly script_dir
8+
echo "[INFO] script_dir: '$script_dir'"
9+
10+
source "$script_dir/common.sh"
11+
12+
function docker_stop
13+
{
14+
local -r name="$1"
15+
local -r docker_name="$docker_name_prefix-$name"
16+
17+
set +o errexit
18+
if docker stop "$docker_name"
19+
then
20+
docker rm "$docker_name"
21+
fi
22+
set -o errexit
23+
}
24+
25+
docker_stop rabbitmq
26+
docker_stop uaa
27+
docker_stop keycloak
28+
29+
declare -r docker_network="$docker_name_prefix-net"
30+
docker network rm --force "$docker_network"

.ci/oauth2/test.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
set -o errexit
4+
set -o pipefail
5+
set -o xtrace
6+
7+
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
8+
readonly script_dir
9+
echo "[INFO] script_dir: '$script_dir'"
10+
11+
source "$script_dir/common.sh"
12+
13+
export OAUTH2_MODE="$mode"
14+
15+
dotnet test --environment OAUTH2_MODE="$mode" "$GITHUB_WORKSPACE/projects/OAuth2Test/OAuth2Test.csproj" --logger "console;verbosity=detailed" --framework "net6.0"

.ci/versions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"erlang": "26.1",
2+
"erlang": "26.1.1",
33
"rabbitmq": "3.12.6"
44
}

.github/workflows/main.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ jobs:
4242
- name: List NuGet sources
4343
run: dotnet nuget locals all --list
4444
- name: Restore
45-
run: dotnet restore ./Build.csproj --verbosity=normal
45+
run: dotnet restore ${{ github.workspace }}\Build.csproj --verbosity=normal
4646
- name: Build
47-
run: dotnet build ./Build.csproj --no-restore --verbosity=normal
47+
run: dotnet build ${{ github.workspace }}\Build.csproj --no-restore --verbosity=normal
4848
- name: Verify
49-
run: dotnet format ./RabbitMQDotNetClient.sln --no-restore --verbosity=diagnostic --verify-no-changes
49+
run: dotnet format ${{ github.workspace }}\RabbitMQDotNetClient.sln --no-restore --verbosity=diagnostic --verify-no-changes
5050
- name: Test
51-
run: ./.ci/gha-run-tests.ps1
51+
run: .\.ci\gha-run-tests.ps1
5252

5353
build:
5454
name: build/test on ubuntu-latest
@@ -68,7 +68,7 @@ jobs:
6868
with:
6969
submodules: true
7070
- name: Setup .NET
71-
uses: actions/setup-dotnet@v2
71+
uses: actions/setup-dotnet@v3
7272
with:
7373
dotnet-version: 6.x
7474
- name: Cache NuGet packages
@@ -81,12 +81,12 @@ jobs:
8181
restore-keys: |
8282
${{ runner.os }}-v0-nuget-
8383
- name: Restore
84-
run: dotnet restore ./Build.csproj --verbosity=normal
84+
run: dotnet restore ${{ github.workspace }}/Build.csproj --verbosity=normal
8585
- name: Build
86-
run: dotnet build ./Build.csproj --no-restore --verbosity=normal
86+
run: dotnet build ${{ github.workspace }}/Build.csproj --no-restore --verbosity=normal
8787
- name: Verify
88-
run: dotnet format ./RabbitMQDotNetClient.sln --no-restore --verbosity=diagnostic --verify-no-changes
88+
run: dotnet format ${{ github.workspace }}/RabbitMQDotNetClient.sln --no-restore --verbosity=diagnostic --verify-no-changes
8989
- name: Test
90-
run: dotnet test ./Build.csproj --no-restore --no-build --logger "console;verbosity=detailed" --framework "net6.0"
90+
run: dotnet test ${{ github.workspace }}/projects/Unit/Unit.csproj --no-restore --no-build --logger "console;verbosity=detailed" --framework "net6.0"
9191
env:
9292
RABBITMQ_RABBITMQCTL_PATH: DOCKER:${{job.services.rabbitmq.id}}

.github/workflows/oauth2.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: rabbitmq-dotnet-client-oauth2
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build-test:
11+
strategy:
12+
matrix:
13+
oauth2-provider: [ uaa, keycloak ]
14+
name: oauth2-${{ matrix.oauth2-provider }}
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
with:
19+
submodules: true
20+
- uses: actions/setup-dotnet@v3
21+
with:
22+
dotnet-version: 6.x
23+
- uses: actions/cache@v3
24+
with:
25+
path: |
26+
~/.nuget/packages
27+
~/.local/share/NuGet/v3-cache
28+
key: ${{ runner.os }}-v0-nuget-${{ hashFiles('**/*.csproj') }}
29+
restore-keys: |
30+
${{ runner.os }}-v0-nuget-
31+
- run: ${{ github.workspace }}/.ci/oauth2/setup.sh ${{ matrix.oauth2-provider }}
32+
- run: ${{ github.workspace }}/.ci/oauth2/test.sh ${{ matrix.oauth2-provider }}

Build.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<ProjectReference Include="projects/TestApplications/CreateChannel/CreateChannel.csproj" />
1313
<ProjectReference Include="projects/TestApplications/MassPublish/MassPublish.csproj" />
1414
<ProjectReference Include="projects/Unit/Unit.csproj" />
15+
<ProjectReference Include="projects/OAuth2Test/OAuth2Test.csproj" />
1516
</ItemGroup>
1617

1718
</Project>

RabbitMQDotNetClient.sln

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestApplications", "TestApp
1919
EndProject
2020
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreateChannel", "projects\TestApplications\CreateChannel\CreateChannel.csproj", "{4A589408-F3A3-40E1-A6DF-F5E620F7CA31}"
2121
EndProject
22-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RabbitMQ.Client.OAuth2", "projects\RabbitMQ.Client.OAuth2\RabbitMQ.Client.OAuth2.csproj", "{794C7B31-0E9A-44A4-B285-0F3CAF6209F1}"
22+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RabbitMQ.Client.OAuth2", "projects\RabbitMQ.Client.OAuth2\RabbitMQ.Client.OAuth2.csproj", "{794C7B31-0E9A-44A4-B285-0F3CAF6209F1}"
23+
EndProject
24+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OAuth2Test", "projects\OAuth2Test\OAuth2Test.csproj", "{897D13F0-AF06-444A-9072-CF7E809A4A2C}"
2325
EndProject
2426
Global
2527
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -51,6 +53,10 @@ Global
5153
{794C7B31-0E9A-44A4-B285-0F3CAF6209F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
5254
{794C7B31-0E9A-44A4-B285-0F3CAF6209F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
5355
{794C7B31-0E9A-44A4-B285-0F3CAF6209F1}.Release|Any CPU.Build.0 = Release|Any CPU
56+
{897D13F0-AF06-444A-9072-CF7E809A4A2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
57+
{897D13F0-AF06-444A-9072-CF7E809A4A2C}.Debug|Any CPU.Build.0 = Debug|Any CPU
58+
{897D13F0-AF06-444A-9072-CF7E809A4A2C}.Release|Any CPU.ActiveCfg = Release|Any CPU
59+
{897D13F0-AF06-444A-9072-CF7E809A4A2C}.Release|Any CPU.Build.0 = Release|Any CPU
5460
EndGlobalSection
5561
GlobalSection(SolutionProperties) = preSolution
5662
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)