Skip to content

Commit 62dc199

Browse files
committed
Adding TLS test script to workflow
1 parent 5620afd commit 62dc199

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

.github/workflows/test.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,26 @@ jobs:
6767
run: |
6868
pythonw server/game_server.py
6969
python tests/test_api.py
70+
test-tls:
71+
name: TLS
72+
runs-on: ubuntu-latest
73+
steps:
74+
- name: Checkout repository
75+
uses: actions/checkout@v6
76+
- name: Copy files
77+
run: |
78+
mkdir tests
79+
cp client/game_server_api.py tests/
80+
cp .github/workflows/test*.py tests/
81+
- name: Create certificate and key
82+
run: |
83+
openssl req -x509 -newkey ed25519 -keyout server/key.pem \
84+
-out server/cert.pem -sha256 -days 3650 -noenc -subj '/CN=localhost'
85+
cp server/cert.pem tests/
86+
echo "ip = 'localhost'" >> server/config.py
87+
echo "tls_cert = 'cert.pem'" >> server/config.py
88+
echo "tls_key = 'key.pem'" >> server/config.py
89+
- name: Start server
90+
run: server/game_server.py &
91+
- name: Test
92+
run: tests/test_tls.py

.github/workflows/test_tls.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Testing TLS.
4+
"""
5+
6+
from game_server_api import GameServerAPI, GameServerError
7+
8+
SERVER = 'localhost'
9+
PORT = 4711
10+
11+
def fail(msg):
12+
exit(f'ERROR: {msg}')
13+
14+
# ========== encryption only ==========
15+
16+
game = GameServerAPI(SERVER, PORT, 'Echo', 'tlstest', 1)
17+
18+
try:
19+
game.enable_tls()
20+
21+
game.join()
22+
game.move(msg='Hello')
23+
state = game.state()
24+
if state['echo'] != 'Hello':
25+
fail('wrong echo')
26+
except GameServerError as e:
27+
fail(e)
28+
29+
# ========== encryption and server identity verification ==========
30+
31+
game = GameServerAPI(SERVER, PORT, 'Echo', 'tlstest', 1)
32+
33+
try:
34+
game.enable_tls('cert.pem')
35+
36+
game.join()
37+
game.move(msg='Hello')
38+
state = game.state()
39+
if state['echo'] != 'Hello':
40+
fail('wrong echo')
41+
except GameServerError as e:
42+
fail(e)
43+
44+
print('OK')

0 commit comments

Comments
 (0)