chore: import upstream snapshot with attribution
CI / Shell Format Check (push) Has been cancelled
CI / Check Ruby (3.4) (push) Has been cancelled
CI / CI Config (push) Has been cancelled
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Has been cancelled
CI / Build on Node ${{ matrix.node }} (push) Has been cancelled
CI / Style Check (push) Has been cancelled
CI / Generate Assets (push) Has been cancelled
CI / Check Python (3.14) (push) Has been cancelled
CI / Check Python (3.9) (push) Has been cancelled
CI / Build Docs (push) Has been cancelled
CI / Code Scan Action (push) Has been cancelled
CI / Site tests (push) Has been cancelled
CI / webui tests (push) Has been cancelled
CI / Run Integration Tests (push) Has been cancelled
CI / Run Smoke Tests (push) Has been cancelled
CI / Go Tests (push) Has been cancelled
CI / Share Test (push) Has been cancelled
CI / Redteam (Production API) (push) Has been cancelled
CI / Redteam (Staging API) (push) Has been cancelled
CI / GitHub Actions Lint (push) Has been cancelled
CI / Check Ruby (3.0) (push) Has been cancelled
release-please / release-please (push) Has been cancelled
release-please / build (push) Has been cancelled
release-please / publish-npm (push) Has been cancelled
release-please / publish-npm-backfill (push) Has been cancelled
release-please / docker (push) Has been cancelled
release-please / publish-code-scan-action (push) Has been cancelled
release-please / attest-code-scan-action (push) Has been cancelled
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Has been cancelled
Test and Publish Multi-arch Docker Image / test (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-arm64 platform:linux/arm64 runner:ubuntu-24.04-arm]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Has been cancelled
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Has been cancelled
Validate Renovate Config / Validate Renovate Configuration (push) Has been cancelled
CI / Shell Format Check (push) Has been cancelled
CI / Check Ruby (3.4) (push) Has been cancelled
CI / CI Config (push) Has been cancelled
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Has been cancelled
CI / Build on Node ${{ matrix.node }} (push) Has been cancelled
CI / Style Check (push) Has been cancelled
CI / Generate Assets (push) Has been cancelled
CI / Check Python (3.14) (push) Has been cancelled
CI / Check Python (3.9) (push) Has been cancelled
CI / Build Docs (push) Has been cancelled
CI / Code Scan Action (push) Has been cancelled
CI / Site tests (push) Has been cancelled
CI / webui tests (push) Has been cancelled
CI / Run Integration Tests (push) Has been cancelled
CI / Run Smoke Tests (push) Has been cancelled
CI / Go Tests (push) Has been cancelled
CI / Share Test (push) Has been cancelled
CI / Redteam (Production API) (push) Has been cancelled
CI / Redteam (Staging API) (push) Has been cancelled
CI / GitHub Actions Lint (push) Has been cancelled
CI / Check Ruby (3.0) (push) Has been cancelled
release-please / release-please (push) Has been cancelled
release-please / build (push) Has been cancelled
release-please / publish-npm (push) Has been cancelled
release-please / publish-npm-backfill (push) Has been cancelled
release-please / docker (push) Has been cancelled
release-please / publish-code-scan-action (push) Has been cancelled
release-please / attest-code-scan-action (push) Has been cancelled
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Has been cancelled
Test and Publish Multi-arch Docker Image / test (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-arm64 platform:linux/arm64 runner:ubuntu-24.04-arm]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Has been cancelled
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Has been cancelled
Validate Renovate Config / Validate Renovate Configuration (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
import { beforeEach, describe, expect, it } from 'vitest';
|
||||
import { IndirectPromptInjectionGrader } from '../../../src/redteam/plugins/indirectPromptInjection';
|
||||
|
||||
describe('IndirectPromptInjectionGrader', () => {
|
||||
let grader: IndirectPromptInjectionGrader;
|
||||
|
||||
beforeEach(() => {
|
||||
grader = new IndirectPromptInjectionGrader();
|
||||
});
|
||||
|
||||
it('should have the correct plugin ID', () => {
|
||||
expect(grader.id).toBe('promptfoo:redteam:indirect-prompt-injection');
|
||||
});
|
||||
|
||||
describe('getSuggestions', () => {
|
||||
it('should throw error if renderedValue is not provided', () => {
|
||||
expect(() => {
|
||||
grader.getSuggestions({
|
||||
rawPrompt: 'test prompt',
|
||||
});
|
||||
}).toThrow('renderedValue string is expected in indirect prompt injection grader');
|
||||
});
|
||||
|
||||
it('should throw error if renderedValue is not a string', () => {
|
||||
expect(() => {
|
||||
grader.getSuggestions({
|
||||
rawPrompt: 'test prompt',
|
||||
renderedValue: 123 as any,
|
||||
});
|
||||
}).toThrow('renderedValue string is expected in indirect prompt injection grader');
|
||||
});
|
||||
|
||||
it('should return array with datamarking and encoding suggestions', () => {
|
||||
const rawPrompt = 'Original prompt with {input} here';
|
||||
const renderedValue = 'malicious input';
|
||||
|
||||
const result = grader.getSuggestions({
|
||||
rawPrompt,
|
||||
renderedValue,
|
||||
});
|
||||
|
||||
expect(result).toHaveLength(2);
|
||||
expect(result[0].type).toBe('datamark');
|
||||
expect(result[1].type).toBe('encoding');
|
||||
expect(result[0].action).toBe('replace-prompt');
|
||||
expect(result[1].action).toBe('replace-prompt');
|
||||
});
|
||||
|
||||
it('should generate correct datamarking suggestion', () => {
|
||||
const userInput = 'test input';
|
||||
const rawPrompt = `Original prompt with ${userInput} here`;
|
||||
|
||||
const result = grader.getSuggestions({
|
||||
rawPrompt,
|
||||
renderedValue: userInput,
|
||||
});
|
||||
|
||||
const datamarkSuggestion = result[0];
|
||||
const expectedDatamarked = 'test^input';
|
||||
|
||||
expect(datamarkSuggestion.value).toContain('^');
|
||||
expect(datamarkSuggestion.value).toContain(`Original prompt with ${expectedDatamarked} here`);
|
||||
});
|
||||
|
||||
it('should generate correct encoding suggestion', () => {
|
||||
const userInput = 'test input';
|
||||
const rawPrompt = `Original prompt with ${userInput} here`;
|
||||
const expectedEncoded = Buffer.from(userInput).toString('base64');
|
||||
|
||||
const result = grader.getSuggestions({
|
||||
rawPrompt,
|
||||
renderedValue: userInput,
|
||||
});
|
||||
|
||||
const encodingSuggestion = result[1];
|
||||
expect(encodingSuggestion.value).toContain('base64');
|
||||
expect(encodingSuggestion.value).toContain(`Original prompt with ${expectedEncoded} here`);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user