This repository was archived by the owner on Mar 6, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 97
311 lines (270 loc) · 11.3 KB
/
pull-request-testing.yaml
File metadata and controls
311 lines (270 loc) · 11.3 KB
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
name: PR Test - Build and Integration Test
on:
pull_request:
branches: [master]
env:
NODE_VERSION: '22'
jobs:
build-and-test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16-alpine
env:
POSTGRES_USER: testuser
POSTGRES_PASSWORD: testpassword
POSTGRES_DB: testdb
ports:
- 5432:5432
options: >-
--health-cmd="pg_isready -U testuser -d testdb"
--health-interval=10s
--health-timeout=5s
--health-retries=5
steps:
- name: Checkout PR
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm install
- name: Generate Prisma client
env:
DATABASE_URL: postgresql://testuser:testpassword@localhost:5432/testdb
run: npx prisma generate
- name: Run database migrations
env:
DATABASE_URL: postgresql://testuser:testpassword@localhost:5432/testdb
run: npx prisma migrate deploy
- name: Build the backend
env:
DATABASE_URL: postgresql://testuser:testpassword@localhost:5432/testdb
META_NAME: 'CI Backend Test server'
META_DESCRIPTION: 'CI Test Instance'
CRYPTO_SECRET: '0GwvbW7ZHlpZ6y0uSkU22Xi7XjoMpHX' # This is just for the CI server. DO NOT USE IN PROD
run: npm run build
- name: Start the backend server
env:
DATABASE_URL: postgresql://testuser:testpassword@localhost:5432/testdb
META_NAME: 'Test Backend'
META_DESCRIPTION: 'CI Test Instance'
CRYPTO_SECRET: '0GwvbW7ZHlpZ6y0uSkU22Xi7XjoMpHX'
run: |
node .output/server/index.mjs &
echo $! > server.pid
# Wait for server to be ready
for i in {1..30}; do
if curl -s http://localhost:3000 > /dev/null; then
echo "Server is ready!"
break
fi
echo "Waiting for server... attempt $i"
sleep 2
done
- name: Verify server is running
run: |
response=$(curl -s http://localhost:3000)
echo "Server response: $response"
if echo "$response" | grep -q "Backend is working"; then
echo "+------------------+------+"
echo "| Backend Working? | True |"
echo "+------------------+------+"
else
echo "+------------------+--------+"
echo "| Backend Working? | FAILED |"
echo "+------------------+--------+"
exit 1
fi
- name: Run account creation integration test
run: |
# Making sure this is installed cause it keeeps failing cause of this
# Create a Node.js script to handle the crypto operations
cat > auth-test.mjs << 'EOF'
import crypto from 'crypto';
import nacl from 'tweetnacl';
const TEST_MNEMONIC = "awkward safe differ large subway junk gallery flight left glue fault glory";
function toBase64Url(buffer) {
return Buffer.from(buffer)
.toString('base64')
.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/=+$/g, '');
}
async function pbkdf2Async(password, salt, iterations, keyLen, digest) {
return new Promise((resolve, reject) => {
crypto.pbkdf2(password, salt, iterations, keyLen, digest, (err, derivedKey) => {
if (err) return reject(err);
resolve(new Uint8Array(derivedKey));
});
});
}
async function main() {
console.log("=== Step 1: Getting challenge code ===");
const challengeRes = await fetch('http://localhost:3000/auth/register/start', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({})
});
const challengeData = await challengeRes.json();
const challengeCode = challengeData.challenge;
if (!challengeCode) {
console.log("+----------------+-----------+");
console.log("| Challenge Code | NOT FOUND |");
console.log("+----------------+-----------+");
process.exit(1);
}
console.log("+----------------+-------+");
console.log("| Challenge Code | FOUND |");
console.log("+----------------+-------+");
console.log(`Challenge: ${challengeCode}`);
console.log("\n=== Step 2: Deriving keypair from mnemonic ===");
const seed = await pbkdf2Async(TEST_MNEMONIC, 'mnemonic', 2048, 32, 'sha256');
const keyPair = nacl.sign.keyPair.fromSeed(seed);
const publicKeyBase64Url = toBase64Url(keyPair.publicKey);
console.log(`Public Key: ${publicKeyBase64Url}`);
console.log("+------------+---------+");
console.log("| Public Key | DERIVED |");
console.log("+------------+---------+");
const messageBuffer = Buffer.from(challengeCode);
const signature = nacl.sign.detached(messageBuffer, keyPair.secretKey);
const signatureBase64Url = toBase64Url(signature);
console.log(`Signature: ${signatureBase64Url}`);
console.log("+------------------+--------+");
console.log("| Challenge Signed | SUCCESS |");
console.log("+------------------+--------+");
const registerRes = await fetch('http://localhost:3000/auth/register/complete', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'User-Agent': 'CI-Test-Agent/1.0'
},
body: JSON.stringify({
publicKey: publicKeyBase64Url,
challenge: {
code: challengeCode,
signature: signatureBase64Url
},
namespace: "ci-test",
device: "CI-Test-Device",
profile: {
colorA: "#FF0000",
colorB: "#00FF00",
icon: "user"
}
})
});
const registerData = await registerRes.json();
if (registerData.user && registerData.token) {
console.log("+---------------+---------+");
console.log("| Registration | SUCCESS |");
console.log("+---------------+---------+");
console.log(`User ID: ${registerData.user.id}`);
console.log(`Nickname: ${registerData.user.nickname}`);
console.log(`Token: ${registerData.token.substring(0, 50)}...`);
const meRes = await fetch('http://localhost:3000/users/@me', {
headers: {
'Authorization': `Bearer ${registerData.token}`
}
});
const meData = await meRes.json();
if (meData.user && meData.user.id === registerData.user.id) {
console.log("+------------------+---------+");
console.log("| Auth Validation | SUCCESS |");
console.log("+------------------+---------+");
} else {
console.log("+------------------+--------+");
console.log("| Auth Validation | FAILED |");
console.log("+------------------+--------+");
process.exit(1);
}
const loginStartRes = await fetch('http://localhost:3000/auth/login/start', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ publicKey: publicKeyBase64Url })
});
const loginStartData = await loginStartRes.json();
if (loginStartData.challenge) {
const loginChallenge = loginStartData.challenge;
const loginSignature = nacl.sign.detached(Buffer.from(loginChallenge), keyPair.secretKey);
const loginSignatureBase64Url = toBase64Url(loginSignature);
const loginCompleteRes = await fetch('http://localhost:3000/auth/login/complete', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'User-Agent': 'CI-Test-Agent/1.0'
},
body: JSON.stringify({
publicKey: publicKeyBase64Url,
challenge: {
code: loginChallenge,
signature: loginSignatureBase64Url
},
device: "CI-Test-Device-Login"
})
});
const loginData = await loginCompleteRes.json();
if (loginData.user && loginData.token) {
console.log("+------------+---------+");
console.log("| Login Flow | SUCCESS |");
console.log("+------------+---------+");
} else {
console.log("+------------+--------+");
console.log("| Login Flow | FAILED |");
console.log("+------------+--------+");
console.log(JSON.stringify(loginData, null, 2));
process.exit(1);
}
}
} else {
console.log("+---------------+--------+");
console.log("| Registration | FAILED |");
console.log("+---------------+--------+");
console.log(JSON.stringify(registerData, null, 2));
process.exit(1);
}
console.log("\n+---------------------------+---------+");
console.log("| All Auth Tests Completed | SUCCESS |");
console.log("+---------------------------+---------+");
}
main().catch(err => {
console.error("Test failed:", err);
process.exit(1);
});
EOF
node auth-test.mjs
rm auth-test.mjs
- name: Run API endpoint tests
run: |
echo "=== Testing /meta endpoint ==="
META_RESPONSE=$(curl -s http://localhost:3000/meta)
echo "Meta response: $META_RESPONSE"
if echo "$META_RESPONSE" | grep -q "name"; then
echo "+---------------+---------+"
echo "| Meta Endpoint | SUCCESS |"
echo "+---------------+---------+"
else
echo "+---------------+--------+"
echo "| Meta Endpoint | FAILED |"
echo "+---------------+--------+"
exit 1
fi
echo ""
echo "+-----------------------------+---------+"
echo "| All Integration Tests | PASSED |"
echo "+-----------------------------+---------+"
- name: Stop the server
if: always()
run: |
if [ -f server.pid ]; then
kill $(cat server.pid) 2>/dev/null || true
fi
- name: Upload build artifacts
if: failure()
uses: actions/upload-artifact@v4
with:
name: build-output
path: .output/
retention-days: 5