Skip to content

Commit 028bd04

Browse files
authored
feat(testitall): Update the test starter-kit (#237)
Update OpenAPI spec to use relative URL Remove hosted server info Update Mock server to support patch test Update `AlmostTooLarge` context test limit to 130KB Renamed `securitySchemes` in OpenAPI spec to v2 standard
1 parent 16dc1c3 commit 028bd04

File tree

15 files changed

+579
-456
lines changed

15 files changed

+579
-456
lines changed
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
node_modules
22
npm-debug.log
33
package-lock.json
4-
.env

integrations/extensions/starter-kits/testitall/mock-server/.env-sample

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
API_SERVER_PORT=4000
22

3-
# The response size limit for WA extensions, in bytes; Used by the Context too large tests. Default is 102400 (100KB).
4-
RESPONSE_SIZE_LIMIT=102400
3+
# The response size limit for WA extensions, in bytes; Used by the Context too large tests. Default is 133120 (130KB).
4+
RESPONSE_SIZE_LIMIT=133120
55

66
# [Authentication Credentials]
77
# Basic Authentication

integrations/extensions/starter-kits/testitall/mock-server/Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ RUN npm install --only=production
1010

1111
# Bundle app source
1212
COPY . .
13-
# Copy .env-sample to .env
14-
COPY .env-sample .env
1513

1614
EXPOSE 4000
1715

integrations/extensions/starter-kits/testitall/mock-server/server/controllers/delay-controller.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ export async function delay(req, res) {
99
});
1010
}
1111

12-
async function sleep(milliseconds) {
13-
const promise = new Promise();
14-
setTimeout(() => {
15-
promise.resolve();
16-
}, milliseconds);
17-
return promise;
18-
}
12+
function sleep(milliseconds) {
13+
return new Promise((resolve) => {
14+
setTimeout(resolve, milliseconds);
15+
});
16+
}

integrations/extensions/starter-kits/testitall/mock-server/server/controllers/oauth-providers/auth-code.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function issueAccessToken() {
88
const accessToken = Math.random().toString(36).slice(-8)
99
const accessExpireTime = Date.now() + 1000 * parseInt(process.env.OAUTH_ACCESS_TOKEN_EXPIRES, 10)
1010
accessTokensAuthCode.set(accessToken, accessExpireTime)
11-
console.log('[auth code] Issuing token:', accessToken)
11+
console.log(`[auth code] Issuing token: ${accessToken}, expires: ${new Date(accessExpireTime)}`)
1212

1313
return accessToken
1414
}

integrations/extensions/starter-kits/testitall/mock-server/server/controllers/oauth-providers/client-cred.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function issueAccessToken() {
88
const accessToken = Math.random().toString(36).slice(-8)
99
const accessExpireTime = Date.now() + 1000 * parseInt(process.env.OAUTH_ACCESS_TOKEN_EXPIRES, 10)
1010
accessTokensClientCred.set(accessToken, accessExpireTime)
11-
console.log('[client cred] Issuing token:', accessToken)
11+
console.log(`[client cred] Issuing token: ${accessToken}, expires: ${new Date(accessExpireTime)}`)
1212

1313
return accessToken
1414
}

integrations/extensions/starter-kits/testitall/mock-server/server/controllers/oauth-providers/custom-apikey.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function issueAccessToken() {
1010
const accessExpireTime = Date.now() + 1000 * parseInt(process.env.OAUTH_ACCESS_TOKEN_EXPIRES, 10)
1111
accessTokensCustomApikey.set(accessToken, accessExpireTime)
1212

13-
console.log('[custom apikey] Issuing token:', accessToken)
13+
console.log(`[custom apikey] Issuing token: ${accessToken}, expires: ${new Date(accessExpireTime)}`)
1414
return accessToken
1515
}
1616

integrations/extensions/starter-kits/testitall/mock-server/server/controllers/oauth-providers/password.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function issueAccessToken() {
66
const accessToken = Math.random().toString(36).slice(-8)
77
const accessExpireTime = Date.now() + 1000 * parseInt(process.env.OAUTH_ACCESS_TOKEN_EXPIRES, 10)
88
accessTokensPassword.set(accessToken, accessExpireTime)
9-
console.log('[password] Issuing token:', accessToken)
9+
console.log(`[password] Issuing token: ${accessToken}, expires: ${new Date(accessExpireTime)}`)
1010

1111
return accessToken
1212
}

integrations/extensions/starter-kits/testitall/mock-server/server/controllers/security-controller.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ export function basicTest(req, res) {
2727
// Bearer Auth Middleware
2828
export function bearerAuthMiddleware(req, res, next) {
2929
// parse login and password from headers
30-
const token = (req.headers.authorization || '').split(' ')[1] || ''
30+
const authHeader = req.headers.authorization || ''
31+
const token = authHeader.split(' ')[1] || ''
3132

3233
// Verify login and password are set and correct
33-
if (req.headers.authorization.toLowerCase().startsWith("bearer") && token === process.env.AUTH_TOKEN) {
34+
if (authHeader.toLowerCase().startsWith("bearer") && token === process.env.AUTH_TOKEN) {
3435
// Access granted...
3536
return next()
3637
}

integrations/extensions/starter-kits/testitall/mock-server/server/controllers/test-controller.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,22 @@ export function postTest(req, res) {
3232
}
3333
}
3434

35+
export function patchTest(req, res) {
36+
return res.json({
37+
status: 'PATCHED',
38+
});
39+
}
40+
3541
export function authHeaderTest(req, res) {
3642
return res.json({
3743
auth_header: req.header('Authorization') || 'No Authorization header provided',
3844
});
3945
}
4046

4147
export function arraysInObjectTest(req, res) {
48+
const my_array = req.body.my_array || [];
4249
return res.json({
43-
my_chosen_item: req.body.item, reverse_array: req.body.my_array.reverse(), status: 'POST Array Object',
50+
my_chosen_item: req.body.item, reverse_array: my_array.reverse(), status: 'POST Array Object',
4451
});
4552
}
4653

@@ -59,7 +66,7 @@ export function errorTest(req, res) {
5966

6067

6168
export function contextTooLargeTest(req, res) {
62-
const fakeData = 'x'.repeat(parseInt(process.env.RESPONSE_SIZE_LIMIT, 10) * 5); // Default: 500KB
69+
const fakeData = 'x'.repeat(parseInt(process.env.RESPONSE_SIZE_LIMIT, 10) * 5); // Default: 130KB * 5 = 650KB
6370
const response = {
6471
data: fakeData
6572
}
@@ -68,7 +75,7 @@ export function contextTooLargeTest(req, res) {
6875
}
6976

7077
export function contextAlmostTooLargeTest(req, res) {
71-
const fakeData = 'x'.repeat(parseInt(process.env.RESPONSE_SIZE_LIMIT, 10) - 1024); // Default: 99KB
78+
const fakeData = 'x'.repeat(parseInt(process.env.RESPONSE_SIZE_LIMIT, 10) - 1024); // Default: 130KB - 1KB = 129KB
7279

7380
const response = {
7481
data: fakeData

0 commit comments

Comments
 (0)