-
Notifications
You must be signed in to change notification settings - Fork 0
196 lines (172 loc) · 6.93 KB
/
test.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
name: Test Docker Image
on:
pull_request:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
actions: read
security-events: write
env:
REGISTRY: ghcr.io
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: lowercase github.repository
run: |
echo "IMAGE_NAME=`echo ${{ env.REGISTRY }}/${{ github.repository }}:${{ github.sha }} | tr '[:upper:]' '[:lower:]'`" >> ${GITHUB_ENV}
- uses: docker/build-push-action@v6
with:
tags: "${{ env.IMAGE_NAME }}"
platforms: linux/amd64
-
name: Scan for vulnerabilities
uses: crazy-max/ghaction-container-scan@v3
id: scan
env:
TRIVY_DISABLE_VEX_NOTICE: true
with:
image: ${{ env.IMAGE_NAME }}
annotations: true
severity_threshold: HIGH
dockerfile: ./Dockerfile
-
name: Upload SARIF file
if: ${{ steps.scan.outputs.sarif != '' }}
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ${{ steps.scan.outputs.sarif }}
# cookie strategy
- name: Run Docker Image with Cookie Strategy
run: |
docker run --name statista_proxy -d -p80:80 \
-e STRATEGY=COOKIE \
-e OLD_DOMAIN=haproxy.com:443 -e NEW_DOMAIN=apache.org:443 \
-e COOKIE_STRATEGY_NAME="my_app_routing=new" \
"${{ env.IMAGE_NAME }}"
sleep 2
docker ps -a
docker logs statista_proxy
- name: Test Docker Image with Cookie Strategy without cookie
id: test-cookie-no-cookie
continue-on-error: true
run: |
curl -Is localhost:80 | grep -i -e "x-proxy-flow: route-to-legacy"
- name: Test Docker Image with Cookie Strategy with cookie
continue-on-error: true
run: |
curl -Is --cookie "my_app_routing=new" localhost:80 | grep -i -e "x-proxy-flow: route-to-new"
- name: Stop the Cookie Strategy Docker Image
if: success() || failure()
run: docker rm -f statista_proxy
# percentage strategy
- name: Run Docker Image with Percentage Strategy
run: |
docker run --name statista_proxy -d -p80:80 \
-e STRATEGY=PERCENTAGE \
-e OLD_DOMAIN=haproxy.com:443 -e NEW_DOMAIN=apache.org:443 \
-e PERCENTAGE_NEW=50 -e PERCENTAGE_OLD=50 \
-e COOKIE_PERCENTAGE_NAME=my_app \
"${{ env.IMAGE_NAME }}"
sleep 2
docker ps -a
docker logs statista_proxy
- name: Test Docker Image with Percentage Strategy backend selection
id: test-percentage-strategy
continue-on-error: true
run: |
curl -Is localhost:80 | grep -i -e "x-proxy-flow: route-to-percentage"
- name: Test Docker Image with Percentage Strategy with sticky cookie on old domain
id: test-percentage-sticky-old-domain
continue-on-error: true
run: |
curl -Is localhost:80 --cookie "my_app=old_domain_50" | grep -i -e "server: Apache"
- name: Test Docker Image with Percentage Strategy with sticky cookie on new domain
id: test-percentage-sticky-new-domain
continue-on-error: true
run: |
curl -Is localhost:80 --cookie "my_app=new_domain_50" | grep -i -e "x-served-by: cache-"
- name: Test Docker Image with Percentage Strategy with round robin
id: test-percentage-round-robin
continue-on-error: true
# sadly we dont know which server serves us first, so we have to check both
run: |
curl -Is localhost:80 | grep -i -e "server:" -e "x-served-by:" -e "set-cookie: my_app=new_domain; path=/" -e "set-cookie: my_app=old_domain; path=/"
curl -Is localhost:80 | grep -i -e "server:" -e "x-served-by:" -e "set-cookie: my_app=new_domain; path=/" -e "set-cookie: my_app=old_domain; path=/"
- name: Stop the Percentage Strategy Docker Image
if: success() || failure()
run: docker rm -f statista_proxy
# validation TEMPLATE
#- name: name of the test
# timeout-minutes: 1 # set so if the command runs successfully the test will fail
# id: test-validation-percentage-new # important since all steps run and we collect the failure at then end
# continue-on-error: true # important for allowing other steps to be run regardless of this one which might fail
# run: |
# ! docker run \ # important simply negate the exit code, since we expect the container to fail (which means succesfull validation)
# -e OLD_DOMAIN=haproxy.com:443 -e NEW_DOMAIN=apache.org:443 \
# "${{ env.IMAGE_NAME }}"
# variable validation
- name: Run Docker Image with Invalid new Percentage
timeout-minutes: 1
id: test-validation-percentage-new
continue-on-error: true
run: |
! docker run \
-e STRATEGY=PERCENTAGE \
-e OLD_DOMAIN=haproxy.com:443 -e NEW_DOMAIN=apache.org:443 \
-e PERCENTAGE_NEW=foo -e PERCENTAGE_OLD=50 \
-e COOKIE_PERCENTAGE_NAME=my_app \
"${{ env.IMAGE_NAME }}"
- name: Run Docker Image with Invalid old Percentage
timeout-minutes: 1
id: test-validation-percentage-old
continue-on-error: true
run: |
! docker run \
-e STRATEGY=PERCENTAGE \
-e OLD_DOMAIN=haproxy.com:443 -e NEW_DOMAIN=apache.org:443 \
-e PERCENTAGE_NEW=50 -e PERCENTAGE_OLD=foo \
-e COOKIE_PERCENTAGE_NAME=my_app \
"${{ env.IMAGE_NAME }}"
- name: Run Docker Image with Invalid old domain
timeout-minutes: 1
id: test-validation-old-domain
continue-on-error: true
run: |
! docker run \
-e STRATEGY=PERCENTAGE \
-e NEW_DOMAIN=apache.org:443 \
-e COOKIE_PERCENTAGE_NAME=my_app \
"${{ env.IMAGE_NAME }}"
- name: Run Docker Image with Invalid new domain
timeout-minutes: 1
id: test-validation-new-domain
continue-on-error: true
run: |
! docker run \
-e STRATEGY=PERCENTAGE \
-e OLD_DOMAIN=haproxy.com:443 -e NEW_DOMAIN=apache.org:lol \
-e COOKIE_PERCENTAGE_NAME=my_app \
"${{ env.IMAGE_NAME }}"
- name: Run Docker Image with Invalid server count
timeout-minutes: 1
id: test-validation-server-count
continue-on-error: true
run: |
! docker run \
-e STRATEGY=PERCENTAGE \
-e OLD_DOMAIN=haproxy.com:443 -e NEW_DOMAIN=apache.org:443 \
-e COOKIE_PERCENTAGE_NAME=my_app \
-e SERVER_COUNT=foo \
"${{ env.IMAGE_NAME }}"
- name: Check for failures
if: always()
env:
STEPS_CONTEXT: ${{ toJson(steps) }}
run: |
set +e
! echo "$STEPS_CONTEXT" | grep -q 'failure'