mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-05-05 15:31:27 +00:00
add check for userPromptSubmit
This commit is contained in:
parent
cf0b67ef8e
commit
0c6b16c695
4 changed files with 151 additions and 4 deletions
|
|
@ -9,7 +9,7 @@ import type {
|
|||
ToolCallConfirmationDetails,
|
||||
ToolEditConfirmationDetails,
|
||||
} from '@qwen-code/qwen-code-core';
|
||||
import { escapeAnsiCtrlCodes } from './textUtils.js';
|
||||
import { escapeAnsiCtrlCodes, sanitizeSensitiveText } from './textUtils.js';
|
||||
|
||||
describe('textUtils', () => {
|
||||
describe('escapeAnsiCtrlCodes', () => {
|
||||
|
|
@ -167,4 +167,71 @@ describe('textUtils', () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('sanitizeSensitiveText', () => {
|
||||
it('should return text unchanged if no sensitive patterns', () => {
|
||||
const text = 'Hello, this is a normal prompt';
|
||||
expect(sanitizeSensitiveText(text)).toBe(text);
|
||||
});
|
||||
|
||||
it('should redact OpenAI-style API keys', () => {
|
||||
const text = 'Use API key sk-1234567890abcdefghijklmnopqrstuv for access';
|
||||
expect(sanitizeSensitiveText(text)).toBe(
|
||||
'Use API key sk-***REDACTED*** for access',
|
||||
);
|
||||
});
|
||||
|
||||
it('should redact api_key assignments', () => {
|
||||
const text = 'api_key=supersecretkey123456789012';
|
||||
expect(sanitizeSensitiveText(text)).toBe('api_key=***REDACTED***');
|
||||
});
|
||||
|
||||
it('should redact Bearer tokens', () => {
|
||||
const text = 'Authorization: Bearer abc123token456xyz';
|
||||
expect(sanitizeSensitiveText(text)).toBe(
|
||||
'Authorization: Bearer ***REDACTED***',
|
||||
);
|
||||
});
|
||||
|
||||
it('should redact password assignments', () => {
|
||||
const text = 'password=mysecretpassword123';
|
||||
expect(sanitizeSensitiveText(text)).toBe('password=***REDACTED***');
|
||||
});
|
||||
|
||||
it('should redact AWS access keys', () => {
|
||||
const text = 'AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE';
|
||||
expect(sanitizeSensitiveText(text)).toBe(
|
||||
'AWS_ACCESS_KEY_ID=***REDACTED***',
|
||||
);
|
||||
});
|
||||
|
||||
it('should truncate long text', () => {
|
||||
const text = 'a'.repeat(300);
|
||||
const result = sanitizeSensitiveText(text, 200);
|
||||
expect(result.length).toBe(200);
|
||||
expect(result.endsWith('...')).toBe(true);
|
||||
});
|
||||
|
||||
it('should handle custom max length', () => {
|
||||
const text =
|
||||
'This is a test prompt with sk-1234567890abcdefghijklmnopqrstuv';
|
||||
const result = sanitizeSensitiveText(text, 20);
|
||||
expect(result.length).toBe(20);
|
||||
expect(result).toBe('This is a test pr...');
|
||||
});
|
||||
|
||||
it('should handle empty string', () => {
|
||||
expect(sanitizeSensitiveText('')).toBe('');
|
||||
});
|
||||
|
||||
it('should redact multiple sensitive patterns', () => {
|
||||
const text =
|
||||
'api_key=secretkey12345678901234 and password=mypass123 and sk-test123456789012345678901';
|
||||
const result = sanitizeSensitiveText(text);
|
||||
expect(result).toContain('***REDACTED***');
|
||||
expect(result).not.toContain('secretkey12345678901234');
|
||||
expect(result).not.toContain('mypass123');
|
||||
expect(result).not.toContain('sk-test123456789012345678901');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue