feat(handler): sanitize sensitive fields in form data

- Removes `username` and `apiKey` from form data to prevent errors
  from the LanguageTool server when these fields are present
- Updates test cases to reflect the new handling of form data bodies
This commit is contained in:
2025-05-11 10:59:49 +02:00
parent 4326a2d92c
commit b6763f7483
2 changed files with 37 additions and 6 deletions

View File

@@ -16,12 +16,16 @@ Deno.test('ltProxyHandler: proxies request and returns response', async () => {
const originalFetch = globalThis.fetch;
globalThis.fetch = async () => expectedResponse;
// Form body wie bei echtem Request
const formData = new URLSearchParams({ text: 'Hallo Welt' });
const bodyBytes = new TextEncoder().encode(formData.toString());
const req = new Request('http://localhost/v2/check?language=de-DE', {
method: 'POST',
body: new TextEncoder().encode('text=Hallo+Welt'),
headers: {
'content-type': 'application/x-www-form-urlencoded',
},
body: bodyBytes,
});
const ctx: IContext = {
@@ -30,7 +34,9 @@ Deno.test('ltProxyHandler: proxies request and returns response', async () => {
query: {
language: 'de-DE',
},
state: {},
state: {
body: bodyBytes,
},
};
const response = await ltProxyHandler(ctx);