-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
2,900 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* eslint-env node */ | ||
module.exports = { | ||
root: true, | ||
extends: ['eslint:recommended', 'plugin:import/recommended'], | ||
parser: '@typescript-eslint/parser', | ||
plugins: ['@typescript-eslint'], | ||
ignorePatterns: ['node_modules'], | ||
rules: { | ||
eqeqeq: 'error', | ||
'func-style': ['error', 'declaration'], | ||
'object-shorthand': 'error', | ||
'no-restricted-imports': [ | ||
'error', | ||
{ | ||
patterns: ['../*'], | ||
}, | ||
], | ||
'prefer-template': 'error', | ||
'import/no-unresolved': [ | ||
'error', | ||
{ | ||
ignore: ['k6/*'], | ||
}, | ||
], | ||
'import/order': [ | ||
'error', | ||
{ | ||
alphabetize: { order: 'asc' }, | ||
'newlines-between': 'always', | ||
warnOnUnassignedImports: true, | ||
pathGroups: [ | ||
{ | ||
pattern: '@src/**', | ||
group: 'internal', | ||
position: 'before', | ||
}, | ||
], | ||
groups: [ | ||
['builtin', 'external'], | ||
['internal', 'parent', 'index', 'sibling'], | ||
['object', 'type'], | ||
], | ||
}, | ||
], | ||
'no-mixed-spaces-and-tabs': 0, // disable rule | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { check, sleep } from 'k6'; | ||
import exec from 'k6/execution'; | ||
import http from 'k6/http'; | ||
|
||
export const options = { | ||
//vus and duration can be changed depending on what simulation needed running | ||
scenarios: { | ||
contacts: { | ||
executor: 'constant-vus', | ||
vus: 100, | ||
duration: '30m', | ||
}, | ||
}, | ||
}; | ||
|
||
const baseUrl = 'http://localhost:3001'; | ||
const cookieName = 'prompt-injection.sid'; | ||
const vuCookieJar = (() => { | ||
const cookieJars = {}; | ||
return { | ||
get: (id) => cookieJars[id], | ||
set: (id, jar) => (cookieJars[id] = jar), | ||
}; | ||
})(); | ||
|
||
export default () => { | ||
// Use same jar for every iteration of same VU! k6 doesn't do this for us :( | ||
const vuID = exec.vu.idInTest; | ||
let jar = vuCookieJar.get(vuID); | ||
if (!jar) { | ||
jar = http.cookieJar(); | ||
vuCookieJar.set(vuID, jar); | ||
} | ||
let originalCookie = (jar.cookiesForURL(baseUrl)[cookieName] || [])[0]; | ||
|
||
const data = { infoMessage: 'Hi', chatMessageType: 'LEVEL_INFO', level: 3 }; | ||
const response = http.post(`${baseUrl}/test/load`, JSON.stringify(data), { | ||
headers: { 'Content-Type': 'application/json' }, | ||
jar, | ||
}); | ||
// Expecting cookie to match original, OR first-time be added to the jar | ||
const expectedCookie = | ||
originalCookie || jar.cookiesForURL(baseUrl)[cookieName][0]; | ||
check(response, { | ||
'response code was 200': (response) => response.status === 200, | ||
'cookie was preserved': (response) => | ||
response.cookies[cookieName].length === 1 && | ||
response.cookies[cookieName][0].value === expectedCookie, | ||
}); | ||
|
||
sleep(1); | ||
}; |
Oops, something went wrong.